Tags:
search1Add my vote for this tag structured_wiki1Add my vote for this tag twiki_application2Add my vote for this tag create new tag
view all tags
ALERT! NOTE: This is a DistributionDocument.
  • Please help maintain high quality documentation: This is a wiki, please fix the documentation if you find errors or incomplete content.
  • Put questions and suggestions concerning the documentation of this topic in the comments section below.
  • Use the Support web for problems you are having using TWiki.
  • Use the Sandbox web to evaluate & test TWiki.

TWiki Formatted Search

Inline search feature allows flexible formatting of search result

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 variables, such as %SEARCH{ "food" format="| $topic | $summary |" }%. See %SEARCH{...}% for other search parameters, such as separator="".

Syntax

Three parameters can be used to customize a search result:

1. header="..." parameter

Use the header parameter to specify the header of a search result. It should correspond to the format of the format parameter. This parameter is optional.
Example: header="| *Topic:* | *Summary:* |"

Variables that can be used in the header string:

Name: Expands To:
$web Name of the web

Formatting Tokens

TWiki defines some standard special tokens that can be used to replace characters in some parameters - notably those to FormattedSearch and IfStatements - to defer evaluation of the parameter until later. These special tokens are often called "escapes", because they allow the character to "escape" from its normal meaning.

$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation". This variable gets removed; useful for nested search
$quot or \" Double quote (")
$aquot Apostrophe quote (')
$percnt Percent sign (%)
$dollar Dollar sign ($)
$lt Less than sign (<)
$gt Greater than sign (>)

2. format="..." parameter

Use the format parameter to specify the format of one search hit.
Example: format="| $topic | $summary |"

Variables that can be used in the format string:

Name: Expands To:
$web Name of the web
$topic Topic name
$topic(20) Topic name, "- " hyphenated each 20 characters
$topic(30, -<br />) Topic name, hyphenated each 30 characters with separator "-<br />"
$topic(40, ...) Topic name, shortened to 40 characters with "..." indication
$topictitle Topic title, in order of sequence defined by: Form field named "Title", topic preference setting named TITLE, topic name
$parent Name of parent topic; empty if not set
$parent(20) Name of parent topic, same hyphenation/shortening like $topic()
$text Formatted topic text. In case of a multiple="on" search, it is the line found for each search hit.
$text(encode:type) Same as above, but encoded in the specified type. Possible types are the same as in ENCODE. Though ENCODE can take the extra parameter, $text(encode:type) cannot. Example: $text(encode:html)
$locked LOCKED flag (if any)
$date Time stamp of last topic update, e.g. 2024-02-29 - 10:53
$isodate Time stamp of last topic update, e.g. 2024-02-29T10:53Z
$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 TWiki variables, formatting and line breaks removed; up to 162 characters
$summary(50) Topic summary, up to 50 characters shown
$summary(showvarnames) Topic summary, with %ALLTWIKI{...}% variables shown as ALLTWIKI{...}
$summary(expandvar) Topic summary, with %ALLTWIKI{...}% variables expanded
$summary(noheader) Topic summary, with leading ---+ headers removed
Note: The tokens can be combined, for example $summary(100, showvarnames, noheader)
$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, $formfield(TopicClassification) would get expanded to PublicFAQ. This applies only to topics that have a TWikiForm
$formfield(name, encode:type) Form field value, encoded in the specified type. Possible types are the same as in ENCODE: quote, moderate, safe, entity, html, url and csv. The encode:type parameter can be combined with other parameters described below, but it needs to be the last parameter. Example: $formfield(Description, 20, encode:html)
$formfield(name, render:display) Form field value, rendered for display. For example, a form field of type color will render as a colored box. If not specified, the raw value is returned, such as a color value #336699. The render:display parameter can be combined with other parameters, but must be used after the parameters described below.
$formfield(name, 10) Form field value, "- " hyphenated each 10 characters
$formfield(name, 20, -<br />) Form field value, hyphenated each 20 characters with separator "-<br />"
$formfield(name, 30, ...) Form field value, shortened to 30 characters with "..." indication
$query(query-syntax) Access topic meta data using SQL-like QuerySearch syntax. Example:
$query(attachments.arraysize) returns the number of files attached to the current topic
$query(attachments[name~'*.gif'].size) returns an array with size of all .gif attachments, such as 848, 1425, 923
$query(parent.name) is equivalent to $parent
$query(query-syntax, quote:") Strings in QuerySearch result are quoted with the specified quote. Useful to triple-quote strings for use in SpreadSheetPlugin's CALCULATE, such as $query(attachments.comment, quote:''') which returns a list of triple-quoted attachment comment strings -- the spreadhseet funcions will work properly even if comment strings contain commas and parenthesis
$query(query-syntax, encode:type) QuerySearch result is encoded in the specified type. This is in parallel to $formfield(name, encode:type) mentioned above
$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
$pattern(reg-exp, encode:type) A text extracted by reg-exp is encoded in the specified type. This is in parallel to $formfield(name, encode:type) mentioned above
$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
$tntopics The total number of topics matched
$nwebs The number of webs searched
$nhits Number of hits if multiple="on". Cumulative across all topics in current web. Identical to $ntopics unless multiple="on"

Formatting Tokens

TWiki defines some standard special tokens that can be used to replace characters in some parameters - notably those to FormattedSearch and IfStatements - to defer evaluation of the parameter until later. These special tokens are often called "escapes", because they allow the character to "escape" from its normal meaning.

$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation". This variable gets removed; useful for nested search
$quot or \" Double quote (")
$aquot Apostrophe quote (')
$percnt Percent sign (%)
$dollar Dollar sign ($)
$lt Less than sign (<)
$gt Greater than sign (>)

3. 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: footer="| *Topic* | *Summary* |"

Variables that can be used in the footer string:

Name: Expands To:
$web Name of the web
$ntopics Number of topics found in current web
$tntopics The total number of topics matched
$nwebs The number of webs searched
$nhits Number of hits if multiple="on". Cumulative across all topics in current web. Identical to $ntopics unless multiple="on"

Formatting Tokens

TWiki defines some standard special tokens that can be used to replace characters in some parameters - notably those to FormattedSearch and IfStatements - to defer evaluation of the parameter until later. These special tokens are often called "escapes", because they allow the character to "escape" from its normal meaning.

$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation". This variable gets removed; useful for nested search
$quot or \" Double quote (")
$aquot Apostrophe quote (')
$percnt Percent sign (%)
$dollar Dollar sign ($)
$lt Less than sign (<)
$gt Greater than sign (>)

4. default="..." parameter

Use the default parameter to specify a default message if there are no hits in a web. This parameter is optional.
Example: default="| *Note* | Nothing found in the [[$web.WebHome][$web]] web |"

Variables that can be used in the default string:

Name: Expands To:
$web Name of the web

Formatting Tokens

TWiki defines some standard special tokens that can be used to replace characters in some parameters - notably those to FormattedSearch and IfStatements - to defer evaluation of the parameter until later. These special tokens are often called "escapes", because they allow the character to "escape" from its normal meaning.

$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation". This variable gets removed; useful for nested search
$quot or \" Double quote (")
$aquot Apostrophe quote (')
$percnt Percent sign (%)
$dollar Dollar sign ($)
$lt Less than sign (<)
$gt Greater than sign (>)

Results pagination

When a search return many results, you may want to paginate them having the following line below the results.

«Prev   1   2   3   4   5   Next»

SearchResultsPagination describes how to do it.

Evaluation order of variables

By default, variables embedded in the format parameter of %SEARCH{}% are evaluated once before the search. This is OK for variables that do not change, such as %SCRIPTURLPATH%. Variables that should be evaluated once per search hit must be escaped. For example, to escape a conditional:
    %IF{ "..." then="..." else="..." }%
write this:
    format="$percntIF{ \"...\" then=\"...\" else=\"...\" }$percnt"

Examples

Here are some samples of formatted searches. The SearchPatternCookbook has other examples, such as creating a picklist of usernames, searching for topic children and more.

Bullet list showing topic name and summary

Write this:

%SEARCH{
 "FAQ"
 scope="topic"
 nosearch="on"
 nototal="on"
 header="   * *Topic: Summary:*"
 format="   * [[$topic]]: $summary"
 footer="   * *Topic: Summary*"
}%

To get this:

  • Topic: Summary:
  • TWikiFAQ: Frequently Asked Questions About TWiki This is a real FAQ, and also a demo of an easily implemented knowledge base solution. To see how it`s done, view the source...
  • TWikiFaqTemplate: FAQ: Answer: Back to: TWikiFAQ Contributors:
  • TextFormattingFAQ: Text Formatting FAQ This topics lists frequently asked questions on text formatting. Text formatting applies to people who edit TWiki pages in raw edit mode . TextFormattingRules...
  • Topic: Summary

Table showing form field values of topics with a form

In a web where there is a form that contains a TopicClassification field, an OperatingSystem field and an OsVersion field we could write:

| *Topic:* | *OperatingSystem:* | *OsVersion:* |
%SEARCH{ "[T]opicClassification.*?value=\"[P]ublicFAQ\"" scope="text" type="regex" nosearch="on" nototal="on" format="| [[$topic]] | $formfield(OperatingSystem) | $formfield(OsVersion) |" }%

To get this:

Topic: OperatingSystem OsVersion
IncorrectDllVersionW32PTH10DLL OsWin 95/98
WinDoze95Crash OsWin 95

Extract some text from a topic using regular expression

Write this:

%SEARCH{
 "__Back to\:__ TWikiFAQ"
 scope="text"
 type="regex"
 nosearch="on"
 nototal="on"
 header="TWiki FAQs:"
 format="   * $pattern(.*?FAQ\:[\n\r]*([^\n\r]+).*) [[$topic][Answer...]]"
}%

To get this:

TWiki FAQs:

  • How can I create a simple TWiki Forms based application? Answer...
  • I am a registered user and I have authenticated myself before I edited a topic. But after saving the topic, the left bar and the variable %WIKIUSERNAME% are showing "TWikiGuest" instead of my name. Answer...
  • How do I convert a table from HTML to TML? Answer...
  • How do I set up cron jobs on Mac OS X? Answer...
  • How do I delete or rename a topic? Answer...
  • How do I delete or rename a file attachment? Answer...
  • Why does the topic revision not increase when I edit a topic? Answer...
  • When I try to access TWiki, I get the "Premature end of script headers: ..." error. Answer...
  • TWiki has a GPL (GNU General Public License). What is GPL? Answer...
  • How can I create a .htpasswd file that is owned by the webserver user? Answer...
  • How do you log off? Suppose I log in with the guest username but later I want to use another username, how do I log off from the guest user name? Answer...
  • How do I move the form to the top of the page? Answer...
  • Answer...
  • Need to know which is the best stable version of perl to be used in the End. Answer...
  • I've problems with the WebSearch. There is no Search Result on any inquiry. By clicking the Index topic it's the same problem. Answer...
  • What happens if two of us try to edit the same topic simultaneously? Answer...
  • I would like to install TWiki on my server. Can I get the source? Answer...
  • How can I use international (I18N) characters in usernames? Answer...
  • What does the "T" in TWiki stand for? Answer...
  • So what is this WikiWiki thing exactly? Answer...
  • Everybody can edit any page, this is scary. Doesn't that lead to chaos? Answer...

Nested Search

Search can be nested. For example, search for some topics, then form a new search for each topic found in the first search. The idea is to build the nested search string using a formatted search in the first search.

Here is an example. Let's search for all topics that contain the word "culture" (first search), and let's find out where each topic found is linked from (second search).

  • First search:
    • %SEARCH{ "culture" format="   * $topic is referenced by: (list all references)" nosearch="on" nototal="on" }%
  • Second search. For each hit we want this search:
    • %SEARCH{ "(topic found in first search)" format="$topic" nosearch="on" nototal="on" separator=", " }%
  • Now let's nest the two. We need to escape the second search, e.g. the first search will build a valid second search string. Note that we escape the second search so that it does not get evaluated prematurely by the first search:
    • Use $percnt to escape the leading percent of the second search
    • Use \" to escape the double quotes
    • Use $dollar to escape the $ of $topic
    • Use $nop to escape the }% sequence

Write this:

%SEARCH{
 "culture"
 format="   * $topic is referenced by:$n      * $percntSEARCH{ \"$topic\" format=\"$dollartopic\" nosearch=\"on\" nototal=\"on\" separator=\", \" }$nop%"
 nosearch="on"
 nototal="on"
}%

To get this:

Note: Nested search can be slow, especially if you nest more then 3 times. Nesting is limited to 16 levels. For each new nesting level you need to "escape the escapes", e.g. write $dollarpercntSEARCH{ for level three, $dollardollarpercntSEARCH{ for level four, etc.

Note: Another option, instead of a nested search, is to create a hash. Refer to the blog TWiki:Blog.BlogEntry201603x1. A search using hashes, if possible, may be significantly faster than a nested search.

Most recently changed pages

Write this:

%SEARCH{
 "\.*"
 scope="topic"
 type="regex"
 nosearch="on"
 nototal="on"
 sort="modified"
 reverse="on"
 format="| [[$topic]] | $wikiusername  | $date |"
 limit="7"
}%=

To get this:

WebStatistics TWikiGuest 2023-10-03 - 18:15
TWikiOnUbuntu PeterThoeny 2023-07-15 - 21:08
WebHome PeterThoeny 2022-08-09 - 03:13
ResetPassword PeterThoeny 2022-01-05 - 09:13
TinyMCEFrequentlyAskedQuestions PeterThoeny 2021-09-07 - 17:20
TinyMCEQuickHelp PeterThoeny 2021-09-07 - 17:17
WelcomeGuest TWikiGuest 2019-10-31 - 23:12

Search with conditional output

A regular expression search is flexible, but there are limitations. For example, you cannot show all topics that are up to exactly one week old, or create a report that shows all records with invalid form fields or fields within a certain range, etc. You need some additional logic to format output based on a condition:

  1. Specify a search which returns more hits then you need
  2. For each search hit apply a spreadsheet formula to determine if the hit is needed
  3. If needed, format and output the result
  4. Else supress the search hit

This requires the TWiki:Plugins.SpreadSheetPlugin. The following example shows all topics in the Main web that have been updated in the last 7 days.

Write this:

%CALCULATE{$SET(weekold, $TIMEADD($TIME(), -7, day))}%
%SEARCH{ "." scope="topic" type="regex" web="Main" nonoise="on" sort="modified" reverse="on" format="$percntCALCULATE{$IF($TIME($date) < $GET(weekold), <nop>, | [[$web.$topic][$topic]] | $wikiusername | $date | $rev |)}$percnt" limit="100" }%

  • The first line sets the weekold variable to the serialized date of exactly one week ago
  • The SEARCH has a deferred CALCULATE. The $percnt makes sure that the CALCULATE gets executed once for each search hit
  • The CALCULATE compares the date of the topic with the weekold date
  • If topic is older, a <nop> is returned, which gets removed at the end of the TWiki rendering process
  • Otherwise, the search hit is formatted and returned
  • This example is for illustration only, it is easier to use the date="..." paramter in SEARCH to restrict the date.

To get this:

RakhimSafiullin TWikiRegistrationAgent 2024-02-29 - 09:15 1
TWikiUsers TWikiAdminUser 2024-02-29 - 09:15 38620
SiteStatistics TWikiAdminGroup 2024-02-29 - 08:00 4769
FairouzMalek PeterThoeny 2024-02-28 - 13:08 3
DietmarBeine TWikiRegistrationAgent 2024-02-26 - 12:25 1
IngoMarksteiner TWikiRegistrationAgent 2024-02-26 - 10:41 1
KevinPaquette TWikiRegistrationAgent 2024-02-24 - 21:28 1
RobertSchwarz TWikiRegistrationAgent 2024-02-24 - 02:34 1
SandraAcosta TWikiRegistrationAgent 2024-02-23 - 20:53 1

The condition can be anything you like. To restrict search based on a date range it is easier to use the date="" parameter as shown in the next example.

Restrict search based on a date range

A search can be restricted based on a date range. The following example is identical to the previous one, showing all topics in the Main web that have been updated in the last 7 days.

Write this:

%SEARCH{
 "."
 scope="topic"
 type="regex"
 web="%USERSWEB%"
 nonoise="on"
 sort="modified"
 reverse="on"
 format="| [[$web.$topic][$topic]] | $wikiusername | $date | $rev |"
 limit="100"
 date="P1w/$today"
}%=

To get this:

RakhimSafiullin TWikiRegistrationAgent 2024-02-29 - 09:15 1
TWikiUsers TWikiAdminUser 2024-02-29 - 09:15 38620
SiteStatistics TWikiAdminGroup 2024-02-29 - 08:00 4769
FairouzMalek PeterThoeny 2024-02-28 - 13:08 3
DietmarBeine TWikiRegistrationAgent 2024-02-26 - 12:25 1
IngoMarksteiner TWikiRegistrationAgent 2024-02-26 - 10:41 1
KevinPaquette TWikiRegistrationAgent 2024-02-24 - 21:28 1
RobertSchwarz TWikiRegistrationAgent 2024-02-24 - 02:34 1
SandraAcosta TWikiRegistrationAgent 2024-02-23 - 20:53 1

Embedding search forms to return a formatted result

Use an HTML form and an embedded formatted search on the same topic. You can link them together with an %URLPARAM{"..."}% variable. Example:

Write this:

<form action="%SCRIPTURLPATH{"view"}%/%WEB%/%TOPIC%">
Find Topics: 
<input type="text" name="q" size="32" value="%URLPARAM{"q" encode="entity"}%" />&nbsp;<input type="submit" class="twikiSubmit" value="Search" />
</form>
Result:
%SEARCH{
 search="%URLPARAM{"q" encode="quote"}%"
 type="keyword"
 format="   * $web.$topic: %BR% $summary"
 nosearch="on"
}%

To get this:

Find Topics:  
Result:

Related Topics: UserDocumentationCategory, SearchHelp, VarSEARCH, VarENCODE, SearchResultsPagination, SearchPatternCookbook, RegularExpression, QuerySearch

-- Contributors: TWiki:Main.PeterThoeny, TWiki:Main.CrawfordCurrie, TWiki:Main.SopanShewale



Comments & Questions about this Distribution Document Topic

I'd appreciate it if someone would modify the #Table_with_form_field_values_of_topics_with_a_form example to create an example that displays the form field values as a bulleted list. (Or confirms whether it can / cannot be done.)

-- RandyKramer - 02 Dec 2001

Bullet list of WebForm data works... Just happened to do it.

-- MikeMannix - 29 Dec 2001

Mike,

Wonderful, thanks! Now that I think about it though, did you do that in a search? (I'd like to be able to do it without a search -- what I'm trying to say is I'd just like to be able to display the form data, which normally appears as a table, as a bulleted list. I will revise this question and add it to the TWikiVariables page where it might be more appropriate.)

-- RandyKramer - 11 Jan 2002

It'd be great to integrate in the doc from SearchEnhancmentsRFC. I needed those features and stumbled across them poking around looking at various pages on TWiki.org

-- MattWalsh -- 14 Jan 2002

This is described in TWikiVariables. Topic is now updated with link.

-- PeterThoeny - 14 Jan 2002

I had this one all over the place, with def in TWikiVariables, and examples in an...Appendix - until Peter dropped me a "suggestion". This set-up, with the clearer intro para, works well in practice. Still, this def logically belongs in TWikiVariables, except the table format and long examples wouldn't work. Anyhow, I added a bit more explanation and a formatted syntax example to TWikiVariables for now....

-- MikeMannix - 23 Jan 2002

Lets say I want to make a search, and and just have it return the content of every topic that matches. I would think that the solution is something like using a format=" $text " in my search, but our TWiki doesn't have $text as a variable that can be used for a FormattedSearch. I know that I can make $text work just by adding one line to the searchWeb function in Search.pm, but how can you enable that kind of thing without modifying the core TWiki code?

-- DavidSachitano - 21 Jun 2002

There should be a FormattedSearchSolutions or FormattedSearchContributions or whatever where people could add their favorite search constructions._ There are mentions of this in various places in both Support and Codev, including some references to TWikiAdminCookBook, but I haven't been able to find any lists of formatted searches. For instance, I worked out the following to get a bulleted list of topics whose names have the name of the current topic as a prefix:

%SEARCH{ "^%TOPIC%[A-Za-z0-9]" scope="topic" regex="on" nosearch="on" nototal="on" format="   * [[$topic]]" }%
I'm sure I'm not the first to figure this out. I'd like to save the effort of working out common searches for myself and help save other people's efforts by contributing searches I've worked out.

-- MitchellModel - 13 Nov 2002

How do you sort results in a search? I don't see it spelled out anywhere I've yet looked.

-- GrantBow - 30 Nov 2002

From TWikiVariables: just use the order attribute on the embedded search command.

-- RichardDonkin - 30 Nov 2002

This document does not describe the possible values for $scope. It can take 'text' and 'topic'. Text means look in the document whilst topic means look only at the topic name.

-- MartinCleaver - 16 May 2003

$summary and $topic don't seem to work well if a search references another Web - is this easy to fix?

-- JohnTalintyre - 10 Sep 2003

It'd be nice if you could provide a comma separated list of webs to search - it would provide koalaskin the ability to recursively search its child webs.

-- MartinCleaver - 17 Oct 2003

The documentation above is a bit inaccurate for $formfield(name). In fact the code picks up $formfield(title). This can be a problem if the title is not a WikiWord. For example, in the case I was working on, I find the following META tags at the bottom of the topic file:

META:FORM{name="BuyerForm"}%
META:FIELD{name="BuyerType" title="BuyerType" value="ComputerHardwareMfg, TeleCom"}%
META:FIELD{name="Region" title="[[Region]]" value="NorthAmericaRegion"}%
META:FIELD{name="CompanyRevenue2002MilUS" title="Company Revenue 2002 (Mil US$)" value="18915"}%
META:FIELD{name="CompanyRevenue2001MilUS" title="Company Revenue 2001 (Mil US$)" value="21790"}%

This works for something like

$formfield([[Region]])

But blows everything up if you use the more complex

$formfield(Company Revenue 2002 (Mil US$))

I think it would be better to use the "name" field above, so that the documentation is correct. It is probably generally improper to use the title of the META field for processing. To fix this, make the following minor change in Search.pm:

sub getMetaFormField
...snip...
        $title = $field->{"title"};          # should change to $title = $field->{"name"};
        $value = $field->{"value"};
        $value =~ s/^\s*(.*?)\s*$/$1/go;
        if( $title eq $name ) {
            $value = breakName( $value, $break );
            return $value;

See FormattedSearchUsesTitleInsteadOfName

-- RaymondLutz - 17 Oct 2003

Added multiple webs, which was implemented in the code but not documented.

-- MartinCleaver - 17 Oct 2003

That description for web appears to be for the parameter, not the formatting variable.

-- SamHasler - 09 Jan 2004

$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. The pattern must cover the whole text (topic or line). For example, $pattern(.*?\*.*?Email\:\s*([^\n\r]+).*) extracts the email address from a bullet of format * Email: ....

Why does $pattern have to match the whole text? It seems more sensible to allow it to match whatever it wants to, and then extract

  • $1 if it exists, or
  • $0 (whole match) if not

With this simplification, the above pattern becomes simply $pattern(\*.*?Email\:\s*([^\n\r]+))

Why the elaborate and unusual requirements for this syntax? I see that pulling out patterns like the above might be a problem due to paren-matching issues, but there are ways around that. Make an exception for $pattern and have it be something like $pattern([[<pattern>]]) and everything is simple again.

-- WalterMundt - 20 Feb 2004

Walter, spec discussions are best done in Codev.

-- PeterThoeny - 17 Mar 2004

I can't seem to generate a table that puts the search results into a grid. I've read over FormattedSearch, TWikiVariables, and TablePlugin and am still lost. Perhaps I'm overlooking something... I can't seem to generate a table that resembles the one below.

Result One
One line description.

Result Two
One line description.

Result Three
One line description.

Result Four
One line description.

Any suggestions?

-- BryanRathouz - 20 Apr 2004

I'd have to say this was impossible with the current implementation of search. The simplest way that I can think to do it would be to write a plugin to reformat a table from one column to many columns as above. Then you use the search to create a one column table and the plugin to reformat it. As far as I know such a plugin does not (yet) exist.

-- SamHasler - 21 Apr 2004

Please ask in the Support web how to questions. This comment section is about the documentation. In your case I can imagine a solution with spreadsheet formulae.

-- PeterThoeny - 22 Apr 2004

If you have to use a plugin and send it attributes, all in a nested search, everything has to be "double-escaped" to get the layout right. I saw confusion regarding this a couple of times, so here's a shot at a syntax you can use in your nested search:

format=\"... $dollarpercntPLUGINTAG{attribute=\\"value\\"}$dollarpercnt ...\"

-- SteffenPoulsen - 06 Apr 2005

The Syntax section should mention the "separator=" parameter which is required to build certain kinds of search results and is used in several of the examples (nested search).

I needed this to create a list of form option values. I wanted them in a table and the table requires the entire cell to be on one "line" thus separator had to be "" or a single space.

-- PhilipPokorny - 15 Feb 2006

All SEARCH parameters are documented in TWikiVariables. I added a note accordingly.

-- PeterThoeny - 15 Feb 2006

Check out a search app I put together to SearchWithHighlights. I couldn't find anything else out there to do this, so this was a first shot at it. I'll admit it doesn't format things right all the time. And right now it's configured to only search items in the Know web. But it's a nice start anyway.

As an example, search for run, and you'll see run in bold and italics within each searched line. (You'll also notice the messed up formatting of the WebStatistics page...)

-- BobKocisko - 28 Feb 2006

In the documentation under the heading Table showing form field values of topics with a form you begin the search criteria with:

%SEARCH{ "[T]opicClassification.*?value=\"[P]ublicFAQ\"" ...

What purpose do the open/close brackets perform? There is no documentation covering them. Through experimentation, their presence or absence seem to be insignificant. In any (programming) language, syntax is everything... and I'd hate to accidentally launch missiles at Toledo (Ohio) through a simple coding error.

UPDATE: An hour later, after staring at at it while watching S.T. Voyager, it dawned on me to try it as a part of a regular expression. So, I tried:

%SEARCH{ "[Tabcdefg]opicClassif.*?value=\"[P]ublicFAQ\"" ...

and it works just fine. Therefore, and please correct me if I'm wrong, the brackets are treated as a set in a Regular Expression, no?

-- TerrillBennett - 22 Jun 2007

Yes, [Tabcdefg] is a set. [T] is a "set" with just a single letter, e.g. the letter itself. So why do we need it? In a RegularExpression, [T]opicClassification and TopicClassification are identical after all. It is used to avoid a hit on the search term itself. An alternative is to use excludetopic="%TOPIC%".

-- PeterThoeny - 23 Jun 2007

Is the default value of the format argument specified anywhere?

-- BryanThale - 15 Oct 2007

There is no default value, e.g. there is no output if no search hit.

-- PeterThoeny - 16 Oct 2007

I want to simplify the "Embedding search forms to return a formatted result" sample above so that the results refresh if you simply choose another option of the select field or at least that the selected option stays selected after pressing the submit button. How can this be done? Here's what I have now:

<form action="%SCRIPTURLPATH{"view"}%/%WEB%/%TOPIC%" method="get">
Show:
<select name="StatusFilter" size="1" onchange="this.form.submit();"><option value="None">&nbsp;</option><option value="New">New</option><option value="In Work">Active</option><option value="Ready">Ready</option><option value="">All</option></select> 
</form>
Projects&nbsp;&nbsp;&nbsp; Projectstatus: %URLPARAM{"StatusFilter"}%

%INCLUDE{"ProjectList" ClientName="%TOPIC%" ProjectStatus="%URLPARAM{"StatusFilter" default=""}%" }%
This uses a parametrized INCLUDE to parametrize the search, which works great. The thing that doesn't work properly is the select field, it always jumps back to the first option (here: None resp. an nonbreakable space as workaround). How can I force the view to display the selected option properly? I also did try some javascript, but couldn't get it right cause my javascript sucks.

Show:
Projects    Projectstatus:

-- FranzJosefGigler - 18 Oct 2007

The answer to my question above can be found on DynamicSelectedChoiceInSelectList, thanks Peter!

-- FranzJosefGigler - 27 Oct 2007

Hi All,

Is there any possibility to treat

$summary
as link. I mean that the search result must point to one of the entry in TOC on the page but not to topic which include search result.

-- KirillMessel - 08 May 2008

Please ask support questions in the Support web.

-- PeterThoeny - 08 May 2008

Thank you JaniHamalainen for adding the helpful note on search performance. It needs some changes before we can take this into the release. This topic is part of the TWiki core release. As such, links to non-core topics do not work, so instead of a TWiki internal link like [[+Blog.SomeTopic]] write TWiki:Blog.SomeTopic, which auto-links. This ensures that links continue to work in TWiki installed somewhere else. Also, from the official docs we do not link to support topics because they tend to have some noise. How about writing a blog post with what you learned? You could add a link in this topic pointing to your blog post on TWiki.org.

-- Peter Thoeny - 2016-03-09

Thanks Peter. I've removed the support topic link and added the newly created blog content to this topic using the proper link.

-- Jani Hamalainen - 2016-03-12

Please use the Support forum if you have questions about TWiki features. This comment section is about the documentation of this topic.
Edit | Attach | Watch | Print version | History: r90 < r89 < r88 < r87 < r86 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r90 - 2016-03-12 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.