New Foswiki release 2.1.6 is available with important security fixes.
Sourceforge foswiki email lists being discontinued. Subscribe to the new Foswiki announce and discuss lists at MailingLists
same as cairo, so i'm marking this as an enhancement


Probably good to introduce a new parameter toplimit (or the like) to limit the total number of hits. This is for compatibility.

-- PTh

This would be a real treat. Have had a suggestions from users to use some top space (WebTopBar) for a "last 5 changed topics, globally"-style info area, but this is not easy to implement using current search.

-- SP

ThisIsEasy CC

I hope you are right, CC smile

Looking at the code, naively I'd probably jump in around line 949 in, where all webs has been searched. - Unfortunately, everything is rendered more or less up at this point, so I guess the only simple opportunity left (without a major refactor) is simply regexp'ing the $searchresult for $separator, taking first $toplimit matches and cutting the rest.

In cases where the search result contains $separators on it's own, this will of course not work reliably, but I'm having problems imagining any real life searches where this would actually be a problem.

Other solutions, or will this work? I.e. something like:

Index: lib/TWiki/
--- lib/TWiki/   (revision 8988)
+++ lib/TWiki/   (working copy)
@@ -381,6 +381,7 @@
     my $header =        $params{header} || '';
     my $inline =        $params{inline};
     my $limit =         $params{limit} || '';
+    my $toplimit =      $params{toplimit};
     my $doMultiple =    TWiki::isTrue( $params{multiple} );
     my $nonoise =       TWiki::isTrue( $params{nonoise} );
     my $noEmpty =       TWiki::isTrue( $params{noempty}, $nonoise );
@@ -947,6 +948,12 @@
         return '' if ( $ntopics == 0 && $zeroResults );
+    # if toplimit is set, cut down number of searchresults
+    if ( defined $toplimit && $toplimit =~ /(^\d+$)/o && $noTotal ) {
+        my $sep = $separator || "\n";
+        $searchResult =~ s/^((.*?$sep){0,$toplimit}).*$/$1/s;
+    }
     if( $format  && ! $finalTerm ) {
         if( $separator ) {
             $searchResult =~ s/$separator$//s;  # remove separator at end
Index: data/TWiki/VarSEARCH.txt
--- data/TWiki/VarSEARCH.txt   (revision 8988)
+++ data/TWiki/VarSEARCH.txt   (working copy)
@@ -1,4 +1,4 @@
-%META:TOPICINFO{author="TWikiContributor" date="1111929255" format="1.2" version="$Rev$"}%
+%META:TOPICINFO{author="SteffenPoulsen" date="1141253089" format="1.1" version="1.2"}%
@@ -15,7 +15,8 @@
      | =type="keyword"= <br /> =type="literal"= <br /> =type="regex"= | Do a keyword search like =soap "web service" -shampoo=; a literal search like =web service=; or RegularExpression search like =soap;web service;!shampoo= | =%<nop>SEARCHVAR- DEFAULTTYPE%= [[TWikiPreferences][preferences]] setting (%SEARCHVARDEFAULTTYPE%) |
      | =scope="topic"= <br /> =scope="text"= <br /> =scope="all"= | Search topic name (title); the text (body) of topic; or all (both) | ="text"= |
      | =order="topic"= <br /> =order="created"= <br />  =order="modified"= <br /> =order="editby"= <br /> =order=<br />&nbsp;"formfield(name)"= | Sort the results of search by the topic names, topic creation time, last modified time, last editor, or named field of TWikiForms. The sorting is done web by web; if you want to sort across webs, create a [[FormattedSearch][formatted]] table and sort it with TablePlugin's initsort. Note that dates are sorted most recent date *last* (i.e at the bottom of the table). | Sort by topic name |
-     | =limit="all"= <br /> =limit="16"= | Limit the number of results returned. This is done after sorting if =order= is specified | All results |
+     | =limit="all"= <br /> =limit="16"= | Limit the number of results returned from a single web. This is done after sorting if =order= is specified | All results |
+     | =toplimit="20"= | Limit the number of total number of results returned. This is done after sorting if =order= is specified. =toplimit= will only work if =nototal= is set to "on". | All results |
      | =date="..."= | limits the results to those pages with latest edit time in the given TimeInterval.  | All results |
      | =reverse="on"= | Reverse the direction of the search | Ascending search |
      | =casesensitive="on"= | Case sensitive search | Ignore case |
@@ -37,4 +38,3 @@
    * Example with format: =%<nop>SEARCH{"FAQ" scope="topic" nosearch="on" nototal="on" header="| *Topic: * | *Summary: * |" format="<nop>| $topic | $summary |"%= _(displays results in a table with header - [[FormattedSearch][details]])_
    * %H% Hint: If the TWiki:Plugins.TablePlugin is installed, you may set a =%<nop>TABLE{}%= variable just before the =%<nop>SEARCH{}%= to alter the output of a search.  Example: =%<nop>TABLE{ tablewidth="90%" }%=
    * Related: [[#VarMETASEARCH][METASEARCH]], [[#VarTOPICLIST][TOPICLIST]], [[#VarWEBLIST][WEBLIST]], FormattedSearch

-- SP

Whooops, completely missed the fact that topics are not globally sorted in $searchResult, but only sorted "per web". This means giving up on the easy part for me.

-- SP

This topic was lost from the lists due to not having a codebase field. Rediscovered 3/2/07.


No spec change please. New paramter is ok.

-- PTh

I would find limitall a more intuitive name, alongside limitweb, while limit is maintained for compatibility.

-- TWiki:Main.ArthurClemens - 03 Feb 2007

Sounds like it's just waiting for an implementor. Set status accordingly.


new limitall and limitweb, keeping limit as undocumented feature sounds like a plan.

-- TWiki:Main.PeterThoeny - 05 Feb 2007

One possible workaround for creating the "last 5 modified pages" search is the following hack:

<!-- Hide the macro assignment
   * Set number_of_changed_topics = 5
   * Set changed_topics = %SEARCH{"!='WikiGnome'" type="query" nosearch="on" nototal="on" 
      limit="%number_of_changed_topics%" web="all" excludetopic="WebStatistics" 
      reverse="on" order="modified" format="$isodate-[[$web/$topic]] ($wikiname)" separator=", "

%CALC{"$LISTMAP($REPLACE($item,1,$FIND([, $item),[),$LISTTRUNCATE(%number_of_changed_topics%, $LISTREVERSE($LISTSORT(%changed_topics%))))"}%

The hack creates a SEARCH which gives comma separated list of topics, prefixed with the last modified date of the topic. Search gives at most number_of_changed_topics topics in each web.

After that we use the SpreadSheetPlugin to modify the list. From backward, first sorting, then reversing, then taking the number_of_changed_topics from the head of the list, then applying replace function to each item to remove the date prefix.

-- AivoJurgenson - 10 Feb 2009

This is now implemented in foswiki 1.1 - due to the paging code needing it - see MakeSEARCHResultPartitioningByWebOptional .

basically, as groupby=none to your SEARCH.

BEWARE that this might change in foswiki 2.0 - though I hope not.

-- SvenDowideit - 19 May 2010

ItemTemplate edit

Summary Modify the SEARCH limit parameter to apply to the total number of matches (not per web)
ReportedBy TWiki:Main.WillNorris
Codebase trunk
SVN Range
AppliesTo Engine
Priority Enhancement
CurrentState Closed
Checkins distro:7a0b8eb4c066
TargetRelease minor
ReleasedIn 1.1.0
Topic revision: r20 - 04 Oct 2010, KennethLavrsen - This page was cached on 18 Sep 2018 - 15:46.

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