Difference: FormattedSearch (24 vs. 25)

Revision 252013-04-23 - TWikiContributor

Line: 1 to 1
 
META TOPICPARENT name="TWikiVariables"

TWiki Formatted Search

Line: 36 to 36
 
$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
Added:
>
>
$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.
Added:
>
>
$text(encode:type) Same as above, but encoded in the specified type. Possible types are the same as ENCODE. Though ENCODE can take the extra parameter, $text(encode:type) cannot. e.g. $text(encode:html)
 
$locked LOCKED flag (if any)
$date Time stamp of last topic update, e.g. 28 Mar 2024 - 22:34
$isodate Time stamp of last topic update, e.g. 2024-03-28T22:34Z
Line: 59 to 61
 
$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
Added:
>
>
$formfield(name, encode:type) Form field value, encoded in the specified type. This is in parallel to $text(encode:type) shown above. Comma followed by encode:type can be added to the $formfield(...) syntax below as well. But it needs to be the last paramer. e.g. $formfield(Description, 20, encode:html)
 
$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
Added:
>
>
$query(query-syntax, encode:type) QuerySearch result is encoded in the specified type. This is in parallel to $text(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
Added:
>
>
$pattern(reg-exp, encode:type) A text extracted by reg-exp is encoded in the specified type. This is in parallel to $text(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
Added:
>
>
$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"
$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 (>)
Line: 78 to 85
 
Name: Expands To:
$web Name of the web
$ntopics Number of topics found in current web
Added:
>
>
$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"
$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 (>)
Added:
>
>

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:
<-- -->
Sorted ascending
Expands To:
$aquot Apostrophe quote (')
$dollar Dollar sign ($)
$gt Greater than sign (>)
$lt Less than sign (<)
$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
$percnt Percent sign (%)
$quot or \" Double quote (")
$web Name of the web

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

Line: 98 to 125
  Write this:
Changed:
<
<
%SEARCH{ "FAQ" scope="topic" nosearch="on" nototal="on" header="   * *Topic: Summary:*" format="   * [[$topic]]: $summary"  footer="   * *Topic: Summary*"  }%
>
>
%SEARCH{
 "FAQ"
 scope="topic"
 nosearch="on"
 nototal="on"
 header="   * *Topic: Summary:*"
 format="   * [[$topic]]: $summary"
 footer="   * *Topic: Summary*"
}%
  To get this:
Changed:
<
<
  • 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
>
>
  • 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

Line: 123 to 168
  Write this:
Changed:
<
<
%SEARCH{ "__Back to\:__ TWikiFAQ" scope="text" type="regex" nosearch="on" nototal="on" header="TWiki FAQs:" format="   * $pattern(.*?FAQ\:[\n\r]*([^\n\r]+).*) [[$topic][Answer...]]" }%
>
>
%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:
Changed:
<
<
TWiki FAQs:
  • How can I create a simple TWiki Forms based application? 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...
  • TWiki is distributed under the GPL (GNU General Public License). What is GPL? 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...
  • 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...
>
>
TWiki FAQs:
  • How can I create a simple TWiki Forms based application? 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...
  • TWiki is distributed under the GPL (GNU General Public License). What is GPL? 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...
  • 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

Line: 148 to 211
  Write this:
Changed:
<
<
%SEARCH{ "culture" format="   * $topic is referenced by:$n      * $percntSEARCH{ \"$topic\" format=\"$dollartopic\" nosearch=\"on\" nototal=\"on\" separator=\", \" }$nop%" nosearch="on" nototal="on" }%
>
>
%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:
Changed:
<
<
>
>
  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.
Line: 160 to 235
  Write this:
Changed:
<
<
%SEARCH{ "\.*" scope="topic" type="regex" nosearch="on" nototal="on" order="modified" reverse="on"  format="| [[$topic]] | $wikiusername  | $date |" limit="7" }%
>
>
%SEARCH{
 "\.*"
 scope="topic"
 type="regex"
 nosearch="on"
 nototal="on"
 sort="modified"
 reverse="on"
 format="| [[$topic]] | $wikiusername  | $date |"
 limit="7"
}%=
  To get this:
Changed:
<
<
WebStatistics Main.TFrancois2 2016-10-12 - 21:16
LaTeXToMathMLPlugin TWikiAdminUser 2016-02-26 - 16:51
LatexSymbols3 TWikiAdminUser 2016-02-25 - 20:00
LatexSymbols TWikiAdminUser 2016-02-25 - 20:00
LatexIntro TWikiAdminUser 2016-02-18 - 22:43
LatexModePlugin TWikiAdminUser 2016-02-18 - 22:43
LatexSymbols2 TWikiAdminUser 2016-02-18 - 22:43
>
>
WebStatistics Main.TFrancois2 2016-10-12 - 21:16
LaTeXToMathMLPlugin TWikiAdminUser 2016-02-26 - 16:51
LatexSymbols3 TWikiAdminUser 2016-02-25 - 20:00
LatexSymbols TWikiAdminUser 2016-02-25 - 20:00
LatexIntro TWikiAdminUser 2016-02-18 - 22:43
LatexModePlugin TWikiAdminUser 2016-02-18 - 22:43
LatexSymbols2 TWikiAdminUser 2016-02-18 - 22:43
 

Search with conditional output

Line: 178 to 275
  Write this:
Changed:
<
<
%CALC{$SET(weekold, $TIMEADD($TIME(), -7, day))}%
%SEARCH{ "." scope="topic" type="regex" web="Main" nonoise="on" order="modified" reverse="on" format="$percntCALC{$IF($TIME($date) < $GET(weekold), <nop>, | [[$web.$topic][$topic]] | $wikiusername | $date | $rev |)}$percnt" limit="100" }%
>
>
%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
Changed:
<
<
  • The SEARCH has a deferred CALC. The $percnt makes sure that the CALC gets executed once for each search hit
  • The CALC compares the date of the topic with the weekold date
>
>
  • 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
Added:
>
>
  • This example is for illustration only, it is easier to use the date="..." paramter in SEARCH to restrict the date.
  To get this:
Changed:
<
<
WebStatistics TWikiGuest 2024-03-28 - 07:54 2180
SiteStatistics TWikiGuest 2024-03-26 - 08:52 1319
>
>
WebStatistics TWikiGuest 2024-03-28 - 07:54 2180
SiteStatistics TWikiGuest 2024-03-26 - 08:52 1319
  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.
Line: 200 to 298
  Write this:
Changed:
<
<
%SEARCH{ "." scope="topic" type="regex" web="Main" nonoise="on" order="modified" reverse="on" format="| [[$web.$topic][$topic]] | $wikiusername | $date | $rev |" limit="100" date="P1w/$today" }%
>
>
%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:
Changed:
<
<
WebStatistics TWikiGuest 2024-03-28 - 07:54 2180
SiteStatistics TWikiGuest 2024-03-26 - 08:52 1319
>
>
WebStatistics TWikiGuest 2024-03-28 - 07:54 2180
SiteStatistics TWikiGuest 2024-03-26 - 08:52 1319
 

Embedding search forms to return a formatted result

Line: 218 to 340
   Result:
Changed:
<
<
>
>
 

To get this:

Line: 228 to 355
   Result:
Changed:
<
<
>
>
 
Changed:
<
<
Related Topics: UserDocumentationCategory, SearchHelp, VarSEARCH, SearchPatternCookbook, RegularExpression, QuerySearch
>
>
Related Topics: UserDocumentationCategory, SearchHelp, VarSEARCH, VarENCODE, SearchResultsPagination, SearchPatternCookbook, RegularExpression, QuerySearch
  -- Contributors: TWiki:Main.PeterThoeny, TWiki:Main.CrawfordCurrie, TWiki:Main.SopanShewale
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.FormattedSearch.