diff options
Diffstat (limited to 'TWiki')
-rw-r--r-- | TWiki/FormattedSearch.mdwn | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/TWiki/FormattedSearch.mdwn b/TWiki/FormattedSearch.mdwn new file mode 100644 index 00000000..89b49c92 --- /dev/null +++ b/TWiki/FormattedSearch.mdwn @@ -0,0 +1,116 @@ +**Formatted Search Using <code>**%SEARCH\{... format="..."\}%**</code> Variable** + +%TOC% + +## <a name="Preface"> Preface </a> + +By default, the format for displaying a search result is fixed, e.g. a table with rows of topic name and topic summary. 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 (i.e. <code>%SEARCH\{ "food" format="| $topic | $summary |" \}%</code>). + +## <a name="Syntax"> Syntax </a> + +Two paramters can be used to specify a customized search result: + +1. `header="..."` parameter + +Use the header paramter to specify the header of a search result. It should correspond to the format of the format parameter. This parameter is optional. I.e. <code>header="| \*Topic:\* | \*Summary:\* |"</code> + +2. `format="..."` parameter + +Use the format paramter to specify the format of one search hit. I.e. `format="| $topic | $summary |"` + +Variables that can be used in the format string: + +<table border="1" cellpadding="1" cellspacing="0"> + <tr> + <th bgcolor="#99CCCC"><strong>Name:</strong></th> + <th bgcolor="#99CCCC"><strong>Expands To:</strong></th> + </tr> + <tr> + <td><code>$web</code></td> + <td> Name of the web </td> + </tr> + <tr> + <td><code>$topic</code></td> + <td> Topic name </td> + </tr> + <tr> + <td><code>$locked</code></td> + <td> LOCKED flag (if any) </td> + </tr> + <tr> + <td><code>$date</code></td> + <td> Time stamp of last topic update </td> + </tr> + <tr> + <td><code>$rev</code></td> + <td> Number of last topic revision, i.e. <code>1.4</code></td> + </tr> + <tr> + <td><code>$wikiusername</code></td> + <td> Wiki user name of last topic update, i.e. <code>%MAINWEB%.<nop>JohnSmith</nop></code></td> + </tr> + <tr> + <td><code>$summary</code></td> + <td> Topic summary </td> + </tr> + <tr> + <td><code>$formfield(name)</code></td> + <td> The field value of a form field, i.e. <code>$formfield(<span style="background:"><font color="">Topic Classification</font></span><a href="http://LOCATION/TopicClassification">?</a>)</code> would get expanded to <code>PublicFAQ</code>. This applies only to topics that have a <span style="background:"><font color="">TWiki Form</font></span><a href="http://LOCATION/TWikiForms">?</a></td> + </tr> + <tr> + <td><code>$pattern(reg-exp)</code></td> + <td> A regular expression pattern to extract some text from a topic, i.e. <code>$pattern(.*?\*.*?Email\:\s*([^\n\r]+).*)</code> extracts the email address from a bullet of format <code>* Email: ...</code>. </td> + </tr> +</table> + +**_Note:_** For `$pattern(reg-exp)`, specify a [[RegularExpression]] that scans from start to end and contains the text you want to keep in parenthesis, i.e. `$pattern(.*?(from here.*?to here).*)`. You need to make sure that the integrity of a web page is not compromised, i.e. if you include a table make sure to include everything including the table end tag. + +## <a name="Examples"> Examples </a> + +### <a name="Bullet_list_showing_topic_name_a"> Bullet list showing topic name and summary </a> + +Write this: + +<code>%SEARCH\{ "FAQ" scope="topic" nosearch="on" nototal="on" header=" \* \*Topic: Summary:\*" format=" \* [[$topic]]: $summary" \}%</code> + +To get this: + +%SEARCH\{ "FAQ" scope="topic" nosearch="on" nototal="on" header=" \* \*Topic: Summary:\*" format=" \* [[Topic]]: $summary" \}% + +### <a name="Table_showing_form_field_values_"> Table showing form field values of topics with a form </a> + +Write this in the Know web: + +<code>| \*Topic:\* | \*OperatingSystem:\* | \*OsVersion:\* |</code><br /><code>%SEARCH\{ "[T]opicClassification.\*?value=\\"[P]ublicFAQ\\"" scope="text" regex="on" nosearch="on" nototal="on" format="| [[$topic]] | $formfield([[OperatingSystem]]) | $formfield([[OsVersion]]) |" \}%</code> + +To get this: + +<table border="1" cellpadding="1" cellspacing="0"> + <tr> + <th bgcolor="#99CCCC"><strong>Topic:</strong></th> + <th bgcolor="#99CCCC"><strong>OperatingSystem:</strong></th> + <th bgcolor="#99CCCC"><strong>OsVersion:</strong></th> + </tr> + <tr> + <td><a href="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/Know/IncorrectDllVersionW32PTH10DLL">IncorrectDllVersionW32PTH10DLL</a></td> + <td><a href="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/Know/OsWin">OsWin</a></td> + <td> 95/98 </td> + </tr> + <tr> + <td><a href="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/Know/WinDoze95Crash">WinDoze95Crash</a></td> + <td><a href="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/Know/OsWin">OsWin</a></td> + <td> 95 </td> + </tr> +</table> + +### <a name="Extract_some_text_from_a_topic_u"> Extract some text from a topic using regular expression </a> + +Write this: + +<code>%SEARCH\{ "\_\_Back to\\:\_\_ TWikiFAQ" scope="text" regex="on" nosearch="on" nototal="on" header="TWiki FAQs:" format=" \* $pattern(.\*?FAQ\\:[\\n\\r]\*([^\\n\\r]+).\*) [[$topic]\[Answer...]]" \}%</code> + +To get this: + +%SEARCH\{ "\_\_Back to\\:\_\_ [[TWikiFAQ]]" scope="text" regex="on" nosearch="on" nototal="on" header="TWiki FAQs:" format=" \* $pattern(.\*?FAQ\\:[\\n\\r]\*([^\\n\\r]+).\*) [[Topic]]" \}% + +-- [[Main/PeterThoeny]] - 24 Oct 2001 <br /> |