SearchGroup

<< | Cookbook-V1 | >>

Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


Goal

Limit searches to a single group without requiring a group specifier in the search string.

Solution

In local.php, modify the form given by $SearchTagFmt to include a "group" control element:

    $SearchTagFmt = "<form action='\$PageUrl' method='get'>
      <input type='hidden' name='group' value='\$Group' />
      <input type='hidden' name='action' value='search' />
      <input type='text' name='text' value='' size='40' />
      <input type='submit' value='Search' /></form>";

Discussion

When performing a search, the search.php script that comes with PmWiki/PmWiki searches all groups on a site unless restricted to a single group by either a "Group/" specifier at the beginning of the search string or a "group" control element in the search form. The solution given above modifies the search form generated by the [[$Search]] tag to include a group control element that restricts the search to the current group.

For example, this search box will only search for pages in the Cookbook-V1 group.

Even with this modification, the user can still search a different group by including a group name and slash at the beginning of the search string.

There's nothing that says the group control has to be a 'hidden' control; one can also use other form elements such as checkboxes, radio buttons, text fields, etc. to specify the group. $Searchradio?

For example, John Rankin creates a group pick list using the <select> and <option> elements, with the current group set to <option selected='selected'>. He does this by reading and sorting the pages listed on Main.AllRecentChanges to create a list of groups.

At present there's no way to search a limited number of groups; you can either search a single group or search all of them. However, Pm says he can modify search.php to allow multiple group searches if that's needed.

Suggestion
Change the search results line to read "Searching for needle in haystack." The needle is the text being sought (or all) and the haystack is the group name (or all groups).

See Also

  • Main.SearchWiki

Contributors

Comments

Here's 2 votes for Pm to modify search.php to allow multiple group seraches.
Search the WikiFarm would also be practical sometimes. PatrickOgay

The above search box actually searches all groups currently... The trick doesn't work!!!


It works now -- I didn't have this particular recipe enabled on t his page (the local customization didn't survive one of pmwiki.org's upgrades).

The ability to search multiple groups is available in PmWiki 2?. --Pm


Hm, for me the search result of the above box still shows hits in all groups. Must be because this is a V1 recipe in a V2 wiki :-)

Henning pmwiki-2.3.38 -- Last modified by {{Henning}}

from IP: 85.171.160.186 ip should be disabled by default for security reasons