Changeset 6990


Ignore:
Timestamp:
03/29/10 09:26:58 (2 years ago)
Author:
ArthurClemens
Message:

Item8795: fix a number of issus:
at least one of the searches does not work
css class missing
SEARCHes can be written more clearly by having each parameter on a new line

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/data/System/SearchPatternCookbook.txt

    r1985 r6990  
    2626How to extract the 'name' values, i.e. 'option1', 'option2' and 'option3' and put them in a HTML form select input? 
    2727 
    28 ---+++ Solution 
    29  
     28---+++ Solution 1 
    3029The following search pattern can be employed: 
    3130 
     
    3332<form> 
    3433<select> 
    35 %SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="<option>$pattern(^\| *(.*?) *\|.*)</option>" }% 
     34%SEARCH{ 
     35"^\|[^\|]*\| *option *\|" 
     36topic="%TOPIC%" 
     37type="regex" 
     38multiple="on" 
     39nosearch="on" 
     40nototal="on" 
     41format="<option>$pattern(^\| *(.*?) *\|.*)</option>" 
     42}% 
    3643</select> 
    3744</form> 
     
    4148<form> 
    4249<select> 
    43 %SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="<option>$pattern(^\| *(.*?) *\|.*)</option>" }% 
    44 </select> 
    45 </form> 
     50%SEARCH{ 
     51"^\|[^\|]*\| *option *\|" 
     52topic="%TOPIC%" 
     53type="regex" 
     54multiple="on" 
     55nosearch="on" 
     56nototal="on" 
     57format="<option>$pattern(^\| *(.*?) *\|.*)</option>" 
     58}% 
     59</select> 
     60</form> 
     61 
     62---+++ Solution 2 
     63If your table has this format: 
     64<verbatim> 
     65| *Country* | 
     66| | 
     67| Afghanistan | 
     68| Aland Islands | 
     69| Albania | 
     70| Algeria | 
     71| American Samoa | 
     72| Andorra | 
     73</verbatim> 
     74 
     75You need to skip the header row. Use this search: 
     76<verbatim> 
     77<select> 
     78%SEARCH{ 
     79"^\|[^\*\|]*\|" 
     80topic="CountryList" 
     81type="regex" 
     82multiple="on" 
     83nosearch="on" 
     84nototal="on" 
     85format="<option>$pattern(^\| *(.*?) *\|.*)</option>" 
     86}% 
     87</select> 
     88</verbatim> 
     89 
     90Which renders as: 
     91 
     92<select> 
     93%SEARCH{ 
     94"^\|[^\*\|]*\|" 
     95topic="CountryList" 
     96type="regex" 
     97multiple="on" 
     98nosearch="on" 
     99nototal="on" 
     100format="<option>$pattern(^\| *(.*?) *\|.*)</option>" 
     101}% 
     102</select> 
     103 
    46104 
    47105 
     
    70128 
    71129<verbatim> 
    72 %SEARCH{"TopicClassification='%URLPARAM{type}%'" type="query" nosearch="on"  
     130%SEARCH{ 
     131"TopicClassification='%URLPARAM{type}%'" 
     132type="query" 
     133nosearch="on"  
    73134format="   * $topic - <font face=\"arial,helvetica\" size=\"1\">  
    74135_last modified by_ $wikiusername _on_ $date </font> %BR% &nbsp;&nbsp;&nbsp;  
    75136<font face=\"arial,helvetica\" size=\"1\"> $formfield(TopicStatus) </font>"  
    76 sort="topic"}% 
     137sort="topic" 
     138}% 
    77139</verbatim> 
    78140 
     
    84146<form name="selectType" action="%SCRIPTURLPATH{"view"}%/%WEB%/" > 
    85147<select name="type" size="1" onchange="document.location=this.value;">  
    86 %SEARCH{ "^\|[^\|]*\| *option *\|" topic="TopicClassification" web="%WEB%" type="regex"  
    87 multiple="on" nosearch="on" nototal="on" format="<option value=%BASETOPIC%?type=$pattern(^\| *(.*?) *\|.*)>$pattern(^\| *(.*?) *\|.*)</option>" }%  
    88 <option value=%BASETOPIC%>All pages</option> </select> 
     148%SEARCH{ 
     149"^\|[^\|]*\| *option *\|" 
     150topic="TopicClassification" 
     151web="%WEB%" 
     152type="regex"  
     153multiple="on" 
     154nosearch="on" 
     155nototal="on" 
     156format="<option value=%BASETOPIC%?type=$pattern(^\| *(.*?) *\|.*)>$pattern(^\| *(.*?) *\|.*)</option>" 
     157}%  
     158<option value=%BASETOPIC%>All pages</option> 
     159</select> 
    89160</form> 
    90161%STOPSIDEBAR%  
     
    108179=%<nop>META{ "parent" dontrecurse="on" }%= 
    109180 
     181---+++ Test case 
     182 
     183%META{ "parent" dontrecurse="on" }% 
     184 
    110185 
    111186<!-- ============================== --> 
     
    123198<verbatim> 
    124199Children: 
    125 %SEARCH{ "parent.name='%TOPIC%'" type="query" nonoise="on" format="[[$topic]]" separator=", " }% 
     200%SEARCH{ 
     201"parent.name='%TOPIC%'" 
     202type="query" 
     203nonoise="on" 
     204format="[[$topic]]" 
     205separator=", " 
     206}% 
    126207</verbatim> 
    127208 
    128209*Note:* Replace =%<nop>TOPIC%= with =%<nop>BASETOPIC%= if you put this SEARCH into the skin or a sidebar. 
    129210 
     211See also HierarchicalNavigation for an elaborate example. 
    130212 
    131213<!-- ============================== --> 
     
    143225<select name="topic"> 
    144226<option value="%TOPIC%">Select...</option> 
    145 %SEARCH{ "%HOMETOPIC%" scope="topic" web="all" topic="%HOMETOPIC%" format="<option value=\"$web.$topic\">$web</option>" separator=" " }% 
    146 </select> 
    147 <input type="submit"  value="Go" /> 
     227%SEARCH{ 
     228"%HOMETOPIC%" 
     229scope="topic" 
     230web="all" 
     231topic="%HOMETOPIC%" 
     232format="<option value=\"$web.$topic\">$web</option>" 
     233separator=" " 
     234}% 
     235</select> 
     236<input type="submit" class="foswikiSubmit" value="Go" /> 
    148237</form> 
    149238</verbatim> 
     
    156245<select name="topic"> 
    157246<option value="%TOPIC%">Select...</option> 
    158 %WEBLIST{ format="<option value=\"$name.%HOMETOPIC%\">$name</option>" webs="public" separator=" " }% 
    159 </select> 
    160 <input type="submit" value="Go" /> 
     247%SEARCH{ 
     248"%HOMETOPIC%" 
     249scope="topic" 
     250web="all" 
     251topic="%HOMETOPIC%" 
     252format="<option value=\"$web.$topic\">$web</option>" 
     253separator=" " 
     254}% 
     255</select> 
     256<input type="submit" class="foswikiSubmit" value="Go" /> 
    161257</form> 
    162258 
     
    183279<select name="type"> 
    184280<option>Select category...</option> 
    185 %SEARCH{"   *\s*.*?" topic="CategoryList" type="regex" multiple="on" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="<option>$pattern(.*   \*\s*([^\n]*).*)</option>"}% 
     281%SEARCH{ 
     282"   *\s*.*?" 
     283topic="CategoryList" 
     284type="regex" 
     285multiple="on" 
     286casesensitive="on" 
     287nosummary="on" 
     288nosearch="on" 
     289noheader="on" 
     290nototal="on" 
     291format="<option>$pattern(.*   \*\s*([^\n]*).*)</option>" 
     292}% 
    186293</select> 
    187294</verbatim> 
     
    189296To render the bullet list as a comma-separated list, use the =separator= parameter: 
    190297<verbatim> 
    191 %SEARCH{"   *\s*.*?" topic="CategoryList" type="regex" multiple="on" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" separator="," format="$pattern(.*   \*\s*([^\n]*).*)"}% 
     298%SEARCH{ 
     299"   *\s*.*?" 
     300topic="CategoryList" 
     301type="regex" 
     302multiple="on" 
     303casesensitive="on" 
     304nosummary="on" 
     305nosearch="on" 
     306noheader="on" 
     307nototal="on" 
     308separator="," 
     309format="$pattern(.*   \*\s*([^\n]*).*)" 
     310}% 
    192311</verbatim> 
    193312 
     
    206325 
    207326<verbatim> 
    208 %SEARCH{"   * [N]ame: " topic="%TOPIC%" type="regex" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="---+!! $pattern(.*   \* Name: ([^\n]*).*)"}% 
     327%SEARCH{ 
     328"   \* [N]ame:" 
     329topic="%TOPIC%" 
     330type="regex" 
     331casesensitive="on" 
     332nosummary="on" 
     333nosearch="on" 
     334noheader="on" 
     335nototal="on" 
     336format="---+!! $pattern(.*   \* Name: ([^\n]*).*)" 
     337}% 
    209338</verbatim> 
    210339 
     
    217346Search result: 
    218347 
    219 %SEARCH{"   * [N]ame: " topic="%TOPIC%" type="regex" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="---+!! $pattern(.*   \* Name: ([^\n]*).*)"}% 
     348%SEARCH{ 
     349"   \* [N]ame:" 
     350topic="%TOPIC%" 
     351type="regex" 
     352casesensitive="on" 
     353nosummary="on" 
     354nosearch="on" 
     355noheader="on" 
     356nototal="on" 
     357format="<strong>$pattern(.*   \* Name: ([^\n]*).*)</strong>" 
     358}% 
    220359 
    221360<!-- ============================== --> 
     
    231370Search for the 'moved' meta data. Type this:  
    232371 
    233 =Moved topics: %<nop>SEARCH{ "moved.to!=''" type="query" format="$topic, " nosearch="on" noheader="on" nosummary="on" }%= 
     372<verbatim> 
     373Moved topics: %SEARCH{ 
     374"moved.to!=''" 
     375web="all" 
     376type="query" 
     377separator=", " 
     378format="$web.$topic" 
     379nonoise="on" 
     380noheader="on" 
     381nosummary="on" 
     382}% 
     383</verbatim> 
     384 
     385---+++ Test case 
     386Moved topics: %SEARCH{ 
     387"moved.to!=''" 
     388web="all" 
     389type="query" 
     390separator=", " 
     391format="$web.$topic" 
     392nonoise="on" 
     393noheader="on" 
     394nosummary="on" 
     395}% 
    234396 
    235397--- 
Note: See TracChangeset for help on using the changeset viewer.