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