none
[openafs-wiki.git] / TWiki / FormattedSearch.mdwn
1 <div>
2   <ul>
3     <li><a href="#TWiki Formatted Search Results"> TWiki Formatted Search Results</a><ul>
4         <li><a href="#Overview"> Overview</a></li>
5         <li><a href="#Syntax"> Syntax</a></li>
6         <li><a href="#Examples"> Examples</a><ul>
7             <li><a href="#Bullet list showing topic name a"> Bullet list showing topic name and summary</a></li>
8           </ul>
9         </li>
10       </ul>
11     </li>
12     <li><a href="#TWiki Installation Error">TWiki Installation Error</a><ul>
13         <li>
14           <ul>
15             <li><a href="#Table showing form field values"> Table showing form field values of topics with a form</a></li>
16             <li><a href="#Extract some text from a topic u"> Extract some text from a topic using regular expression</a></li>
17           </ul>
18         </li>
19       </ul>
20     </li>
21     <li><a href="#TWiki Installation Error">TWiki Installation Error</a></li>
22   </ul>
23 </div>
24
25 # <a name="TWiki Formatted Search Results"></a> TWiki Formatted Search Results
26
27 _Inline search feature allows flexible formatting of search result_
28
29 ## <a name="Overview"></a> Overview
30
31 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 |" }%`).
32
33 ## <a name="Syntax"></a> Syntax
34
35 Two paramters can be used to specify a customized search result:
36
37 1. `header="..."` parameter
38
39 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. <br />`header="| *Topic:* | *Summary:* |"`
40
41 2. `format="..."` parameter
42
43 Use the format paramter to specify the format of one search hit. I.e. <br />`format="| $topic | $summary |"`
44
45 Variables that can be used in the format string:
46
47 <table border="1" cellpadding="0" cellspacing="0">
48   <tr>
49     <th bgcolor="#99CCCC"><strong> Name: </strong></th>
50     <th bgcolor="#99CCCC"><strong> Expands To: </strong></th>
51   </tr>
52   <tr>
53     <td><code>$n</code></td>
54     <td> New line </td>
55   </tr>
56   <tr>
57     <td><code>$web</code></td>
58     <td> Name of the web </td>
59   </tr>
60   <tr>
61     <td><code>$topic</code></td>
62     <td> Topic name </td>
63   </tr>
64   <tr>
65     <td><code>$text</code></td>
66     <td> Formatted topic text </td>
67   </tr>
68   <tr>
69     <td><code>$locked</code></td>
70     <td> LOCKED flag (if any) </td>
71   </tr>
72   <tr>
73     <td><code>$date</code></td>
74     <td> Time stamp of last topic update, i.e. <code>29 Jun 2010 - 15:34</code></td>
75   </tr>
76   <tr>
77     <td><code>$isodate</code></td>
78     <td> Time stamp of last topic update, i.e. <code>2010-06-29T15:34Z</code></td>
79   </tr>
80   <tr>
81     <td><code>$rev</code></td>
82     <td> Number of last topic revision, i.e. <code>1.4</code></td>
83   </tr>
84   <tr>
85     <td><code>$wikiusername</code></td>
86     <td> Wiki user name of last topic update, i.e. <code>Main.JohnSmith</code></td>
87   </tr>
88   <tr>
89     <td><code>$username</code></td>
90     <td> User name of last topic update, i.e. <code>JohnSmith</code></td>
91   </tr>
92   <tr>
93     <td><code>$summary</code></td>
94     <td> Topic summary </td>
95   </tr>
96   <tr>
97     <td><code>$formfield(name)</code></td>
98     <td> The field value of a form field, i.e. <code>$formfield(TopicClassification)</code> would get expanded to <code>PublicFAQ</code>. This applies only to topics that have a [[Main/TWikiForms]]</td>
99   </tr>
100   <tr>
101     <td><code>$pattern(reg-exp)</code></td>
102     <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>
103   </tr>
104 </table>
105
106 **_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.
107
108 ## <a name="Examples"></a> Examples
109
110 ### <a name="Bullet list showing topic name a"></a> Bullet list showing topic name and summary
111
112 Write this:
113
114 `%SEARCH{ "FAQ" scope="topic" nosearch="on" nototal="on" header="   * *Topic: Summary:*" format="   * [[$topic]]: $summary" }%`
115
116 To get this:
117
118 # <a name="TWiki Installation Error"></a> TWiki Installation Error
119
120 Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
121
122 ### <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
123
124 Write this in the Know web:
125
126 `| *Topic:* | *OperatingSystem:* | *OsVersion:* |`<br />`%SEARCH{ "[T]opicClassification.*?value=\"[P]ublicFAQ\"" scope="text" regex="on" nosearch="on" nototal="on" format="| [[$topic]] | $formfield(OperatingSystem) | $formfield(OsVersion) |" }%`
127
128 To get this:
129
130 <table border="1" cellpadding="1" cellspacing="0">
131   <tr>
132     <th bgcolor="#99CCCC"><strong>Topic:</strong></th>
133     <th bgcolor="#99CCCC"><strong>OperatingSystem:</strong></th>
134     <th bgcolor="#99CCCC"><strong>OsVersion:</strong></th>
135   </tr>
136   <tr>
137     <td><a href="http://www.dementia.org/twiki//view/Know/IncorrectDllVersionW32PTH10DLL">IncorrectDllVersionW32PTH10DLL</a></td>
138     <td><a href="http://www.dementia.org/twiki//view/Know/OsWin">OsWin</a></td>
139     <td> 95/98 </td>
140   </tr>
141   <tr>
142     <td><a href="http://www.dementia.org/twiki//view/Know/WinDoze95Crash">WinDoze95Crash</a></td>
143     <td><a href="http://www.dementia.org/twiki//view/Know/OsWin">OsWin</a></td>
144     <td> 95 </td>
145   </tr>
146 </table>
147
148 ### <a name="Extract some text from a topic u"></a> Extract some text from a topic using regular expression
149
150 Write this:
151
152 `%SEARCH{ "__Back to\:__ TWikiFAQ" scope="text" regex="on" nosearch="on" nototal="on" header="TWiki FAQs:" format="   * $pattern(.*?FAQ\:[\n\r]*([^\n\r]+).*) [[$topic][Answer...]]" }%`
153
154 To get this:
155
156 # <a name="TWiki Installation Error"></a> TWiki Installation Error
157
158 Incorrect format of searchformat template (missing sections? There should be 4 %SPLIT% tags)
159
160 -- [[PeterThoeny]] - 28 Nov 2001 <br />