data/TWiki/SearchPatternCookbook.txt,v
changeset 0 414e01d06fd5
equal deleted inserted replaced
-1:000000000000 0:414e01d06fd5
       
     1 head	1.5;
       
     2 access;
       
     3 symbols;
       
     4 locks; strict;
       
     5 comment	@# @;
       
     6 
       
     7 
       
     8 1.5
       
     9 date	2008.01.22.03.21.33;	author TWikiContributor;	state Exp;
       
    10 branches;
       
    11 next	1.4;
       
    12 
       
    13 1.4
       
    14 date	2007.01.16.04.12.01;	author TWikiContributor;	state Exp;
       
    15 branches;
       
    16 next	1.3;
       
    17 
       
    18 1.3
       
    19 date	2006.06.25.16.26.26;	author TWikiContributor;	state Exp;
       
    20 branches;
       
    21 next	1.2;
       
    22 
       
    23 1.2
       
    24 date	2006.04.01.05.55.10;	author TWikiContributor;	state Exp;
       
    25 branches;
       
    26 next	1.1;
       
    27 
       
    28 1.1
       
    29 date	2006.02.01.12.01.18;	author TWikiContributor;	state Exp;
       
    30 branches;
       
    31 next	;
       
    32 
       
    33 
       
    34 desc
       
    35 @new-topic
       
    36 @
       
    37 
       
    38 
       
    39 1.5
       
    40 log
       
    41 @buildrelease
       
    42 @
       
    43 text
       
    44 @%META:TOPICINFO{author="TWikiContributor" date="1168735119" format="1.1" version="5"}%
       
    45 %META:TOPICPARENT{name="FormattedSearch"}%
       
    46 ---+!! Search Pattern Cookbook
       
    47 
       
    48 The Search function in TWiki is very powerful. Especially searches using a RegularExpression play an important part of tapping TWiki's full potential. Unfortunately RegularExpressions can be incredibly obscure to the uninitiated. 
       
    49 
       
    50 Most people not familiar (enough) with Regular Expressions mostly cut and paste (and maybe tweak) from existing examples. This page intends to collect lots of examples together.
       
    51 
       
    52 %TOC{ depth="2" }%
       
    53 
       
    54 <!-- ============================== -->
       
    55 #SearchTables
       
    56 ---++ Pattern 1: Extract values from a table
       
    57 
       
    58 ---+++ Problem definition
       
    59 
       
    60 Suppose there is a topic with a table defining entries in a !TWikiForm. I.e. they define select menu items in a form template. They are then formatted like:
       
    61 
       
    62 <verbatim>
       
    63 | *Name* | *Type* | *Tooltip message* |
       
    64 | option1 | option | |
       
    65 | option2 | option | |
       
    66 | option3 | option | |
       
    67 </verbatim>
       
    68 
       
    69 How to extract the 'name' values, i.e. 'option1', 'option2' and 'option3' and put them in a HTML form select input?
       
    70 
       
    71 ---+++ Solution
       
    72 
       
    73 The following search pattern can be employed:
       
    74 
       
    75 <verbatim>
       
    76 <form>
       
    77 <select>
       
    78 %SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="<option>$pattern(^\| *(.*?) *\|.*)</option>" }%
       
    79 </select>
       
    80 </form>
       
    81 </verbatim>
       
    82 
       
    83 which is, in effect:
       
    84 <form>
       
    85 <select>
       
    86 %SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="<option>$pattern(^\| *(.*?) *\|.*)</option>" }%
       
    87 </select>
       
    88 </form>
       
    89 
       
    90 
       
    91 <!-- ============================== -->
       
    92 #SearchFormClassification
       
    93 ---++ Pattern 2: List generated from form classification
       
    94 
       
    95 ---+++ Problem
       
    96 
       
    97 Imagine a TWiki form-based topic classification, i.e. every page has a form with several fields. How to:
       
    98    1. create a search to display all topics where one form field is set to a certain value
       
    99    1. create a search to filter the list above based on the values of a second form field
       
   100 
       
   101 ---+++ Test case
       
   102 
       
   103 In practice: %BR%
       
   104 Image a TWiki form with two fields:
       
   105    * !TopicClassification = One, Two or Three
       
   106    * !TopicStatus = Test or Final
       
   107 
       
   108 We will:
       
   109    1. List all topics where the !TopicClassification field is set to 'Two'
       
   110    2. Enable the user to filter this list based on the values of !TopicStatus
       
   111 
       
   112 ---+++ Solution
       
   113 
       
   114 <verbatim>
       
   115 %SEARCH{"[T]opicClassification.*value\=.*Two;[T]opicStatus.*value\=.*%URLPARAM{type}%"
       
   116 type="regex" casesensitive="on" nosearch="on" 
       
   117 format="   * $topic - <font face=\"arial,helvetica\" size=\"1\"> 
       
   118 _last modified by_ $wikiusername _on_ $date </font> %BR% &nbsp;&nbsp;&nbsp; 
       
   119 <font face=\"arial,helvetica\" size=\"1\"> $formfield(TopicStatus) </font>" 
       
   120 sort="topic"}%
       
   121 </verbatim>
       
   122 
       
   123 The filtering select dialogue is created as in Pattern 1:
       
   124 
       
   125 <verbatim>
       
   126 %STARTSIDEBAR%
       
   127 *Filter:* %BR%
       
   128 <form name="selectType" action="%SCRIPTURLPATH{"view"}%/%WEB%/" >
       
   129 <select name="type" size="1" onchange="document.location=this.value;"> 
       
   130 %SEARCH{ "^\|[^\|]*\| *option *\|" topic="TopicClassification" web="%WEB%" type="regex" 
       
   131 multiple="on" nosearch="on" nototal="on" format="<option value=%INCLUDINGTOPIC%?type=$pattern(^\| *(.*?) *\|.*)>$pattern(^\| *(.*?) *\|.*)</option>" }% 
       
   132 <option value=%INCLUDINGTOPIC%>All pages</option> </select>
       
   133 </form>
       
   134 %STOPSIDEBAR% 
       
   135 </verbatim>
       
   136 
       
   137 This will create similar functionality as TWiki:Plugins.TopicClassificationAddOn
       
   138 
       
   139 
       
   140 <!-- ============================== -->
       
   141 #SearchUsernames
       
   142 ---++ Pattern 3: Creating lists of TWiki usernames
       
   143 
       
   144 ---+++ Problem
       
   145 
       
   146 How to populate a list box with all usernames of registered TWiki users
       
   147 
       
   148 ---+++ Solution 1: Appropriate for Sep 2004 TWiki (Cairo)
       
   149 
       
   150 <verbatim>
       
   151 <form name="testing" action="%SCRIPTURLPATH{"view"}%/%USERSWEB%" method="get">
       
   152 <select name="topic">
       
   153 <option>Select user...</option>
       
   154 %SEARCH{ "Name:;Email:;Country:" web="%USERSWEB%" type="regex" nosearch="on" nototal="on" format="<option>$topic</option>" }%
       
   155 </select>
       
   156 <input type="submit" value="Go" />
       
   157 </form>
       
   158 </verbatim>
       
   159 
       
   160 Which expands to this: (here limited to all Z* users because TWiki.org has so many)
       
   161 
       
   162 <form name="testing" action="%SCRIPTURLPATH{"view"}%/%USERSWEB%" method="get">
       
   163 <select name="topic">
       
   164 <option>Select user...</option>
       
   165 %SEARCH{ "Name:;Email:;Country:" web="%USERSWEB%" type="regex" topic="Z*" nosearch="on" nototal="on" format="<option>$topic</option>" }%
       
   166 </select>
       
   167 <input type="submit" value="Go" />
       
   168 </form>
       
   169 
       
   170 This searches all topics in the Main web that contain "Name", "Email" and "Country" bullets. Alternatively, do a %SYSTEMWEB%.FormattedSearch with =multiple="on"= on the [[%USERSWEB%.TWikiUsers]] topic.
       
   171 
       
   172 ---+++ Solution 2: As Solution 1, but with possibility for multi-selecting usernames
       
   173 
       
   174 The example of Solution 1 produces the list box.  Add a MULTIPLE to the _select_ statement, i.e.:
       
   175 <verbatim>
       
   176 <select name="topic" size="2" MULTIPLE>
       
   177 </verbatim>
       
   178 
       
   179 Please note that the Search pattern is unchanged compared to Solution 1. The change is in the HTML form element.
       
   180 
       
   181 The abovementioned modification is, in effect:
       
   182 <form name="testing" action="%SCRIPTURLPATH{"view"}%/%USERSWEB%" method="get">
       
   183 <select name="topic" size="2" MULTIPLE>
       
   184 <option>Select user...</option>
       
   185 %SEARCH{ "Name:;Email:;Country:" web="%USERSWEB%" type="regex" topic="Z*" nosearch="on" nototal="on" format="<option>$topic</option>" }%
       
   186 </select>
       
   187 <input type="submit" value="Go" />
       
   188 </form>
       
   189 
       
   190 ---+++ Solution 3: Appropriate for TWiki 4 (Dakar)
       
   191 
       
   192 When the User information is stored in a UserForm (as is default in Dakar) then this list can be generated as follows:
       
   193 
       
   194 <verbatim>
       
   195 <form name="testing" action="%SCRIPTURLPATH{"view"}%/%USERSWEB%" method="get">
       
   196 <select name="topic">
       
   197 <option>Select user...</option>
       
   198 %SEARCH{"%META:FORM.*[U]serForm" web="%USERSWEB%" type="regex" casesensitive="on" nosearch="on" format="<option>$topic</option>" sort="topic" excludetopic="Test*, TWiki*"}%
       
   199 </select>
       
   200 <input type="submit" value="Go" />
       
   201 </form>
       
   202 </verbatim>
       
   203 
       
   204 In the above example:
       
   205    * ==META:FORM.*[U]serForm== will search for all topics with a UserForm attached - change this if you have a different form where userdata is stored. Please note that this search does not actually extract anything from the form - it just uses it to identify the appropriate pages
       
   206    * ==excludetopic="Test*, TWiki*"== allows to skip all topics starting with Test and TWiki, such as !TestUser or !TWikiAdmin. Use this if you have any special users who you do not want appearing in this list
       
   207 
       
   208 
       
   209 <!-- ============================== -->
       
   210 #SearchTopicParent
       
   211 ---++ Pattern 4: Extract the parent of a given topic
       
   212 
       
   213 ---+++ Problem
       
   214 
       
   215 How to get to the parent of the current topic to display on the page?
       
   216 
       
   217 ---+++ Solution 1: Using META
       
   218 
       
   219 Since TWiki 4.0 you can now use the META variable:
       
   220 
       
   221 =%<nop>META{ "parent" dontrecurse="on" }%=
       
   222 
       
   223 
       
   224 ---+++ Solution 2: Using !SpreadSheetPlugin
       
   225 
       
   226 You might think that the following Search would do the trick:
       
   227 <verbatim>
       
   228 %SEARCH{ "^%BASETOPIC%$" scope="topic" nosearch="on" type="regex" nonoise="on" format="   * $parent" }%
       
   229 </verbatim>
       
   230 
       
   231 However, the =$parent= link fails if the topic has no parent set (=$parent= will be empty). You can use some TWiki:Plugins/SpreadSheetPlugin magic to conditionally link to the parent or to =WebHome=:
       
   232 
       
   233 <verbatim>
       
   234 $percntCALC{$IF($EXACT($parent,),<nop>,$NOP(   * $parent))}$percnt
       
   235 </verbatim>
       
   236 
       
   237 So the total Search query to find a topic's parent topic is:
       
   238 <verbatim>
       
   239 %SEARCH{ "^%BASETOPIC%$" scope="topic" type="regex" nonoise="on" format="$percntCALC{$IF($EXACT($parent,),<nop>,$NOP(   * $parent))}$percnt" }%
       
   240 </verbatim>
       
   241 
       
   242 ---++++ Test Case
       
   243 
       
   244 The parent topic of this topic is:
       
   245 %SEARCH{ "^%BASETOPIC%$" scope="topic" type="regex" nonoise="on" format="$percntCALC{$IF($EXACT($parent,),<nop>,$NOP(   * $parent))}$percnt" }%
       
   246 
       
   247 ---+++ Solution 3: Using IF statement
       
   248 This pattern can be rewritten using =%<nop>IF%=, removing the dependency on !SpreadSheetPlugin:
       
   249 <verbatim>
       
   250 %SEARCH{ "^%BASETOPIC%$" web="%BASEWEB%" scope="topic" type="regex" nonoise="on" format="$percntIF{$quot$parent$quot then=$quot   * $parent$quot else=$quot<nop>$quot}$percnt" }%
       
   251 </verbatim>
       
   252 
       
   253 ---++++ Test Case
       
   254 The parent topic of this topic is: %BR%
       
   255 %SEARCH{ "^%BASETOPIC%$" web="%BASEWEB%" scope="topic" type="regex" nonoise="on" format="$percntIF{$quot$parent$quot then=$quot   * $parent$quot else=$quot<nop>$quot}$percnt" }%
       
   256 
       
   257 
       
   258 <!-- ============================== -->
       
   259 #SearchTopicChildren
       
   260 ---++ Pattern 5: Show all Children of a given topic
       
   261 
       
   262 ---+++ Problem
       
   263 
       
   264 How to get to the list of all children of the current topic to display on the page?
       
   265 
       
   266 ---+++ Solution
       
   267 
       
   268 The parent information is stored in the META:TOPICPARENT meta data. Do a SEARCH to find all topic parent meta data pointing to the current topic:
       
   269 
       
   270 <verbatim>
       
   271 Children:
       
   272 %SEARCH{ "META\:TOPICPARENT.*\"%TOPIC%\"" type="regex" nonoise="on" format="[[$topic]]" separator=", " }%
       
   273 </verbatim>
       
   274 
       
   275 __Note:__ Replace =%<nop>TOPIC%= with =%<nop>BASETOPIC%= if you put this SEARCH into the skin or a sidebar.
       
   276 
       
   277 
       
   278 <!-- ============================== -->
       
   279 #SearchPublicWebsList
       
   280 ---++ Pattern 6: Search and display the home topics of public webs in a list
       
   281 
       
   282 ---+++ Problem
       
   283 
       
   284 How to find and display public webs in a drop down list box.
       
   285 
       
   286 ---+++ Solution
       
   287 
       
   288 _Thanks to TWiki:Main.PeterThoeny for these solutions._
       
   289 
       
   290 <verbatim>
       
   291 <form>
       
   292 <select name="topic">
       
   293 <option value="%TOPIC%">Select...</option>
       
   294 %SEARCH{ "%HOMETOPIC%" scope="topic" web="all" topic="%HOMETOPIC%" format="<option value=\"$web.$topic\">$web</option>" separator=" " }%
       
   295 </select>
       
   296 <input type="submit"  value="Go" />
       
   297 </form>
       
   298 </verbatim>
       
   299 
       
   300 ---+++ Test case
       
   301 
       
   302 Public webs of TWiki.
       
   303 
       
   304 <form>
       
   305 <select name="topic">
       
   306 <option value="%TOPIC%">Select...</option>
       
   307 %SEARCH{ "%HOMETOPIC%" scope="topic" web="all" topic="%HOMETOPIC%" format="<option value=\"$web.$topic\">$web</option>" separator=" " }%
       
   308 </select>
       
   309 <input type="submit"  value="Go" />
       
   310 </form>
       
   311 
       
   312 %T% For private webs, or any other webs you wish to exclude from the display, use "on" for the =Exclude web from a web="all" search= setting in the relevant web's !WebPreferences topic.
       
   313 
       
   314 ---+++ Alternative solution
       
   315 
       
   316 This result can also be accomplished with the %<nop>WEBLIST% variable.
       
   317 
       
   318 <form>
       
   319 <select name="topic">
       
   320 <option value="%TOPIC%">Select...</option>
       
   321 %WEBLIST{ format="<option value=\"$name.%HOMETOPIC%\">$name</option>" webs="public" separator=" " }%
       
   322 </select>
       
   323 <input type="submit" value="Go" />
       
   324 </form>
       
   325 
       
   326 
       
   327 <!-- ============================== -->
       
   328 #SearchBulletList
       
   329 ---++ Pattern 7: Create a select box with values from a bullet list
       
   330 
       
   331 ---+++ Problem
       
   332 
       
   333 We have a topic with a bullet list with category names. In another topic we want to offer these values in a select box dropdown.
       
   334 
       
   335 For example, !CategoryList has:
       
   336    * Clients
       
   337    * People
       
   338    * Rooms
       
   339    * Buildings
       
   340 
       
   341 ---+++ Solution
       
   342 
       
   343 The following search pattern can be employed:
       
   344 
       
   345 <verbatim>
       
   346 <select name="type">
       
   347 <option>Select category...</option>
       
   348 %SEARCH{"   *\s*.*?" topic="CategoryList" type="regex" multiple="on" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="<option>$pattern(.*   \*\s*([^\n]*).*)</option>"}%
       
   349 </select>
       
   350 </verbatim>
       
   351 
       
   352 To render the bullet list as a comma-separated list, use the =separator= parameter:
       
   353 <verbatim>
       
   354 %SEARCH{"   *\s*.*?" topic="CategoryList" type="regex" multiple="on" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" separator="," format="$pattern(.*   \*\s*([^\n]*).*)"}%
       
   355 </verbatim>
       
   356 
       
   357 
       
   358 <!-- ============================== -->
       
   359 #SearchNamedBulletList
       
   360 ---++ Pattern 8: Extract a value from a named bullet list item
       
   361 
       
   362 ---+++ Problem
       
   363 
       
   364 Display the user name in the user's topic title
       
   365 
       
   366 ---+++ Solution
       
   367 
       
   368 Search for the =Name:= entry.
       
   369 
       
   370 <verbatim>
       
   371 %SEARCH{"   * [N]ame: " topic="%TOPIC%" type="regex" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="---+!! $pattern(.*   \* Name: ([^\n]*).*)"}%
       
   372 </verbatim>
       
   373 
       
   374 ---+++ Test case
       
   375 
       
   376 To create a test case, we will put a name entry here:
       
   377 
       
   378    * Name: John Doe
       
   379 
       
   380 Search result:
       
   381 
       
   382 %SEARCH{"   * [N]ame: " topic="%TOPIC%" type="regex" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="---+!! $pattern(.*   \* Name: ([^\n]*).*)"}%
       
   383 
       
   384 
       
   385 <!-- ============================== -->
       
   386 #SearchMetaData
       
   387 ---++ Pattern 9: Search for Form and Meta data: explained
       
   388 
       
   389 ---+++ Problem
       
   390 
       
   391 Below is an example of a search that searches form data. The questions are:
       
   392    * why is this searching the metadata, shouldn't it just search the text?
       
   393    * what is the meaning of the =td..td= in the search expression? 
       
   394 
       
   395 <pre>
       
   396 %<nop>SEARCH{ "[S]tatus.*(td..td|value\=).*[W]aiting" casesensitive="on" type="regex" 
       
   397 nosearch="on" nototal="on" format="| [[$topic]]&lt;br /> ($date - $rev - 
       
   398 [[%<nop>SCRIPTURLPATH{rdiff}%/$web/$topic][Diffs]]) |"}%
       
   399 </pre>
       
   400 
       
   401 ---+++ Solution
       
   402 
       
   403 %SEARCH depends on grep, and grep searches the whole file, including the meta data.
       
   404 
       
   405 An example meta data form field is:
       
   406 <pre>
       
   407 %<nop>META:<nop>FIELD{name="OperatingSystem" title="OperatingSystem" value="Os<nop>Win"}%
       
   408 </pre>
       
   409 So a search for a form field could look like:
       
   410 <pre>
       
   411 %<nop>SEARCH{ "[O]peratingSystem.*value\=.*[O]sWin" type="regex" ... }%
       
   412 </pre>
       
   413    * Using square brackets is a trick to avoid a hit on the topic doing the search.
       
   414    * The =.*= indicate that there can be any number of any character between =OperatingSystem= and =value= in the (whole) file
       
   415 
       
   416 Now the original file format of the category table (the predecessor of the TWiki forms) looks like this:
       
   417 <verbatim>
       
   418 <td valign="top" align="right"> OperatingSystem:  </td><td>  OsWin </td>
       
   419 </verbatim>
       
   420 The following search finds topics in the old and new format:
       
   421 <pre>
       
   422 %<nop>SEARCH{ "[O]peratingSystem.*(td..td|value\=).*[O]sWin" type="regex" ... }%
       
   423 </pre>
       
   424 
       
   425 The =td..td= matches =td&lt;&gt;td=; a simple search on ="[O]peratingSystem.*[O]sWin"= could find a hit in the topic text by coincidence.
       
   426 
       
   427 A simple =%<nop>SEARCH{ "[O]peratingSystem.*value\=<nop>.*[O]sWin" ...}%= search is sufficient if you do not have topics in the old format.
       
   428 
       
   429 
       
   430 <!-- ============================== -->
       
   431 #MovedTopics
       
   432 ---++ Pattern 10: Search all topics that have been moved
       
   433 
       
   434 ---+++ Problem
       
   435 
       
   436 How would I go about listing all moved topics ?
       
   437 
       
   438 ---+++ Solution
       
   439 
       
   440 Search for the META:TOPICMOVED meta data. Type this: 
       
   441 
       
   442 =Moved topics: %<nop>SEARCH{ "%META\:TOPICMOVED" type="regex" format="$topic, " nosearch="on" noheader="on" nosummary="on" }%=
       
   443 
       
   444 to get this (limited to 10 results):
       
   445 
       
   446 Moved topics: %SEARCH{ "%META\:TOPICMOVED" type="regex" format="$topic, " nosearch="on" noheader="on" nosummary="on" limit="10"}%
       
   447 
       
   448 __Related Topics:__ UserDocumentationCategory, SearchHelp, TWikiVariables#VarSEARCH, FormattedSearch, RegularExpression
       
   449 
       
   450 -- __Contributors:__ TWiki:Main.AntonAylward, TWiki:Main.ArthurClemens, TWiki:Main.JosMaccabiani, TWiki:Main.PeterThoeny, TWiki:Main.SueLocke
       
   451 @
       
   452 
       
   453 
       
   454 1.4
       
   455 log
       
   456 @buildrelease
       
   457 @
       
   458 text
       
   459 @d1 1
       
   460 a1 1
       
   461 %META:TOPICINFO{author="TWikiContributor" date="1168735119" format="1.1" version="4"}%
       
   462 d108 1
       
   463 a108 1
       
   464 <form name="testing" action="%SCRIPTURLPATH{"view"}%/%MAINWEB%" method="get">
       
   465 d111 1
       
   466 a111 1
       
   467 %SEARCH{ "Name:;Email:;Country:" web="%MAINWEB%" type="regex" nosearch="on" nototal="on" format="<option>$topic</option>" }%
       
   468 d119 1
       
   469 a119 1
       
   470 <form name="testing" action="%SCRIPTURLPATH{"view"}%/%MAINWEB%" method="get">
       
   471 d122 1
       
   472 a122 1
       
   473 %SEARCH{ "Name:;Email:;Country:" web="%MAINWEB%" type="regex" topic="Z*" nosearch="on" nototal="on" format="<option>$topic</option>" }%
       
   474 d127 1
       
   475 a127 1
       
   476 This searches all topics in the Main web that contain "Name", "Email" and "Country" bullets. Alternatively, do a %TWIKIWEB%.FormattedSearch with =multiple="on"= on the [[%MAINWEB%.TWikiUsers]] topic.
       
   477 d139 1
       
   478 a139 1
       
   479 <form name="testing" action="%SCRIPTURLPATH{"view"}%/%MAINWEB%" method="get">
       
   480 d142 1
       
   481 a142 1
       
   482 %SEARCH{ "Name:;Email:;Country:" web="%MAINWEB%" type="regex" topic="Z*" nosearch="on" nototal="on" format="<option>$topic</option>" }%
       
   483 d152 1
       
   484 a152 1
       
   485 <form name="testing" action="%SCRIPTURLPATH{"view"}%/%MAINWEB%" method="get">
       
   486 d155 1
       
   487 a155 1
       
   488 %SEARCH{"%META:FORM.*[U]serForm" web="%MAINWEB%" type="regex" casesensitive="on" nosearch="on" format="<option>$topic</option>" sort="topic" excludetopic="Test*, TWiki*"}%
       
   489 @
       
   490 
       
   491 
       
   492 1.3
       
   493 log
       
   494 @buildrelease
       
   495 @
       
   496 text
       
   497 @d1 2
       
   498 a2 1
       
   499 %META:TOPICINFO{author="TWikiContributor" date="1127406241" format="1.1" version="3"}%
       
   500 d9 1
       
   501 a9 1
       
   502 %TOC%
       
   503 d11 2
       
   504 d16 1
       
   505 d29 1
       
   506 d35 1
       
   507 a35 1
       
   508 %SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" regex="on" multiple="on" nosearch="on" nototal="on" format="<option>$pattern(^\| *(.*?) *\|.*)</option>" }%
       
   509 d43 1
       
   510 a43 1
       
   511 %SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" regex="on" multiple="on" nosearch="on" nototal="on" format="<option>$pattern(^\| *(.*?) *\|.*)</option>" }%
       
   512 a45 1
       
   513 %BR%
       
   514 d47 3
       
   515 d53 1
       
   516 d59 1
       
   517 d73 1
       
   518 a73 1
       
   519 regex="on" casesensitive="on" nosearch="on" 
       
   520 d87 1
       
   521 a87 1
       
   522 %SEARCH{ "^\|[^\|]*\| *option *\|" topic="TopicClassification" web="%WEB%" regex="on" 
       
   523 a94 1
       
   524 %BR%
       
   525 d96 3
       
   526 d130 1
       
   527 d148 1
       
   528 d155 1
       
   529 a155 1
       
   530 %SEARCH{"%META:FORM.*[U]serForm" web="%MAINWEB%" regex="on" casesensitive="on" nosearch="on" format="<option>$topic</option>" sort="topic" excludetopic="Test*, TWiki*"}%
       
   531 d165 3
       
   532 d174 8
       
   533 a181 1
       
   534 ---+++ Solution
       
   535 d185 1
       
   536 a185 1
       
   537 %SEARCH{ "^%BASETOPIC%$" scope="topic" nosearch="on" type="regex" nototal="on" format="[[$parent][parent_link]]" }%
       
   538 d188 5
       
   539 a192 1
       
   540 However, the =[<nop>[$parent][parent_link]]= link fails if the topic has no parent set (=$parent= will be empty). You can use some Plugins.SpreadSheetPlugin magic to conditionally link to the parent or to =WebHome=: =[<nop>[$percntCALC{$IF($EXACT($parent,), %<nop>HOMETOPIC%, $parent)}$percnt][parent_link]]= 
       
   541 d196 12
       
   542 a207 1
       
   543 %SEARCH{ "^%BASETOPIC%$" scope="topic" nosearch="on" type="regex" nototal="on" format="[<nop>[$percntCALC{$IF($EXACT($parent,), <nop>%HOMETOPIC%, $parent)}$percnt][parent_link]]" }%
       
   544 d210 3
       
   545 a212 2
       
   546 ---+++ Test Case
       
   547 The parent topic of this topic is: %SEARCH{ "^%BASETOPIC%$" scope="topic" nosearch="on" type="regex" nototal="on" format="$percntCALC{$IF($EXACT($parent,), %HOMETOPIC%, $parent)}$percnt" }%
       
   548 d214 24
       
   549 a237 1
       
   550 ---++ Pattern 5: Search and display the home topics of public webs in a list
       
   551 d283 35
       
   552 a317 1
       
   553 ---++ Pattern 6: Extract a value from a bullet list
       
   554 d328 1
       
   555 a328 1
       
   556 %SEARCH{"   * [N]ame: " topic="%TOPIC%" regex="on" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="---+!! $pattern(.*   \* Name: ([^\n]*).*)"}%
       
   557 d339 6
       
   558 a344 1
       
   559 %SEARCH{"   * [N]ame: " topic="%TOPIC%" regex="on" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="---+!! $pattern(.*   \* Name: ([^\n]*).*)"}%
       
   560 a345 1
       
   561 ---++ Pattern 7: Search for Form and Meta data: explained
       
   562 d347 1
       
   563 d353 1
       
   564 a353 1
       
   565 %<nop>SEARCH{ "[S]tatus.*(td..td|value\=).*[W]aiting" casesensitive="on" regex="on" 
       
   566 d359 1
       
   567 d368 1
       
   568 a368 1
       
   569 %<nop>SEARCH{ "[O]peratingSystem.*value\=.*[O]sWin" regex="on" ... }%
       
   570 d379 1
       
   571 a379 1
       
   572 %<nop>SEARCH{ "[O]peratingSystem.*(td..td|value\=).*[O]sWin" regex="on" ... }%
       
   573 d386 5
       
   574 a390 1
       
   575 ---++ Pattern 8: Search all topics that have been moved
       
   576 d392 1
       
   577 d396 1
       
   578 d399 1
       
   579 a399 1
       
   580 =Moved topics: %<nop>SEARCH{ "%META\:TOPICMOVED" regex="on" format="$topic, " nosearch="on" noheader="on" nosummary="on" }%=
       
   581 d403 1
       
   582 a403 4
       
   583 Moved topics: %SEARCH{ "%META\:TOPICMOVED" regex="on" format="$topic, " nosearch="on" noheader="on" nosummary="on" limit="10"}%
       
   584 
       
   585 
       
   586 ---++ Contributors
       
   587 d405 1
       
   588 a405 1
       
   589 TWiki:Main.AntonAylward, TWiki:Main.ArthurClemens, TWiki:Main.JosMaccabiani, TWiki:Main.PeterThoeny, TWiki:Main.SueLocke
       
   590 d407 1
       
   591 a407 1
       
   592 __Related Topics:__ UserDocumentationCategory
       
   593 @
       
   594 
       
   595 
       
   596 1.2
       
   597 log
       
   598 @buildrelease
       
   599 @
       
   600 text
       
   601 @d1 1
       
   602 a1 1
       
   603 %META:TOPICINFO{author="TWikiContributor" date="1127406241" format="1.1" version="2"}%
       
   604 d88 1
       
   605 a88 1
       
   606 ---++ Pattern 3a: listbox with all user names
       
   607 d94 1
       
   608 a94 1
       
   609 ---+++ Solution
       
   610 d118 2
       
   611 a119 8
       
   612 ---++ Pattern 3b: listbox with all user names - select multiple names
       
   613 
       
   614 ---+++ Problem
       
   615 
       
   616 Suppose you want to send mail from a form on topic page to a selected list of __multiple__ %MAINWEB%.TWikiUsers  
       
   617 
       
   618 ---+++ Solution
       
   619 The example of Pattern 3a produces the list box.  Add a MULTIPLE to the _select_ statement, i.e.:
       
   620 d124 1
       
   621 a124 1
       
   622 Please note that the Search pattern is unchanged compared to Pattern 3a. The change is in the HTML form element.
       
   623 d126 1
       
   624 a126 2
       
   625 ---+++ Test case
       
   626 The Search pattern 3a with the abovementioned modification is, in effect:
       
   627 d135 16
       
   628 @
       
   629 
       
   630 
       
   631 1.1
       
   632 log
       
   633 @buildrelease
       
   634 @
       
   635 text
       
   636 @d1 1
       
   637 a1 1
       
   638 %META:TOPICINFO{author="TWikiContributor" date="1127406241" format="1.1" version="1"}%
       
   639 d47 2
       
   640 a48 2
       
   641 	1. create a search to display all topics where one form field is set to a certain value
       
   642 	1. create a search to filter the list above based on the values of a second form field
       
   643 d53 2
       
   644 a54 2
       
   645 	* !TopicClassification = One, Two or Three
       
   646 	* !TopicStatus = Test or Final
       
   647 d57 2
       
   648 a58 2
       
   649 	1. List all topics where the !TopicClassification field is set to 'Two'
       
   650 	2. Enable the user to filter this list based on the values of !TopicStatus
       
   651 d65 1
       
   652 a65 1
       
   653 format="	* $topic - <font face=\"arial,helvetica\" size=\"1\"> 
       
   654 d223 1
       
   655 a223 1
       
   656 %SEARCH{"	* [N]ame: " topic="%TOPIC%" regex="on" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="---+!! $pattern(.*	\* Name: ([^\n]*).*)"}%
       
   657 d230 1
       
   658 a230 1
       
   659 	* Name: John Doe
       
   660 d234 1
       
   661 a234 1
       
   662 %SEARCH{"	* [N]ame: " topic="%TOPIC%" regex="on" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="---+!! $pattern(.*	\* Name: ([^\n]*).*)"}%
       
   663 d239 2
       
   664 a240 2
       
   665 	* why is this searching the metadata, shouldn't it just search the text?
       
   666 	* what is the meaning of the =td..td= in the search expression? 
       
   667 d259 2
       
   668 a260 2
       
   669 	* Using square brackets is a trick to avoid a hit on the topic doing the search.
       
   670 	* The =.*= indicate that there can be any number of any character between =OperatingSystem= and =value= in the (whole) file
       
   671 @