Remove old TWiki pages
[openafs-wiki.git] / TWiki / SearchPatternCookbook.mdwn
diff --git a/TWiki/SearchPatternCookbook.mdwn b/TWiki/SearchPatternCookbook.mdwn
deleted file mode 100644 (file)
index 746ae2d..0000000
+++ /dev/null
@@ -1,397 +0,0 @@
-# <a name="Search Pattern Cookbook"></a><a name=" Search Pattern Cookbook"></a> Search Pattern Cookbook
-
-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.
-
-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.
-
-<div>
-  <ul>
-    <li>
-      <ul>
-        <li><a href="#Pattern 1: Extract values from a"> Pattern 1: Extract values from a table</a></li>
-      </ul>
-    </li>
-    <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
-        <li><a href="#Pattern 2: List generated from f"> Pattern 2: List generated from form classification</a></li>
-        <li><a href="#Pattern 3: Creating lists of TWi"> Pattern 3: Creating lists of TWiki usernames</a></li>
-      </ul>
-    </li>
-    <li><a href="#TWiki Installation Error">TWiki Installation Error</a></li>
-    <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
-        <li><a href="#Pattern 4: Extract the parent of"> Pattern 4: Extract the parent of a given topic</a></li>
-      </ul>
-    </li>
-    <li><a href="#TWiki Installation Error">TWiki Installation Error</a></li>
-    <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
-        <li><a href="#Pattern 5: Show all Children of"> Pattern 5: Show all Children of a given topic</a></li>
-        <li><a href="#Pattern 6: Search and display th"> Pattern 6: Search and display the home topics of public webs in a list</a></li>
-      </ul>
-    </li>
-    <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
-        <li><a href="#Pattern 7: Create a select box w"> Pattern 7: Create a select box with values from a bullet list</a></li>
-        <li><a href="#Pattern 8: Extract a value from"> Pattern 8: Extract a value from a named bullet list item</a></li>
-      </ul>
-    </li>
-    <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
-        <li><a href="#Pattern 9: Search for Form and M"> Pattern 9: Search for Form and Meta data: explained</a></li>
-        <li><a href="#Pattern 10: Search all topics th"> Pattern 10: Search all topics that have been moved</a></li>
-      </ul>
-    </li>
-  </ul>
-</div>
-
-<a name="SearchTables"></a>
-
-## <a name="Pattern 1: Extract values from a"></a> Pattern 1: Extract values from a table
-
-### <a name="Problem definition"></a> Problem definition
-
-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:
-
-    | *Name* | *Type* | *Tooltip message* |
-    | option1 | option | |
-    | option2 | option | |
-    | option3 | option | |
-
-How to extract the 'name' values, i.e. 'option1', 'option2' and 'option3' and put them in a HTML form select input?
-
-### <a name="Solution"></a> Solution
-
-The following search pattern can be employed:
-
-    <form>
-    <select>
-    %SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="<option>$pattern(^\| *(.*?) *\|.*)</option>" }%
-    </select>
-    </form>
-
-which is, in effect:
-
-<form><select><h1><a name="TWiki Installation Error"></a> TWiki Installation Error </h1>Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags) </select></form>
-
-<a name="SearchFormClassification"></a>
-
-## <a name="Pattern 2: List generated from f"></a> Pattern 2: List generated from form classification
-
-### <a name="Problem"></a> Problem
-
-Imagine a TWiki form-based topic classification, i.e. every page has a form with several fields. How to:
-
-1. create a search to display all topics where one form field is set to a certain value
-2. create a search to filter the list above based on the values of a second form field
-
-### <a name="Test case"></a> Test case
-
-In practice: %BR% Image a TWiki form with two fields:
-
-- TopicClassification = One, Two or Three
-- TopicStatus = Test or Final
-
-We will:
-
-1. List all topics where the TopicClassification field is set to 'Two'
-2. Enable the user to filter this list based on the values of TopicStatus
-
-### <a name="Solution"></a> Solution
-
-    %SEARCH{"[T]opicClassification.*value\=.*Two;[T]opicStatus.*value\=.*%URLPARAM{type}%"
-    type="regex" casesensitive="on" nosearch="on"
-    format="   * $topic - <font face=\"arial,helvetica\" size=\"1\">
-    _last modified by_ $wikiusername _on_ $date </font> %BR% &nbsp;&nbsp;&nbsp;
-    <font face=\"arial,helvetica\" size=\"1\"> $formfield(TopicStatus) </font>"
-    sort="topic"}%
-
-The filtering select dialogue is created as in Pattern 1:
-
-    %STARTSIDEBAR%
-    *Filter:* %BR%
-    <form name="selectType" action="%SCRIPTURLPATH{"view"}%/%WEB%/" >
-    <select name="type" size="1" onchange="document.location=this.value;">
-    %SEARCH{ "^\|[^\|]*\| *option *\|" topic="TopicClassification" web="%WEB%" type="regex"
-    multiple="on" nosearch="on" nototal="on" format="<option value=%INCLUDINGTOPIC%?type=$pattern(^\| *(.*?) *\|.*)>$pattern(^\| *(.*?) *\|.*)</option>" }%
-    <option value=%INCLUDINGTOPIC%>All pages</option> </select>
-    </form>
-    %STOPSIDEBAR%
-
-This will create similar functionality as TWiki:Plugins.TopicClassificationAddOn
-
-<a name="SearchUsernames"></a>
-
-## <a name="Pattern 3: Creating lists of TWi"></a> Pattern 3: Creating lists of TWiki usernames
-
-### <a name="Problem"></a> Problem
-
-How to populate a list box with all usernames of registered TWiki users
-
-### <a name="Solution 1: Appropriate for Sep"></a><a name="Solution 1: Appropriate for Sep "></a> Solution 1: Appropriate for Sep 2004 TWiki (Cairo)
-
-    <form name="testing" action="%SCRIPTURLPATH{"view"}%/%USERSWEB%" method="get">
-    <select name="topic">
-    <option>Select user...</option>
-    %SEARCH{ "Name:;Email:;Country:" web="%USERSWEB%" type="regex" nosearch="on" nototal="on" format="<option>$topic</option>" }%
-    </select>
-    <input type="submit" value="Go" />
-    </form>
-
-Which expands to this: (here limited to all Z\* users because TWiki.org has so many)
-
-<form action="http://www.dementia.org/twiki/view/%USERSWEB%" method="get" name="testing"><select name="topic"><option>Select user...</option>
-    <h1><a name="TWiki Installation Error"></a> TWiki Installation Error </h1>Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags) </select> <input type="submit" value="Go" /></form>
-
-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|USERSWEB/TWikiUsers]] topic.
-
-### <a name="Solution 2: As Solution 1, but w"></a> Solution 2: As Solution 1, but with possibility for multi-selecting usernames
-
-The example of Solution 1 produces the list box. Add a MULTIPLE to the _select_ statement, i.e.:
-
-    <select name="topic" size="2" MULTIPLE>
-
-Please note that the Search pattern is unchanged compared to Solution 1. The change is in the HTML form element.
-
-The abovementioned modification is, in effect:
-
-<form action="http://www.dementia.org/twiki/view/%USERSWEB%" method="get" name="testing"><select multiple="MULTIPLE" name="topic" size="2"><option>Select user...</option>
-    <h1><a name="TWiki Installation Error"></a> TWiki Installation Error </h1>Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags) </select> <input type="submit" value="Go" /></form>
-
-### <a name="Solution 3: Appropriate for TWik"></a> Solution 3: Appropriate for TWiki 4 (Dakar)
-
-When the User information is stored in a [[UserForm]] (as is default in Dakar) then this list can be generated as follows:
-
-    <form name="testing" action="%SCRIPTURLPATH{"view"}%/%USERSWEB%" method="get">
-    <select name="topic">
-    <option>Select user...</option>
-    %SEARCH{"%META:FORM.*[U]serForm" web="%USERSWEB%" type="regex" casesensitive="on" nosearch="on" format="<option>$topic</option>" sort="topic" excludetopic="Test*, TWiki*"}%
-    </select>
-    <input type="submit" value="Go" />
-    </form>
-
-In the above example:
-
-- <code>**META:FORM.\*[U]serForm**</code> 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
-- <code>**excludetopic="Test\*, TWiki\*"**</code> 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
-
-<a name="SearchTopicParent"></a>
-
-## <a name="Pattern 4: Extract the parent of"></a> Pattern 4: Extract the parent of a given topic
-
-### <a name="Problem"></a> Problem
-
-How to get to the parent of the current topic to display on the page?
-
-### <a name="Solution 1: Using META"></a> Solution 1: Using META
-
-Since TWiki 4.0 you can now use the META variable:
-
-`%META{ "parent" dontrecurse="on" }%`
-
-### <a name="Solution 2: Using _SpreadSheetPl"></a> Solution 2: Using SpreadSheetPlugin
-
-You might think that the following Search would do the trick:
-
-    %SEARCH{ "^%BASETOPIC%$" scope="topic" nosearch="on" type="regex" nonoise="on" format="   * $parent" }%
-
-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`:
-
-    $percntCALC{$IF($EXACT($parent,),<nop>,$NOP(   * $parent))}$percnt
-
-So the total Search query to find a topic's parent topic is:
-
-    %SEARCH{ "^%BASETOPIC%$" scope="topic" type="regex" nonoise="on" format="$percntCALC{$IF($EXACT($parent,),<nop>,$NOP(   * $parent))}$percnt" }%
-
-#### <a name="Test Case"></a> Test Case
-
-The parent topic of this topic is:
-
-# <a name="TWiki Installation Error"></a> TWiki Installation Error
-
-Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
-
-### <a name="Solution 3: Using IF statement"></a> Solution 3: Using IF statement
-
-This pattern can be rewritten using `%IF%`, removing the dependency on SpreadSheetPlugin:
-
-    %SEARCH{ "^%BASETOPIC%$" web="%BASEWEB%" scope="topic" type="regex" nonoise="on" format="$percntIF{$quot$parent$quot then=$quot   * $parent$quot else=$quot<nop>$quot}$percnt" }%
-
-#### <a name="Test Case"></a> Test Case
-
-The parent topic of this topic is: %BR%
-
-# <a name="TWiki Installation Error"></a> TWiki Installation Error
-
-Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
-
-<a name="SearchTopicChildren"></a>
-
-## <a name="Pattern 5: Show all Children of"></a><a name="Pattern 5: Show all Children of "></a> Pattern 5: Show all Children of a given topic
-
-### <a name="Problem"></a> Problem
-
-How to get to the list of all children of the current topic to display on the page?
-
-### <a name="Solution"></a> Solution
-
-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:
-
-    Children:
-    %SEARCH{ "META\:TOPICPARENT.*\"%TOPIC%\"" type="regex" nonoise="on" format="[[$topic]]" separator=", " }%
-
-**_Note:_** Replace `%TOPIC%` with `%BASETOPIC%` if you put this SEARCH into the skin or a sidebar.
-
-<a name="SearchPublicWebsList"></a>
-
-## <a name="Pattern 6: Search and display th"></a> Pattern 6: Search and display the home topics of public webs in a list
-
-### <a name="Problem"></a> Problem
-
-How to find and display public webs in a drop down list box.
-
-### <a name="Solution"></a> Solution
-
-_Thanks to TWiki:Main.PeterThoeny for these solutions._
-
-    <form>
-    <select name="topic">
-    <option value="%TOPIC%">Select...</option>
-    %SEARCH{ "%HOMETOPIC%" scope="topic" web="all" topic="%HOMETOPIC%" format="<option value=\"$web.$topic\">$web</option>" separator=" " }%
-    </select>
-    <input type="submit"  value="Go" />
-    </form>
-
-### <a name="Test case"></a> Test case
-
-Public webs of TWiki.
-
-<form><select name="topic"><option value="%TOPIC%">Select...</option>
-    <h1><a name="TWiki Installation Error"></a> TWiki Installation Error </h1>Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags) </select> <input type="submit" value="Go" /></form>
-
-%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.
-
-### <a name="Alternative solution"></a> Alternative solution
-
-This result can also be accomplished with the %WEBLIST% variable.
-
-<form><select name="topic"><option value="%TOPIC%">Select...</option>
-    <p>
-    </p></select> <input type="submit" value="Go" /></form>
-
-<a name="SearchBulletList"></a>
-
-## <a name="Pattern 7: Create a select box w"></a> Pattern 7: Create a select box with values from a bullet list
-
-### <a name="Problem"></a> Problem
-
-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.
-
-For example, CategoryList has:
-
-- Clients
-- People
-- Rooms
-- Buildings
-
-### <a name="Solution"></a> Solution
-
-The following search pattern can be employed:
-
-    <select name="type">
-    <option>Select category...</option>
-    %SEARCH{"   *\s*.*?" topic="CategoryList" type="regex" multiple="on" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="<option>$pattern(.*   \*\s*([^\n]*).*)</option>"}%
-    </select>
-
-To render the bullet list as a comma-separated list, use the `separator` parameter:
-
-    %SEARCH{"   *\s*.*?" topic="CategoryList" type="regex" multiple="on" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" separator="," format="$pattern(.*   \*\s*([^\n]*).*)"}%
-
-<a name="SearchNamedBulletList"></a>
-
-## <a name="Pattern 8: Extract a value from"></a><a name="Pattern 8: Extract a value from "></a> Pattern 8: Extract a value from a named bullet list item
-
-### <a name="Problem"></a> Problem
-
-Display the user name in the user's topic title
-
-### <a name="Solution"></a> Solution
-
-Search for the `Name:` entry.
-
-    %SEARCH{"   * [N]ame: " topic="%TOPIC%" type="regex" casesensitive="on" nosummary="on" nosearch="on" noheader="on" nototal="on" format="---+!! $pattern(.*   \* Name: ([^\n]*).*)"}%
-
-### <a name="Test case"></a> Test case
-
-To create a test case, we will put a name entry here:
-
-- Name: John Doe
-
-Search result:
-
-# <a name="TWiki Installation Error"></a> TWiki Installation Error
-
-Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
-
-<a name="SearchMetaData"></a>
-
-## <a name="Pattern 9: Search for Form and M"></a> Pattern 9: Search for Form and Meta data: explained
-
-### <a name="Problem"></a> Problem
-
-Below is an example of a search that searches form data. The questions are:
-
-- why is this searching the metadata, shouldn't it just search the text?
-- what is the meaning of the `td..td` in the search expression?
-
-    %SEARCH{ "[S]tatus.*(td..td|value\=).*[W]aiting" casesensitive="on" type="regex"
-    nosearch="on" nototal="on" format="| [[$topic]]<br /> ($date - $rev -
-    [[%SCRIPTURLPATH{rdiff}%/$web/$topic][Diffs]]) |"}%
-
-### <a name="Solution"></a> Solution
-
-%SEARCH depends on grep, and grep searches the whole file, including the meta data.
-
-An example meta data form field is:
-
-    %META:FIELD{name="OperatingSystem" title="OperatingSystem" value="OsWin"}%
-
-So a search for a form field could look like:
-
-    %SEARCH{ "[O]peratingSystem.*value\=.*[O]sWin" type="regex" ... }%
-
-- Using square brackets is a trick to avoid a hit on the topic doing the search.
-- The `.*` indicate that there can be any number of any character between `OperatingSystem` and `value` in the (whole) file
-
-Now the original file format of the category table (the predecessor of the TWiki forms) looks like this:
-
-    <td valign="top" align="right"> OperatingSystem:  </td><td>  OsWin </td>
-
-The following search finds topics in the old and new format:
-
-    %SEARCH{ "[O]peratingSystem.*(td..td|value\=).*[O]sWin" type="regex" ... }%
-
-The `td..td` matches `td<>td`; a simple search on `"[O]peratingSystem.*[O]sWin"` could find a hit in the topic text by coincidence.
-
-A simple `%SEARCH{ "[O]peratingSystem.*value\=.*[O]sWin" ...}%` search is sufficient if you do not have topics in the old format.
-
-<a name="MovedTopics"></a>
-
-## <a name="Pattern 10: Search all topics th"></a> Pattern 10: Search all topics that have been moved
-
-### <a name="Problem"></a> Problem
-
-How would I go about listing all moved topics ?
-
-### <a name="Solution"></a> Solution
-
-Search for the META:TOPICMOVED meta data. Type this:
-
-`Moved topics: %SEARCH{ "%META\:TOPICMOVED" type="regex" format="$topic, " nosearch="on" noheader="on" nosummary="on" }%`
-
-to get this (limited to 10 results):
-
-Moved topics:
-
-# TWiki Installation Error
-
-Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
-
-**_Related Topics:_** [[UserDocumentationCategory]], [[SearchHelp]], [[TWikiVariables#VarSEARCH]], [[FormattedSearch]], [[RegularExpression]]
-
--- **_Contributors:_** TWiki:Main.AntonAylward, TWiki:Main.ArthurClemens, TWiki:Main.JosMaccabiani, TWiki:Main.PeterThoeny, TWiki:Main.SueLocke