Formatted Search

Customize the display of search results.

The default output format of a %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="".

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 $n tokens. If you are familiar with sectional includes, you might also consider nested sectional includes to hold the newline content outside of the parameter string entirely.

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 %BR%. Or use two consecutive newlines to create a TML "Paragraph".

$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.

2. footer="..." parameter

Use the footer parameter to specify the footer of a search result. It should correspond to the format of the format parameter. This parameter is optional.
Example:

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 $n tokens. If you are familiar with sectional includes, you might also consider nested sectional includes to hold the newline content outside of the parameter string entirely.

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 %BR%. Or use two consecutive newlines to create a TML "Paragraph".

$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.

3. pagerformat="..." parameter

Use the pagerformat parameter to customise the appearance of the paging control.
It should correspond to the format of the format parameter.
This parameter is optional.
Example:

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 $n tokens. If you are familiar with sectional includes, you might also consider nested sectional includes to hold the newline content outside of the parameter string entirely.

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 %BR%. Or use two consecutive newlines to create a TML "Paragraph".

$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 (,)

4. format="..." parameter

Use the format parameter to specify the format of one search hit.
Example:

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. 15 Sep 2019 - 10:04

$isodate

Time stamp of last topic update, e.g. 2019-09-15T10:04Z

$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.

$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 $n tokens. If you are familiar with sectional includes, you might also consider nested sectional includes to hold the newline content outside of the parameter string entirely.

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 %BR%. Or use two consecutive newlines to create a TML "Paragraph".

$nop or $nop()

Is a "no operation". This token gets removed; useful for nested search

Test case

