summaryrefslogtreecommitdiff
path: root/TWiki/FormattedSearch.mdwn
blob: 591a37de95031e35d13139cacbfaac10e18181bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
%TOC% %STARTINCLUDE%

# <a name="TWiki_Formatted_Search_Results"> TWiki Formatted Search Results </a>

_Inline search feature allows flexible formatting of search result_

## <a name="Overview"> Overview </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. <br /><code>header="| \*Topic:\* | \*Summary:\* |"</code>

2. `format="..."` parameter

Use the format paramter to specify the format of one search hit. I.e. <br />`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>$n</code></td>
    <td> New line </td>
  </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, i.e. <code>%GMTIME{"$day $mon $year - $hour:$min"}%</code></td>
  </tr>
  <tr>
    <td><code>$isodate</code></td>
    <td> Time stamp of last topic update, i.e. <code>%GMTIME{"$year-$mo-$dayT$hour:$minZ"}%</code></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>$username</code></td>
    <td> User name of last topic update, i.e. <code><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(<nop>TopicClassification)</nop></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>[[TWikiForms]]</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]] - 28 Nov 2001 <br />