Daya Bay Reactor Neutrino Experiment
TWiki > FormattedSearch (13 vs. 14)
Daya Bay webs: Public | 中文 | Internal | Help   Log In or Register

Welcome | Register | Changes | Topics | Index | Search | Go
 <<O>>  Difference Topic FormattedSearch (14 - 2004-05-09 - PeterThoeny)
Line: 1 to 1
 
META TOPICPARENT name="TWikiVariables"
Line: 140 to 140
 
WysiwygPlugin TWikiContributor 2014-02-19 - 18:29
WikiReferences TWikiContributor 2013-09-26 - 03:36
WysiwygPluginSettings TWikiContributor 2013-09-12 - 13:06
WysiwygPluginTopicLister TWikiContributor 2013-09-12 - 13:06
WelcomeGuest TWikiContributor 2013-05-01 - 16:03
WebTopicViewTemplate TWikiContributor 2013-01-24 - 09:48
WorkflowAndAutomationVariables TWikiContributor 2012-11-11 - 17:07
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:


View | History: r26 < r25 < r24 < r23 | More

View | History: r26 < r25 < r24 < r23 | More
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Daya Bay? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.FormattedSearch.