Could not perform search. Error was: 'tempfile' can't be called as a method at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Sandbox.pm line 506.
at /usr/share/perl5/vendor_perl/File/Temp.pm line 1006.
File::Temp::tempfile('File::Temp', 'STDERR.30521.XXXXXXXXXX', 'DIR', '/www/sugpo223/cgi-bin/wiki/working/tmp', 'UNLINK', 0) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Sandbox.pm line 506
Foswiki::Sandbox::sysCommand('Foswiki::Sandbox', '/bin/grep -E -i -H -- %TOKEN|U% %FILES|F%', 'TOKEN', '^---[+][^+][^\r\n]+[\r\n]', 'FILES', 'ARRAY(0x2335040)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Store/SearchAlgorithms/Forking.pm line 109
Foswiki::Store::SearchAlgorithms::Forking::search('^---[+][^+][^\r\n]+[\r\n]', 'System', 'Foswiki::Iterator::FilterIterator=HASH(0x23fa298)', 'Foswiki=HASH(0x13e1e20)', 'HASH(0x23269e0)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Store/SearchAlgorithms/Forking.pm line 267
Foswiki::Store::SearchAlgorithms::Forking::_webQuery('Foswiki::Search::Node=HASH(0x23fa0b8)', 'System', undef, 'Foswiki=HASH(0x13e1e20)', 'HASH(0x23269e0)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Store/SearchAlgorithms/Forking.pm line 182
Foswiki::Store::SearchAlgorithms::Forking::query('Foswiki::Search::Node=HASH(0x23fa0b8)', undef, 'Foswiki=HASH(0x13e1e20)', 'HASH(0x23269e0)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Store/VC/Store.pm line 518
Foswiki::Store::VC::Store::query('Foswiki::Store::RcsLite=HASH(0x144d948)', 'Foswiki::Search::Node=HASH(0x23fa0b8)', undef, 'Foswiki=HASH(0x13e1e20)', 'HASH(0x23269e0)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Meta.pm line 839
Foswiki::Meta::query('Foswiki::Search::Node=HASH(0x23fa0b8)', undef, 'HASH(0x23269e0)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Search.pm line 352
Foswiki::Search::searchWeb('Foswiki::Search=HASH(0x225d9b0)', 'search', '^---[+][^+][^\r\n]+[\r\n]', 'basetopic', 'SearchPatternCookbook', 'footer', 'Found $ntopics topics with level-1 headings', '_RAW', '\x{a} "^---[+][^+][^\r\n]+[\r\n]"\x{a} type="regex"\x{a} nonoise...', ...) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Macros/SEARCH.pm line 32
Foswiki::__ANON__() called at /usr/share/perl5/vendor_perl/Error.pm line 419
eval {...} called at /usr/share/perl5/vendor_perl/Error.pm line 411
Error::subs::try('CODE(0x1d94d20)', 'HASH(0x23f9878)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Macros/SEARCH.pm line 41
Foswiki::SEARCH('Foswiki=HASH(0x13e1e20)', 'Foswiki::Attrs=HASH(0x23f6788)', 'Foswiki::Meta=HASH(0x22145c8)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 3145
Foswiki::_expandMacroOnTopicRendering('Foswiki=HASH(0x13e1e20)', 'SEARCH', '\x{a} "^---[+][^+][^\r\n]+[\r\n]"\x{a} type="regex"\x{a} nonoise...', 'Foswiki::Meta=HASH(0x22145c8)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 3021
Foswiki::_processMacros('Foswiki=HASH(0x13e1e20)', '\x{a}

\x{a}%<nop>SEARCH{\x{a} "^---[+][^+][^\r\n]+[\r\...', 'CODE(0x13424a8)', 'Foswiki::Meta=HASH(0x22145c8)', 16) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 2818
Foswiki::innerExpandMacros('Foswiki=HASH(0x13e1e20)', 'SCALAR(0x21f78a0)', 'Foswiki::Meta=HASH(0x22145c8)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Macros/INCLUDE.pm line 297
Foswiki::__ANON__() called at /usr/share/perl5/vendor_perl/Error.pm line 419
eval {...} called at /usr/share/perl5/vendor_perl/Error.pm line 411
Error::subs::try('CODE(0x225d8a8)', 'HASH(0x2492af8)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Macros/INCLUDE.pm line 348
Foswiki::INCLUDE('Foswiki=HASH(0x13e1e20)', 'Foswiki::Attrs=HASH(0x2214700)', 'Foswiki::Meta=HASH(0x1cf4e68)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 3145
Foswiki::_expandMacroOnTopicRendering('Foswiki=HASH(0x13e1e20)', 'INCLUDE', '"SearchPatternCookbook" section="Headings"', 'Foswiki::Meta=HASH(0x1cf4e68)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 3021
Foswiki::_processMacros('Foswiki=HASH(0x13e1e20)', '%<nop>STARTINCLUDE%\x{a}---+ Formatted Search\x{a}Customize the display of...', 'CODE(0x13424a8)', 'Foswiki::Meta=HASH(0x1cf4e68)', 16) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 2818
Foswiki::innerExpandMacros('Foswiki=HASH(0x13e1e20)', 'SCALAR(0x1351760)', 'Foswiki::Meta=HASH(0x1cf4e68)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 3327
Foswiki::expandMacros('Foswiki=HASH(0x13e1e20)', '%<nop>STARTINCLUDE%\x{a}---+ Formatted Search\x{a}Customize the display of...', 'Foswiki::Meta=HASH(0x1cf4e68)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Meta.pm line 3103
Foswiki::Meta::expandMacros('Foswiki::Meta=HASH(0x1cf4e68)', '%<nop>STARTINCLUDE%\x{a}---+ Formatted Search\x{a}Customize the display of...') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/UI/View.pm line 412
Foswiki::UI::View::_prepare('%<nop>STARTINCLUDE%\x{a}---+ Formatted Search\x{a}Customize the display of...', 'Foswiki::Meta=HASH(0x1cf4e68)', 0) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/UI/View.pm line 392
Foswiki::UI::View::view('Foswiki=HASH(0x13e1e20)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/UI.pm line 316
Foswiki::UI::__ANON__() called at /usr/share/perl5/vendor_perl/Error.pm line 419
eval {...} called at /usr/share/perl5/vendor_perl/Error.pm line 411
Error::subs::try('CODE(0xa1bc30)', 'HASH(0x13e1a00)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/UI.pm line 435
Foswiki::UI::_execute('Foswiki::Request=HASH(0x13bb408)', 'CODE(0x13baf58)', 'view', 1) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/UI.pm line 274
Foswiki::UI::handleRequest('Foswiki::Request=HASH(0x13bb408)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Engine/CGI.pm line 41
Foswiki::Engine::CGI::run('Foswiki::Engine::CGI=HASH(0xd68c38)') called
</span>

Nested Search

SEARCH is one of many macros that produce output which may be controlled with 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:

Standard: Use %INNERMACRO% to build the parameter string before%OUTERMACRO% is expanded

%OUTERMACRO{
format="%INNERMACRO%"
}%

Delayed: Use the parameter string to incorporate %INNERMACRO% into the output of %OUTERMACRO%

%OUTERMACRO{
format="$percentINNERMACRO$percent"
}%

When working with a given macro, consult its documentation to determine which parameters support the $percent/$percntformat tokens. Generally only output parameters like header, format and footer support format tokens.

Standard form

The key to understanding nested expressions in Foswiki is to understand that macros are expanded "inside-out, left-to-right". Example:

These topics are for frequently
asked questions including answers.
* Set THETOPIC = %SYSTEMWEB%.FAQWhatIsWikiWiki
* Set THEFIELD = TopicClassification

These topics are for frequently
asked questions including answers.
* Set THETOPIC = System.FAQWhatIsWikiWiki
* Set THEFIELD = TopicClassification

Delayed form

Standard form macros can nearly always be used to build the parameter string of another macro; however, sometimes it is desirable to bypass the inside-out expansion order and delay the inner macro until after the outer macro has finished expansion. This is accomplished by using the $percent format token instead of %, and escaping any " character it uses (becomes \")

When working with a given macro, consult its documentation to determine which parameters support the $percent/$percntformat tokens. Generally only output parameters like header, format and footer support format tokens.

Method 1 (nesting with escapes)

The inner search cannot be placed directly into the format string of the outer, because of the "inside-out, left-to-right" macro expansion behaviour discussed earlier. It must be delayed so that the outer search is evaluated first. To do this, we need to escape the inner search, i.e. let the outer search build a series of searches comprised of the inner search.

To get this:
Could not perform search. Error was: 'tempfile' can't be called as a method at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Sandbox.pm line 506.
at /usr/share/perl5/vendor_perl/File/Temp.pm line 1006.
File::Temp::tempfile('File::Temp', 'STDERR.30521.XXXXXXXXXX', 'DIR', '/www/sugpo223/cgi-bin/wiki/working/tmp', 'UNLINK', 0) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Sandbox.pm line 506
Foswiki::Sandbox::sysCommand('Foswiki::Sandbox', '/bin/grep -F -i -H -- %TOKEN|U% %FILES|F%', 'TOKEN', 'culture', 'FILES', 'ARRAY(0x24a19f0)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Store/SearchAlgorithms/Forking.pm line 109
Foswiki::Store::SearchAlgorithms::Forking::search('culture', 'System', 'Foswiki::Iterator::FilterIterator=HASH(0x23f9938)', 'Foswiki=HASH(0x13e1e20)', 'HASH(0x2214760)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Store/SearchAlgorithms/Forking.pm line 267
Foswiki::Store::SearchAlgorithms::Forking::_webQuery('Foswiki::Search::Node=HASH(0x24c6870)', 'System', undef, 'Foswiki=HASH(0x13e1e20)', 'HASH(0x2214760)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Store/SearchAlgorithms/Forking.pm line 182
Foswiki::Store::SearchAlgorithms::Forking::query('Foswiki::Search::Node=HASH(0x24c6870)', undef, 'Foswiki=HASH(0x13e1e20)', 'HASH(0x2214760)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Store/VC/Store.pm line 518
Foswiki::Store::VC::Store::query('Foswiki::Store::RcsLite=HASH(0x144d948)', 'Foswiki::Search::Node=HASH(0x24c6870)', undef, 'Foswiki=HASH(0x13e1e20)', 'HASH(0x2214760)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Meta.pm line 839
Foswiki::Meta::query('Foswiki::Search::Node=HASH(0x24c6870)', undef, 'HASH(0x2214760)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Search.pm line 352
Foswiki::Search::searchWeb('Foswiki::Search=HASH(0x225d9b0)', 'search', 'culture', 'basetopic', 'FormattedSearch', '_RAW', '\x{a} "culture"\x{a} nonoise="on"\x{a} limit="5"\x{a} format="\\x{a} * ...', 'nonoise', 'on', ...) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Macros/SEARCH.pm line 32
Foswiki::__ANON__() called at /usr/share/perl5/vendor_perl/Error.pm line 419
eval {...} called at /usr/share/perl5/vendor_perl/Error.pm line 411
Error::subs::try('CODE(0x248ee48)', 'HASH(0x24c6570)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Macros/SEARCH.pm line 41
Foswiki::SEARCH('Foswiki=HASH(0x13e1e20)', 'Foswiki::Attrs=HASH(0x24c2be0)', 'Foswiki::Meta=HASH(0x1cf4e68)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 3145
Foswiki::_expandMacroOnTopicRendering('Foswiki=HASH(0x13e1e20)', 'SEARCH', '\x{a} "culture"\x{a} nonoise="on"\x{a} limit="5"\x{a} format="\\x{a} * ...', 'Foswiki::Meta=HASH(0x1cf4e68)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 3021
Foswiki::_processMacros('Foswiki=HASH(0x13e1e20)', '%STARTINCLUDE%\x{a}---+ Formatted Search\x{a}Customize the display of...', 'CODE(0x13424a8)', 'Foswiki::Meta=HASH(0x1cf4e68)', 16) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 2818
Foswiki::innerExpandMacros('Foswiki=HASH(0x13e1e20)', 'SCALAR(0x1351760)', 'Foswiki::Meta=HASH(0x1cf4e68)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki.pm line 3327
Foswiki::expandMacros('Foswiki=HASH(0x13e1e20)', '%STARTINCLUDE%\x{a}---+ Formatted Search\x{a}Customize the display of...', 'Foswiki::Meta=HASH(0x1cf4e68)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Meta.pm line 3103
Foswiki::Meta::expandMacros('Foswiki::Meta=HASH(0x1cf4e68)', '%STARTINCLUDE%\x{a}---+ Formatted Search\x{a}Customize the display of...') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/UI/View.pm line 412
Foswiki::UI::View::_prepare('%STARTINCLUDE%\x{a}---+ Formatted Search\x{a}Customize the display of...', 'Foswiki::Meta=HASH(0x1cf4e68)', 0) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/UI/View.pm line 392
Foswiki::UI::View::view('Foswiki=HASH(0x13e1e20)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/UI.pm line 316
Foswiki::UI::__ANON__() called at /usr/share/perl5/vendor_perl/Error.pm line 419
eval {...} called at /usr/share/perl5/vendor_perl/Error.pm line 411
Error::subs::try('CODE(0xa1bc30)', 'HASH(0x13e1a00)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/UI.pm line 435
Foswiki::UI::_execute('Foswiki::Request=HASH(0x13bb408)', 'CODE(0x13baf58)', 'view', 1) called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/UI.pm line 274
Foswiki::UI::handleRequest('Foswiki::Request=HASH(0x13bb408)') called at /www/sugpo223/cgi-bin/Foswiki-1.1.4_neu/lib/Foswiki/Engine/CGI.pm line 41
Foswiki::Engine::CGI::run('Foswiki::Engine::CGI=HASH(0xd68c38)') called

When nesting with escapes, each new nesting level must "escape the escapes", e.g. write $dollarpercentSEARCH{ for level three, $dollardollarpercentSEARCH{ for level four, etc.

Method 2 (nesting with sectional includes)

Nested expressions with delayed macros can be difficult to write: care must be taken to escape all the quotes of the inner delayed macro, and it may become confusing whether to use $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.

Search with conditional output

Sometimes it may be desirable for each hit to be displayed differently depending on some criteria. For example, maybe you want to list 20 topics modified in 2009, but decorate the hits which are children of UserDocumentationCategory with an icon.

Specify a search which returns the hits you need

For each search hit, test the condition that will influence the output using a nested IFstatement

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.