TWiki home TWiki.Tukro > TWiki > FormattedSearch (r1.13 vs. r1.14) TWiki.Tukro webs:
Main | TWiki | Know | Sandbox
TWiki . { Welcome | Register | Changes | Topics | Index | Search | Go }
 <<O>>  Difference Topic FormattedSearch (r1.14 - 08 May 2004 - PeterThoeny)
Line: 1 to 1
Changed:
<
<
META TOPICINFO PeterThoeny date="1079506500" format="1.0" version="1.13"
>
>
META TOPICINFO PeterThoeny date="1084053269" format="1.0" version="1.14"

META TOPICPARENT TWikiVariables
TOC: No TOC in "TWiki.FormattedSearch"
Line: 140 to 140

WebStatistics TWikiGuest 04 Aug 2005 - 18:18
WebNotify MauricioVieira 24 Jun 2004 - 18:09
TWikiRegistration TWikiGuest 24 Jun 2004 - 17:20
TWikiPreferences TWikiGuest 24 Jun 2004 - 17:17
TWikiVariables PeterThoeny 09 May 2004 - 07:41
EditTablePlugin PeterThoeny 09 May 2004 - 07:21
TWikiContributor PeterThoeny 09 May 2004 - 06:50
Added:
>
>

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 that are up to exactly one week old.

Write this:

%CALC{$SET(weekold, $TIMEADD($TIME(), -7, day))}%
%SEARCH{ "." scope="topic" regex="on" nosearch="on" nototal="on" order="modified" reverse="on" format="$percntCALC{$IF($TIME($date) < $GET(weekold), <nop>, | [[$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 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
  • 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

To get this:


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:



Topic FormattedSearch . { View | Diffs | r1.14 | > | r1.13 | > | r1.12 | More }
Revision r1.13 - 17 Mar 2004 - 06:55 - PeterThoeny
Revision r1.14 - 08 May 2004 - 21:54 - PeterThoeny
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki.Tukro? Send feedback.