Difference between revisions of "Talk:Test includematch"
(→Explanation) |
|||
Line 25: | Line 25: | ||
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 == | + | == Reply and Explanation == |
− | |||
− | + | First, the DPL statement above could be written more elegantly, using the [[table]] command. The [[table]] command was invented recently to facilitate standard view definitions. | |
− | + | Second the regexep uses ".*" before 'English' or '1961'. This means that also pipe characters will be skipped - so '1961' will be accepted if it occurs ANYWHERE AFTER 'languages'. What you wnat, however, is to stop the pattern matching at field boundaries /(i.e. at pipoe characters). Therefore you must use ''[^|]*'' instead of ''.*'' which will match alöl characters EXCEPT The field delimiting pipe charcter. | |
− | + | <pre><nowiki> | |
+ | <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 | ||
+ | noresultsheader= no matching country found.\n | ||
+ | </dpl> | ||
+ | </nowiki></pre> | ||
− | + | And here is the result with 'English': | |
− | |||
<dpl> | <dpl> | ||
− | category=African Country | + | 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% | + | resultsheader=Number of data = %PAGES%\n |
− | + | noresultsheader= no matching country found.\n | |
</dpl> | </dpl> | ||
− | + | .. and with '1961' | |
+ | |||
<dpl> | <dpl> | ||
− | category=African Country | + | category=African Country |
− | + | namespace= | |
− | + | include={African Country}:languages:government_type:area:population:gdp:independence_day | |
− | + | includematch=/languages\s*=\s*[^|]*1961/s | |
− | + | table=class=sortable,Name,Languages,Government,Area,Population,GDP,Independence Day | |
− | resultsheader=Number of data = %PAGES% | + | resultsheader=Number of data = %PAGES%\n |
− | + | noresultsheader= no matching country found.\n | |
</dpl> | </dpl> | ||
− | + | Note: If you use the #dpl parser function notation you must not use the pipe directly because it would be misperceived as a field demiter for #dpl itself. IN that case you should use something like ''<nowiki>[^{{!}}]*</nowiki>'' (assuming that there is a template called ''!'' which retuzrn s a single pipe character. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Revision as of 12:06, 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)
Reply and Explanation
First, the DPL statement above could be written more elegantly, using the table command. The table command was invented recently to facilitate standard view definitions.
Second the regexep uses ".*" before 'English' or '1961'. This means that also pipe characters will be skipped - so '1961' will be accepted if it occurs ANYWHERE AFTER 'languages'. What you wnat, however, is to stop the pattern matching at field boundaries /(i.e. at pipoe characters). Therefore you must use [^|]* instead of .* which will match alöl characters EXCEPT The field delimiting pipe charcter.
<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 noresultsheader= no matching country found.\n </dpl>
And here is the result with '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 |
.. and with '1961'
Number of data = 1
Name | Languages | Government | Area | Population | GDP | Independence Day |
---|---|---|---|---|---|---|
DPL Example 015 |
Note: If you use the #dpl parser function notation you must not use the pipe directly because it would be misperceived as a field demiter for #dpl itself. IN that case you should use something like [^{{!}}]* (assuming that there is a template called ! which retuzrn s a single pipe character.