Summary: How to change the way search results are displayed


How can I change the way search results are displayed?


(:searchresults:) can be customized by editing page Site.Search. For instance to limit the result to group Main you would change the (:searchresults:) to (:searchresults group=Main:)


How can I add a link to create a new page on the search results page when no matches were found?


Add this "hack" to the pagelist.php file in your /scripts directory.

Note that it is highly recommended NOT to modify files from the core distribution which will be replaced when you upgrade. --Petko October 08, 2013, at 09:59 PM

Replace this, on line 55:

XLSDV('en', array(
  'SearchFor' => 'Results of search for <em>$Needle</em>:',
  'SearchFound' => 
    '$MatchCount pages found out of $MatchSearched pages searched.'));

With this:

if($MatchCount < 1) {
 $xlsdvArgs = array(
  'SearchFor' => 'Results of search for <em>$Needle</em>:',
  'SearchFound' => 
    '<p>No results found.  Create a new page for 
        "<a href="index.php/Main/$Needle">$Needle</a>"</p>');	
else {
$xlsdvArgs = array(
  'SearchFor' => 'Results of search for <em>$Needle</em>:',
  'SearchFound' => 
    '$MatchCount pages found out of $MatchSearched pages searched.');

XLSDV('en', $xlsdvArgs); 


How can I exclude pages such as RecentChanges or GroupHeader from being displayed in search results and page lists?


The list=normal Parameter

PmWiki pre-defines a "list=normal" parameter to the (:searchresults:) and (:pagelist:) directives, adding this parameter excludes pages with names like RecentChanges or GroupHeader from appearing in the output. For example,

(:pagelist group=Cookbook list=normal:)

gives a list of all "normal" pages in the Cookbook (pages except for RecentChanges, GroupHeader, etc).

Defining Custom Parameters

PmWiki's default is to display all pages; but a wiki administrator can override this default by adding entries to $SearchPatterns.

For example, to define "list=calendar" to limit the results to pagenames in a yyyy-mm-dd format, an administrator can add the following to config.php, using forward-slash / delimiters (at the start and end of the string) to include pages:

$SearchPatterns['calendar'][] = '/\\.\\d{4}-\\d\\d-\\d\\d$/';

With this definition, the markup (:pagelist list=calendar:) would only display pages with names in a yyyy-mm-dd format.

For search exclusions, use patterns delimited by exclamation points. Thus an administrator can define "list=norc" to exclude any pagename ending in "RecentChanges":

$SearchPatterns['norc'][] = '!RecentChanges$!';

To change the default listings to exclude RecentChanges, AllRecentChanges, GroupHeader, and etc., use something like:

$SearchPatterns['default'][] = '!\\.(All)?Recent(Changes|Uploads)$!';
$SearchPatterns['default'][] = '!\\.Group(Print)?(Header|Footer|Attributes)$!';

Similarly, you can exclude groups.

$SearchPatterns['default'][] = '!^Site\\.!';
$SearchPatterns['default'][] = '!^PmWiki\\.!';


How can i make the Search should use the Group it is called from to return the result

For example you may use a customised search page, say TTC/Search


It appears this can be achieved by the following steps

  • insert $PageSearchForm = '$DefaultGroup.Search'; at the end of your config.php file
  • change $SiteGroup/Search to $DefaultGroup/Search (twice) in the $DefaultGroup pmwiki.tmpl (change $DefaultGroup to suit)
  • create the page DefaultGroup.Search, use the $SiteGroup.Search as a model

Alternatively try

(:searchbox size=24 group=TTC target=TTC.Search:)
(:if equal {$Action} "search":)
(:searchresults list=normal name=-template:)

See also

  • Search   Targeting and customizing search results


If you're using PmWiki as a CMS, the following lines in your local/config.php will exclude wiki-related pages from searches without a list= parameter:

## Exclude Certain pages / groups from search results.

$SearchPatterns['default'] = array(
  'recent' => '!\.(All)?Recent(Changes|Uploads)$!',
  'group' => '!\.Group(Print)?(Header|Footer|Attributes)$!',
  'pmwiki' => '!^(Site|PmWiki)\\.!' );


  • Pm, 20-Oct-2004