Bypass SEARCH's silly web-centric limit-behaviour

  • Tip Category - Developing Wiki Applications
  • Tip Added By - OliverKrueger - 18 Mar 2010 - 18:51
  • Extensions Used - FilterPlugin
  • Useful To - Beginners
  • Tip Status - New
  • Related Topics -

Problem

When you use the limit parameter with the SEARCH macro, the limit is not applied to the whole SEARCH, but to every subsearch for each web you are searching in. For example: limit="5" and web="Main,System,Sandbox" reports back up to 15 hits.

Context

VarSEARCH

Solution

Pipe the output of SEARCH through FilterPlugin's FORMATLIST macro: Usually you can take the line break as a delimitter to split up the results of SEARCH, limit them and finally reassemble them.

 
%FORMATLIST{ 
  "%SEARCH{ search="form.name='*UserForm'" limit="10" web="all" nonooise="on" type="query" format="| $web.$topic |" }%"
  split="\n"
  limit="10"
  separator="$n"   
}% 

A more complex example: This does something like SiteChanges: it shows up to ten changes in all webs in the last three days:

 
%FORMATLIST{ 
  "%SEARCH{   "info.author!='WikiGnome' AND info.date >= d2n('%URLPARAM{"since" default="%CALC{$FORMATTIME($EVAL($TIME()-3*24*3600), $year-$month-$dayT$hour:$minute:$second)}%"}%')"   limit="10"   web="all"   excludetopic="WebStatistics"   reverse="on"   order="modified"   nonoise="on"   type="query"   format="$isodate| [[%SCRIPTURLPATH{"view"}%/$web/$topic#foo_$rev][$topic]] %BR% <span class='foswikiSmall'><span class='foswikiGrayText'>on $date by $percntSPACEOUT{\"$wikiname\"}$percnt in the </span>[[$web.%HOMETOPIC%][$web web]] <span class='foswikiGrayText'>[[%SCRIPTURLPATH{"rdiff"}%/$web/$topic?type=last&render=sequential][changed]].</span></span> |" }%"   
  split="\n"
  limit="10"
  separator="$n"   
  sort="on"   
  pattern="[^\|]+(\|.*)$"   
  reverse="on" 
}% 

Known Uses

Known Limitations

See Also

Note that this sort of mess will be superseded in the 1.1 release - as I'm working hard to remove the web-centric rendering loop while speeding up the searching code, simplifying the rendering loop and adding paging. (though for compatibility reasons it will be on by default)

-- SvenDowideit - 19 Mar 2010

BestPracticeTipsForm edit

Category Developing Wiki Applications
Topic revision: r2 - 19 Mar 2010, SvenDowideit
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy