Difference between revisions of "Talk:Test includematch"

From FollowTheScore
Jump to: navigation, search
(Includematch searches all fields instead of just one (bug?))
 
Line 5: Line 5:
 
<dpl>
 
<dpl>
 
category=African Country
 
category=African Country
includepage={African Country}:languages,{African Country}:goverment,{African Country}:area,{African Country}:population,{African Country}:gdp,{African Country}:independence_day
+
includepage={African Country}:languages,{African Country}:government_type,{African Country}:area,{African Country}:population,{African Country}:gdp,{African Country}:independence_day
 
mode=userformat
 
mode=userformat
 
listseparators=¶{|class=sortable ¶!No ¶! Name ¶! Languages ¶! Government ¶! Area ¶! Population ¶! GDP ¶! Independence Day , ¶|-¶|%NR%¶|[[%PAGE%]] , ,¶|}
 
listseparators=¶{|class=sortable ¶!No ¶! Name ¶! Languages ¶! Government ¶! Area ¶! Population ¶! GDP ¶! Independence Day , ¶|-¶|%NR%¶|[[%PAGE%]] , ,¶|}
Line 24: Line 24:
  
 
and you still got a result because the "Independance day" column is searched. Shouldn't only the "Languages" column being searched? --[[User:Mark P.|Mark P.]] 23:25, 22 November 2007 (CET)
 
and you still got a result because the "Independance day" column is searched. Shouldn't only the "Languages" column being searched? --[[User:Mark P.|Mark P.]] 23:25, 22 November 2007 (CET)
 +
 +
== Explanation ==
 +
No, this is not a bug. As explained [[titlematch]] applies the regep to the whole string used for the temlate´s invocation. It is your responsibility to define the pattern in a a way that in will only match the contents youz are seeking for.
 +
 +
In the above example the ".*" before ''English'' or before ''1961'' causes the surprising behaviour. ".*" means anything, even a pipe separator. So the pattern simply looks if SOMEHWERE in the complete invocatrion string it can find the literal ''languages'' and SOMEWHERE afer that place ''1961'' can be found.
 +
 +
Replace '.*' by '[^|]*' and it will do what  you expect because now the regexp looks for ''languages'' and then it skips all non-fitting characters EXCEPT the pipe symbol.
 +
 +
Note: If you use the #dpl parser function notation you must use an octal notation for the pipe or escape it vi a media wiki template which produces a  pipe.
 +
 +
Example:
 +
 +
looking for 'English'
 +
<dpl>
 +
category=African Country
 +
includepage={African Country}:languages,{African Country}:government_type,{African Country}:area,{African Country}:population,{African Country}:gdp,{African Country}:independence_day
 +
mode=userformat
 +
listseparators=¶{|class=sortable ¶!No ¶! Name ¶! Languages ¶! Government ¶! Area ¶! Population ¶! GDP ¶! Independence Day , ¶|-¶|%NR%¶|[[%PAGE%]] , ,¶|}
 +
secseparators=¶|
 +
resultsheader=Number of data = %PAGES%
 +
includematch=/languages\s*=\s*[^|]*English.*/s
 +
</dpl>
 +
 +
looking for '1961'
 +
<dpl>
 +
category=African Country
 +
includepage={African Country}:languages,{African Country}:government_type,{African Country}:area,{African Country}:population,{African Country}:gdp,{African Country}:independence_day
 +
mode=userformat
 +
listseparators=¶{|class=sortable ¶!No ¶! Name ¶! Languages ¶! Government ¶! Area ¶! Population ¶! GDP ¶! Independence Day , ¶|-¶|%NR%¶|[[%PAGE%]] , ,¶|}
 +
secseparators=¶|
 +
resultsheader=Number of data = %PAGES%
 +
includematch=/languages\s*=\s*[^|]*1961.*/s
 +
</dpl>
 +
 +
with parser function syntax looking for 'English'
 +
{{#dpl:
 +
|category=African Country
 +
|namespace=
 +
|include={African Country}:languages:government_type:area:population:gdp:independence_day
 +
|includematch=/languages\s*=\s*[^{{!}}]*English/s
 +
|table=class=sortable,Name,Languages,Government,Area,Population,GDP,Independence Day
 +
|resultsheader=Number of data = %PAGES%\n
 +
}}

Revision as of 12:54, 24 November 2007

Includematch searches all fields instead of just one (bug?)

I tested the following example and noticed strange includematch behaviour.

<dpl>
category=African Country
includepage={African Country}:languages,{African Country}:government_type,{African Country}:area,{African Country}:population,{African Country}:gdp,{African Country}:independence_day
mode=userformat
listseparators=¶{|class=sortable ¶!No ¶! Name ¶! Languages ¶! Government ¶! Area ¶! Population ¶! GDP ¶! Independence Day , ¶|-¶|%NR%¶|[[%PAGE%]] , ,¶|}
secseparators=¶|
resultsheader=Number of data = %PAGES%
includematch=/languages\s*=\s*.*English.*/s
</dpl>

Try for example replacing

includematch=/languages\s*=\s*.*English.*/s

with

includematch=/languages\s*=\s*.*1961.*/s

and you still got a result because the "Independance day" column is searched. Shouldn't only the "Languages" column being searched? --Mark P. 23:25, 22 November 2007 (CET)

Explanation

No, this is not a bug. As explained titlematch applies the regep to the whole string used for the temlate´s invocation. It is your responsibility to define the pattern in a a way that in will only match the contents youz are seeking for.

In the above example the ".*" before English or before 1961 causes the surprising behaviour. ".*" means anything, even a pipe separator. So the pattern simply looks if SOMEHWERE in the complete invocatrion string it can find the literal languages and SOMEWHERE afer that place 1961 can be found.

Replace '.*' by '[^|]*' and it will do what you expect because now the regexp looks for languages and then it skips all non-fitting characters EXCEPT the pipe symbol.

Note: If you use the #dpl parser function notation you must use an octal notation for the pipe or escape it vi a media wiki template which produces a pipe.

Example:

looking for 'English' Number of data = 2

No Name Languages Government Area Population GDP Independence Day
1 Republic of Cameroon French,English 183,568 sq mi 17,795,000 $43.196 billion 01/10/1961
2 United Republic of Tanzania Swahili, English 364,898 sq mi 37,849,133 $27.12 billion 26/04/1964

looking for '1961'

Extension:DynamicPageList (DPL), version 3.2.1: Warning: No results.

No Name Languages Government Area Population GDP Independence Day

with parser function syntax looking for 'English' Number of data = 3

Name Languages Government Area Population GDP Independence Day
DPL Example 015
Republic of Cameroon French,English 183,568 sq mi 17,795,000 $43.196 billion 01/10/1961
United Republic of Tanzania Swahili, English 364,898 sq mi 37,849,133 $27.12 billion 26/04/1964