3 <li><a href="#TWiki Formatted Search Results"> TWiki Formatted Search Results</a><ul>
4 <li><a href="#Syntax"> Syntax</a></li>
5 <li><a href="#Examples"> Examples</a><ul>
6 <li><a href="#Bullet list showing topic name a"> Bullet list showing topic name and summary</a></li>
11 <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
14 <li><a href="#Table showing form field values"> Table showing form field values of topics with a form</a></li>
15 <li><a href="#Extract some text from a topic u"> Extract some text from a topic using regular expression</a></li>
20 <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
23 <li><a href="#Nested Search"> Nested Search</a></li>
28 <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
31 <li><a href="#Most recently changed pages"> Most recently changed pages</a></li>
36 <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
39 <li><a href="#Search with conditional output"> Search with conditional output</a></li>
44 <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
47 <li><a href="#Embedding search forms to return"> Embedding search forms to return a formatted result</a></li>
52 <li><a href="#TWiki Installation Error">TWiki Installation Error</a></li>
56 # <a name="TWiki Formatted Search Results"></a> TWiki Formatted Search Results
58 _Inline search feature allows flexible formatting of search result_
60 The `%SEARCH{...}%` variable documented in [[TWikiVariables]] has a fixed format for the search result, that is, a table consisting of topic names and topic summaries. Use the `format="..."` parameter to specify a customized format of the search result. The string of the format parameter is typically a bullet list or table row containing variables (such as `%SEARCH{ "food" format="| $topic | $summary |" }%`).
62 ## <a name="Syntax"></a> Syntax
64 Two parameters can be used to specify a customized search result:
66 1. `header="..."` parameter
68 Use the header parameter to specify the header of a search result. It should correspond to the format of the format parameter. This parameter is optional. <br /> Example: `header="| *Topic:* | *Summary:* |"`
70 2. `format="..."` parameter
72 Use the format parameter to specify the format of one search hit. <br /> Example: `format="| $topic | $summary |"`
74 Variables that can be used in the format string:
76 <table border="1" cellpadding="0" cellspacing="0">
78 <th bgcolor="#99CCCC"><strong> Name: </strong></th>
79 <th bgcolor="#99CCCC"><strong> Expands To: </strong></th>
82 <td><code>$web</code></td>
83 <td> Name of the web </td>
86 <td><code>$topic</code></td>
90 <td><code>$topic(20)</code></td>
91 <td> Topic name, "<tt>- </tt>" hyphenated each 20 characters </td>
94 <td><code>$topic(30, -<br />)</code></td>
95 <td> Topic name, hyphenated each 30 characters with separator "<tt>-<br /></tt>" </td>
98 <td><code>$topic(40, ...)</code></td>
99 <td> Topic name, shortended to 40 characters with "<tt>...</tt>" indication </td>
102 <td><code>$text</code></td>
103 <td> Formatted topic text. In case of a <code>multiple="on"</code> search, it is the line found for each search hit. </td>
106 <td><code>$locked</code></td>
107 <td> LOCKED flag (if any) </td>
110 <td><code>$date</code></td>
111 <td> Time stamp of last topic update, e.g. <code>29 Jun 2010 - 15:45</code></td>
114 <td><code>$isodate</code></td>
115 <td> Time stamp of last topic update, e.g. <code>2010-06-29T15:45Z</code></td>
118 <td><code>$rev</code></td>
119 <td> Number of last topic revision, e.g. <code>1.4</code></td>
122 <td><code>$username</code></td>
123 <td> Login name of last topic update, e.g. <code>jsmith</code></td>
126 <td><code>$wikiname</code></td>
127 <td> Wiki user name of last topic update, e.g. <code>JohnSmith</code></td>
130 <td><code>$wikiusername</code></td>
131 <td> Wiki user name of last topic update, like <code>Main.JohnSmith</code></td>
134 <td><code>$createdate</code></td>
135 <td> Time stamp of topic revision 1.1 </td>
138 <td><code>$createusername</code></td>
139 <td> Login name of topic revision 1.1, e.g. <code>jsmith</code></td>
142 <td><code>$createwikiname</code></td>
143 <td> Wiki user name of topic revision 1.1, e.g. <code>JohnSmith</code></td>
146 <td><code>$createwikiusername</code></td>
147 <td> Wiki user name of topic revision 1.1, e.g. <code>Main.JohnSmith</code></td>
150 <td><code>$summary</code></td>
151 <td> Topic summary </td>
154 <td><code>$formname</code></td>
155 <td> The name of the form attached to the topic; empty if none </td>
158 <td><code>$formfield(name)</code></td>
159 <td> The field value of a form field; for example, <code>$formfield(TopicClassification)</code> would get expanded to <code>PublicFAQ</code>. This applies only to topics that have a [[Main/TWikiForms]]</td>
162 <td><code>$formfield(name, 10)</code></td>
163 <td> Form field value, "<tt>- </tt>" hyphenated each 10 characters </td>
166 <td><code>$formfield(name, 20, -<br />)</code></td>
167 <td> Form field value, hyphenated each 20 characters with separator "<tt>-<br /></tt>" </td>
170 <td><code>$formfield(name, 30, ...)</code></td>
171 <td> Form field value, shortended to 30 characters with "<tt>...</tt>" indication </td>
174 <td><code>$pattern(reg-exp)</code></td>
175 <td> A regular expression pattern to extract some text from a topic (does not search meta data; use <code>$formfield</code> instead). In case of a <code>multiple="on"</code> search, the pattern is applied to the line found in each search hit. The pattern must cover the whole text (topic or line). For example, <code>$pattern(.*?\*.*?Email\:\s*([^\n\r]+).*)</code> extracts the email address from a bullet of format <code>* Email: ...</code>. This example has non-greedy <code>.*?</code> patterns to scan for the first occurance of the Email bullet; use greedy <code>.*</code> patterns to scan for the last occurance. </td>
178 <td><code>$n</code> or <code>$n()</code></td>
182 <td><code>$nop</code> or <code>$nop()</code></td>
183 <td> Is a "no operation". This variable gets removed; useful for nested search </td>
186 <td><code>$quot</code></td>
187 <td> Double quote (<code>"</code>). Alternatively write <code>\"</code> to escape it </td>
190 <td><code>$percnt</code></td>
191 <td> Percent sign (<code>%</code>) </td>
194 <td><code>$dollar</code></td>
195 <td> Dollar sign (<code>$</code>) </td>
199 **_Note:_** For `$pattern(reg-exp)`, specify a [[RegularExpression]] that scans from start to end and contains the text you want to keep in parenthesis, like `$pattern(.*?(from here.*?to here).*)`. You need to make sure that the integrity of a web page is not compromised; for example, if you include a table make sure to include everything including the table end tag.
201 ## <a name="Examples"></a> Examples
203 <a name="SearchBulletList"></a>
205 ### <a name="Bullet list showing topic name a"></a> Bullet list showing topic name and summary
209 `%SEARCH{ "FAQ" scope="topic" nosearch="on" nototal="on" header=" * *Topic: Summary:*" format=" * [[$topic]]: $summary" }%`
213 # <a name="TWiki Installation Error"></a> TWiki Installation Error
215 Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
217 ### <a name="Table showing form field values"></a><a name="Table showing form field values "></a> Table showing form field values of topics with a form
219 **Write this in the Know web:**
221 `| *Topic:* | *OperatingSystem:* | *OsVersion:* |`<br />`%SEARCH{ "[T]opicClassification.*?value=\"[P]ublicFAQ\"" scope="text" regex="on" nosearch="on" nototal="on" format="| [[$topic]] | $formfield(OperatingSystem) | $formfield(OsVersion) |" }%`
225 <table border="1" cellpadding="1" cellspacing="0">
227 <th bgcolor="#99CCCC"><strong>Topic:</strong></th>
228 <th bgcolor="#99CCCC"><strong>OperatingSystem:</strong></th>
229 <th bgcolor="#99CCCC"><strong>OsVersion:</strong></th>
232 <td><a href="http://www.dementia.org/twiki//view/Know/IncorrectDllVersionW32PTH10DLL">IncorrectDllVersionW32PTH10DLL</a></td>
233 <td><a href="http://www.dementia.org/twiki//view/Know/OsWin">OsWin</a></td>
237 <td><a href="http://www.dementia.org/twiki//view/Know/WinDoze95Crash">WinDoze95Crash</a></td>
238 <td><a href="http://www.dementia.org/twiki//view/Know/OsWin">OsWin</a></td>
243 ### <a name="Extract some text from a topic u"></a> Extract some text from a topic using regular expression
247 `%SEARCH{ "__Back to\:__ TWikiFAQ" scope="text" regex="on" nosearch="on" nototal="on" header="TWiki FAQs:" format=" * $pattern(.*?FAQ\:[\n\r]*([^\n\r]+).*) [[$topic][Answer...]]" }%`
251 # <a name="TWiki Installation Error"></a> TWiki Installation Error
253 Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
255 ### <a name="Nested Search"></a> Nested Search
257 Search can be nested. For example, search for some topics, then form a new search for each topic found in the first search. The idea is to build the nested search string using a formatted search in the first search.
259 Here is an example. Let's search for all topics that contain the word "culture" (first search), and let's find out where each topic found is linked from (second search).
262 - `%SEARCH{ "culture" format=" * $topic is referenced by: (list all references)" nosearch="on" nototal="on" }%`
263 - Second search. For each hit we want this search:
264 - `%SEARCH{ "(topic found in first search)" format="$topic" nosearch="on" nototal="on" separator=", " }%`
265 - Now let's nest the two. We need to escape the second search, e.g. the first search will build a valid second search string. Note that we escape the second search so that it does not get evaluated prematurely by the first search:
266 - Use `$percnt` to escape the leading percent of the second search
267 - Use `\"` to escape the double quotes
268 - Use `$dollar` to escape the `$` of `$topic`
269 - Use `$nop` to escape the `}%` sequence
273 `%SEARCH{ "culture" format=" * $topic is referenced by:$n * $percntSEARCH{ \"$topic\" format=\"$dollartopic\" nosearch=\"on\" nototal=\"on\" separator=\", \" }$nop%" nosearch="on" nototal="on" }%`
277 # <a name="TWiki Installation Error"></a> TWiki Installation Error
279 Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
281 ### <a name="Most recently changed pages"></a> Most recently changed pages
285 `%SEARCH{ "\.*" scope="topic" regex="on" nosearch="on" nototal="on" order="modified" reverse="on" format="| [[$topic]] | $wikiusername | $date |" limit="7" }%`
289 # <a name="TWiki Installation Error"></a> TWiki Installation Error
291 Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
293 ### <a name="Search with conditional output"></a> Search with conditional output
295 A regular expression search is flexible, but there are limitations. For example, you cannot show all topics that are up to exactly one week old, or create a report that shows all records with invalid form fields or fields within a certain range, etc. You need some additional logic to format output based on a condition:
297 1. Specify a search which returns more hits then you need
298 2. For each search hit apply a spreadsheet formula to determine if the hit is needed
299 3. If needed, format and output the result
300 4. Else supress the search hit
302 This requires the TWiki:Plugins.SpreadSheetPlugin. The following example shows all topics that are up to exactly one week old.
306 `%CALC{$SET(weekold, $TIMEADD($TIME(), -7, day))}%` %BR% `%SEARCH{ "." scope="topic" regex="on" nosearch="on" nototal="on" order="modified" reverse="on" format="$percntCALC{$IF($TIME($date) < $GET(weekold), <nop>, | [[$topic]] | $wikiusername | $date | $rev |)}$percnt" limit="100" }%`
308 - The first line sets the `weekold` variable to the serialized date of exactly one week ago
309 - The SEARCH has a deferred CALC. The `$percnt` makes sure that the CALC gets executed once for each search hit
310 - The CALC compares the date of the topic with the `weekold` date
311 - If topic is older, a `<nop>` is returned, which gets removed at the end of the TWiki rendering process
312 - Otherwise, the search hit is formatted and returned
316 # <a name="TWiki Installation Error"></a> TWiki Installation Error
318 Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
320 ### <a name="Embedding search forms to return"></a> Embedding search forms to return a formatted result
322 Use an HTML form and an embedded formatted search on the same topic. You can link them together with an `%URLPARAM{"..."}%` variable. Example:
326 <form action="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%">
328 <input type="text" name="q" size="32" value="%URLPARAM{"q"}%" />
329 <input type="submit" value="Search" />
332 %SEARCH{ search="%URLPARAM{"q"}%" format=" * $web.$topic: %BR% $summary" nosearch="on" }%
336 <form action="http://www.dementia.org/twiki//view/%WEB%/%TOPIC%"> Find Topics: <input name="q" size="32" type="text" value="" /> <input type="submit" value="Search" /></form>
340 # <a name="TWiki Installation Error"></a> TWiki Installation Error
342 Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
344 -- TWiki:Main.PeterThoeny - 16 Mar 2004