%SEARCH{...}%
is a table consisting of topic names and topic summaries. Use the format="..."
parameter to customize the search result. The format parameter typically defines a bullet or a table row containing macros, such as %SEARCH{ "food" format="| $topic | $summary |" }%
. See %SEARCH{...}%
for other search parameters, such as separator=""
.
header="..."
parameter header="| *Topic:* | *Summary:* |"Format tokens that can be used in the header string:
Name: | Expands To: |
---|---|
$web |
Name of the web |
$ntopics |
Number of topics found in current web. Will be 0 (zero). |
$nhits |
Number of hits if multiple="on" . Will be 0 (zero). |
$pager |
pager control - can be optionally customised using the pagerformat below |
$n or $n() |
New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar Most macros accept parameter strings which are split over multiple lines. This is usually more readable than using Note that newline is not a line break. The browser will wrap the lines together. If you require a line break, displaying the results on two lines, use |
$nop or $nop() |
Is a "no operation". This token gets removed; useful for nested search |
$quot |
Double quote (" ) (\" also works) |
$percent |
Percent sign (% ) ($percnt also works) |
$dollar |
Dollar sign ($ ) |
$lt |
Less than sign (< ) |
$gt |
Greater than sign (> ) |
$amp |
Ampersand (& ) |
$comma |
Comma (, ) |
Note that if the separator parameter for SEARCH is not defined a newline is added after the header.
footer="..."
parameter footer="| *Total:* | *$nhits* |"Format tokens that can be used in the footer string:
Name: | Expands To: |
---|---|
$web |
Name of the web |
$ntopics |
Number of topics found in current web |
$nhits |
Number of hits if multiple="on" . Cumulative across all topics in current web. Identical to $ntopics unless multiple="on" |
$pager |
pager control - can be optionally customised using the pagerformat below |
$n or $n() |
New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar Most macros accept parameter strings which are split over multiple lines. This is usually more readable than using Note that newline is not a line break. The browser will wrap the lines together. If you require a line break, displaying the results on two lines, use |
$nop or $nop() |
Is a "no operation". This token gets removed; useful for nested search |
$quot |
Double quote (" ) (\" also works) |
$percent |
Percent sign (% ) ($percnt also works) |
$dollar |
Dollar sign ($ ) |
$lt |
Less than sign (< ) |
$gt |
Greater than sign (> ) |
$amp |
Ampersand (& ) |
$comma |
Comma (, ) |
Note that if the separator parameter for SEARCH is not defined a newline is added after the last search result.
pagerformat="..."
parameter pagerformat="Page $currentpage of $numberofpages [[$nexturl][next page]]"Format tokens that can be used in the pagerformat string:
Name: | Expands To: |
---|---|
$previouspage |
The page number before the currently displayed one |
$currentpage |
The currently displayed page number |
$nextpage |
The page number after the currently displayed one |
$numberofpages |
Total number of pages there are results for |
$pagesize |
The number of results per page |
$previousurl |
full URL to the previous page - IF using the built in pager system |
$nexturl |
full URL to the previous page - IF using the built in pager system |
$previousbutton |
skin template (SEARCH:pager_previous) html for the full URL to the previous page - IF using the built in pager system |
$nextbutton |
skin template (SEARCH:pager_next) html for the full URL to the previous page - IF using the built in pager system |
$n or $n() |
New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar Most macros accept parameter strings which are split over multiple lines. This is usually more readable than using Note that newline is not a line break. The browser will wrap the lines together. If you require a line break, displaying the results on two lines, use |
$nop or $nop() |
Is a "no operation". This token gets removed; useful for nested search |
$quot |
Double quote (" ) (\" also works) |
$percent |
Percent sign (% ) ($percnt also works) |
$dollar |
Dollar sign ($ ) |
$lt |
Less than sign (< ) |
$gt |
Greater than sign (> ) |
$amp |
Ampersand (& ) |
$comma |
Comma (, ) |
format="..."
parameter format="| $topic | $summary |"Format tokens that can be used in the format string:
Name: | Expands To: |
---|---|
$web |
Name of the web |
$topic |
Topic name |
$topic(20) |
Topic name, "- " hyphenated every 20 characters |
$topic(30, -<br />) |
Topic name, hyphenated every 30 characters with separator "-<br />" |
$topic(40, ...) |
Topic name, shortened to 40 characters with trailing ellipsis. |
$parent |
Name of parent topic; empty if not set |
$parent(20) |
Name of parent topic, same hyphenation/shortening as $topic() |
$text |
Formatted topic text. In case of a multiple="on" search, it is the line found for each search hit. |
$locked |
LOCKED flag (if any) |
$date |
Time stamp of last topic update, e.g. 25 Dec 2024 - 17:23 |
$isodate |
Time stamp of last topic update, e.g. 2024-12-25T17:23Z |
$index |
number of total results - can be used as a running counter in the format , or in the footer . This $index is not affected by web based partitioning of results. |
$item |
the full name of a result item - in a SEARCH context, equivalent to $web.$topic |
$rev |
Number of last topic revision, e.g. 4 |
$username |
Login name of last topic update, e.g. jsmith |
$wikiname |
Wiki user name of last topic update, e.g. JohnSmith |
$wikiusername |
Wiki user name of last topic update, like Main.JohnSmith |
$createdate |
Time stamp of topic revision 1 |
$createusername |
Login name of topic revision 1, e.g. jsmith |
$createwikiname |
Wiki user name of topic revision 1, e.g. JohnSmith |
$createwikiusername |
Wiki user name of topic revision 1, e.g. Main.JohnSmith |
$summary |
Topic summary, just the plain text, all formatting and line breaks removed; up to 162 characters |
$summary(50) |
Topic summary, up to 50 characters shown |
$summary(showvarnames) |
Topic summary, with %SOMEMACRO{...}% macros shown as SOMEMACRO{...} |
$summary(noheader) |
Topic summary, with leading ---+ headers removedNote: The tokens can be combined, for example $summary(100, showvarnames, noheader) |
$summary(searchcontext) |
Creates a topic summary with the search terms highlighted |
$summary(searchcontext, 50) |
Creates a topic summary with the search terms highlighted, up to 50 characters |
$changes |
Summary of changes between latest rev and previous rev |
$changes(n) |
Summary of changes between latest rev and rev n |
$formname |
The name of the form attached to the topic; empty if none |
$formfield(name) |
The field value of a form field; for example, if FAQWhatIsWikiWiki was a search hit, $formfield(TopicClassification) would get expanded to ==. This applies only to topics that have a DataForm. For multi-line textfields new lines are replace by an HTML <br /> |
$formfield(name, 10) |
Form field value, "- " hyphenated every 10 characters |
$formfield(name, 20, -<br />) |
Form field value, hyphenated every 20 characters with separator "-<br />" |
$formfield(name,30,...) |
Form field value, shortened to 30 characters with trailing ellipsis. |
$formfield(name, display) |
Form field value after mapping the stored value to the display value (use with +values form fields). You can still use the hyphenation controls described above by placing them after display e.g. $formfield(name, display, 10) |
$pattern(reg-exp) |
A regular expression pattern to extract some text from a topic (does not search meta data; use $formfield instead). In case of a multiple="on" search, the pattern is applied to the line found in each search hit.• Specify a RegularExpression that covers the whole text (topic or line), which typically starts with .* , and must end in .* • Put text you want to keep in parenthesis, like $pattern(.*?(from here.*?to here).*) • Example: $pattern(.*?\*.*?Email\:\s*([^\n\r]+).*) extracts the e-mail address from a bullet of format * Email: ... • This example has non-greedy .*? patterns to scan for the first occurance of the Email bullet; use greedy .* patterns to scan for the last occurance • Limitation: Do not use .*) inside the pattern, e.g. $pattern(.*foo(.*)bar.*) does not work, but $pattern(.*foo(.*?)bar.*) does • Note: Make sure that the integrity of a web page is not compromised; for example, if you include an HTML table make sure to include everything including the table end tag |
$count(reg-exp) |
Count of number of times a regular expression pattern appears in the text of a topic (does not search meta data). Follows guidelines for use and limitations outlined above under $pattern(reg-exp) . Example: $count(.*?(---[+][+][+][+]) .*) counts the number of <H4> headers in a page. |
$ntopics |
Number of topics found in current web. This is the current topic count, not the total number of topics |
$nhits |
Number of hits if multiple="on" . Cumulative across all topics in current web. Identical to $ntopics unless multiple="on" |
$pager |
pager control - can be optionally customised using the pagerformat below |
$n or $n() |
New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar Most macros accept parameter strings which are split over multiple lines. This is usually more readable than using Note that newline is not a line break. The browser will wrap the lines together. If you require a line break, displaying the results on two lines, use |
$nop or $nop() |
Is a "no operation". This token gets removed; useful for nested search |
$quot |
Double quote (" ) (\" also works) |
$percent |
Percent sign (% ) ($percnt also works) |
$dollar |
Dollar sign ($ ) |
$lt |
Less than sign (< ) |
$gt |
Greater than sign (> ) |
$amp |
Ampersand (& ) |
$comma |
Comma (, ) |
%SEARCH{ "VarREMOTE" scope="topic" nonoise="on" header="| *Topic* | *Summary* |" format="| [[$topic]] | $summary |" footer="| *Topics found* | *$ntopics* |" }%To get this:
Topic | Summary |
---|---|
Topics found | 3 |
VarREMOTEADDR | #VarREMOTEADDR REMOTE_ADDR environment variable * Syntax: %REMOTE_ADDR% * Expands to: == * Related: ENV, HTTP_HOST, REMOTE_PORT, REMOTE_USER |
VarREMOTEPORT | #VarREMOTEPORT REMOTE_PORT environment variable * Syntax: %REMOTE_PORT% * Expands to: * Related: ENV, HTTP_HOST, REMOTE_ADDR, REMOTE_USER |
VarREMOTEUSER | #VarREMOTEUSER REMOTE_USER environment variable * Syntax: %REMOTE_USER% * Expands to: * Related: ENV, HTTP_HOST, REMOTE_ADDR, REMOTE_PORT, USERNAME, WIKINAME ... |
TopicClassification
field, an OperatingSystem
field and an OsVersion
field we could write:
| *Topic:* | *!OperatingSystem:* | *!OsVersion:* | %SEARCH{ "TopicClassification~'FrequentlyAskedQuestion'" type="query" nonoise="on" format="| [[$topic]] | $formfield(OperatingSystem) | $formfield(OsVersion) |" }%To get this (simulated):
Topic: | OperatingSystem: | OsVersion: |
---|---|---|
IncorrectDllVersionW32PTH10DLL | OsWin | 95/98 |
WinDoze95Crash | OsWin | 95 |
$pattern()
token to extract the first level-1 heading for each topic:
%SEARCH{ "^---[+][^+][^\r\n]+[\r\n]" type="regex" nonoise="on" header="Headings:" limit="5" format=" * [[$topic][$pattern([\r\n\-+!]+([^\r\n]*?)[\r\n].*)]]" footer="Found $ntopics topics with level-1 headings" }%
format
, header
and footer
parameters, among others. To make use of additional macros in the output, familiarity with inside-out, left-to-right order of expansion rules is required. There are two forms: %INNERMACRO%
to build the parameter string before %OUTERMACRO%
is expanded %OUTERMACRO{ format="%INNERMACRO%" }%
%INNERMACRO%
into the output of %OUTERMACRO%
%OUTERMACRO{ format="$percentINNERMACRO$percent" }%No permission to view System.Macros
%SEARCH{ "culture" nonoise="on" format=" * $topic is referenced by: (list all references)" }%Second (inner) search: For each hit, we want this search:
%SEARCH{ "(topic found in outer search)" nonoise="on" format="$topic" separator=", " }%Now let's nest the two.
$percent
to escape (delay) the inner search's SEARCH macro
\"
to escape the double quotes
$dollar
to escape the $
of $topic
%SEARCH{ "culture" nonoise="on" limit="5" format="\ * $topic is referenced by: * $percentSEARCH{ \"$topic\" nonoise=\"on\" format=\"$dollartopic\" separator=\", \" }$percent" }%To get this:
When nesting with escapes, each new nesting level must "escape the escapes", e.g. write$dollarpercentSEARCH{
for level three,$dollardollarpercentSEARCH{
for level four, etc.
$topic
, $dollartopic
or $dollardollartopic
.
If you find yourself using escaped tokens like $dollartopic
, another approach is to use the STARTSECTION/ENDSECTION feature of INCLUDE. Instead of nesting the inner search expression directly inside the format string of the outer, the inner search is written as a separate stand-alone section of a topic which is INCLUDEd into the format string of the outer.
Write this:
%SEARCH{ "culture" nonoise="on" limit="5" format="\ * $topic is referenced by: * $percentINCLUDE{\"%TOPIC%\" section=\"mysearch\" thetopic=\"$topic\"}$percent" }% <!-- HTML comment to hide this section from the user and web browser's DOM. verbatim prevents the section being evaluated. Alternatively, sections like this can be placed into dedicated utility topics which may hold many such re-usable pieces of your wiki application <verbatim> %STARTSECTION{"mysearch"}%%SEARCH{ "%thetopic%" nonoise="on" format="$topic" separator=", " }%%ENDSECTION{"mysearch"}% </verbatim> -->
Output will be the same as for the first method Nested search can be slow, especially if you nest more than 3 levels deep. Nesting is limited to 16 levels.
%SEARCH{ "1" type="query" nonoise="on" order="modified" reverse="on" limit="7" format="| [[$topic]] | $wikiusername | $date |" }%To get this:
WebTopBarExample | UrsBeyerle | 19 Mar 2017 - 09:57 |
WebPreferences | UrsBeyerle | 19 Mar 2017 - 09:53 |
WebLeftBarWebsList | MiriamKuebbeler | 21 Feb 2014 - 10:24 |
WebTemplateTopics | ProjectContributor | 23 Sep 2011 - 21:18 |
WebSearch | ProjectContributor | 01 Jul 2011 - 02:16 |
WikiSyntax | ProjectContributor | 19 Sep 2010 - 14:08 |
WikiName | ProjectContributor | 19 Sep 2010 - 14:08 |
%SEARCH{ "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')" type="query" limit="20" format=" * $percentICON{ \"$percentIF{ \"'$topic'/parent.name='UserDocumentationCategory'\" then=\"info\" else=\"gear\" }$percent\" }$percent [[$topic]]" }%
Details:To get this:
- The SEARCH has a delayed ICON. The
$percent
ensures that ICON is evaluated once for each search hit- The ICON contains an IF, which again is delayed with the
$percent
token and will also be evaluated for each SEARCH hit. Additionally, the inside-out, left-to-right rule discussed earlier means that this IF expression will be evaluated before ICON.- If
$topic
is a child of UserDocumentationCategory, theinfo
icon is used; otherwise,gear
.
<form action="%SCRIPTURLPATH{"view"}%/%WEB%/%TOPIC%"> Find Topics: <input type="text" name="q" size="32"\ value="%URLPARAM{"q" encode="entity"}%" /> <input\ type="submit" class="foswikiSubmit" value="Search" /> </form> Result: %SEARCH{ "%URLPARAM{"q" encode="quote"}%" type="keyword" nosearch="on" format=" * $web.$topic: %BR% $summary" }%To get this: Result: