SearchPatterns
Question
How do I specify patterns to include, and patterns to exclude?
Answer
Patterns can be either regexes to include ('/'), regexes to exclude ('!'):
$SearchPatterns['default'][] = '!^MyGroup\.ExcludeThisPage$!';
$SearchPatterns['default'][] = '/^MyGroup\.IncludeThisPage$/';
Question
How do I exclude certain pages from the search results?
Answer
$SearchPatterns['default'][] = '!^MyGroup\.ExcludeThisPage$!';
excludes MyGroup.ExcludeThisPage from the default search.
Question
A search for "/" displays the group name and the name of all the pages it contains. Names like Private.Budget seem to attract attention.
By using various search terms, information can be gleaned from the supposedly private pages. For example, a search for "Project X" hits the page "Private.Budget", implying some discussion of the project in the budget.
Answer
Remove the Private group from searches, by adding:
$SearchPatterns['default'][] = '!^Private\.!'; $SearchPatterns['all'][] = '!^Private\.!'; $SearchPatterns['normal'][] = '!^Private\.!';
A side effect of the code above is that the (:pagelist:) markup no longer lists the Private pages. To make it work inside the Private group change your config.php to read:
if (strncmp($pagename, 'Private.', 8) != 0) { ''as above }''
This excludes the Private group from searches only if you're not already in the Private group.
Question
The pagelist macro lists itself in its search.
Thus (:pagelist Category/Geese:)
will return a
page where the ONLY reference to "Category/Geese" is within the macro.
If there were another reference, I understand, but this gets in the way
of what I'm trying to do, which is have a page that lists all pages that
mention that category in the page.
Answer
Add the following to your config.php:
$SearchPatterns['default'][] = FmtPageName('!^$FullName$!', $pagename);
This will prevent a page from listing itself in (:pagelist:)
or
(:searchresults:)
.
Question
How can I include in a page the results of a search
for (/ -"PmWiki" -"Profiles") by using (:searchresults:)
.
Answer
If you're wanting to do exactly what it says -- i.e., display all pages
that do not have either "PmWiki" or "Profiles" in the text, then it's
just (:searchresults -"PmWiki" -"Profiles" :)
.
But if you're wanting to display all pages that are not in the PmWiki or Profiles groups, you'll probably want to create a custom search list: In config.php:
$SearchPatterns['nopp'][] = '!^(PmWiki|Profiles)\.!';
Then in the markup, use one of (:pagelist list=nopp:)
or (:searchlist list=nopp:)
.
If you're wanting this to be the default for all searches/page listings, use 'default' instead of 'nopp':
$SearchPatterns['default'][] = '!^(PmWiki|Profiles)\.!';
This is somewhat described at Cookbook/SearchResults.
Question
Is there a way to create an exclusion array for groups to feed to (:pagelist:)
like $SearchPatterns
?
Answer
$SearchPatterns
works on full pagenames, not just the part after the group.
So if you want to exclude the PmWiki group by default:
$SearchPatterns['default'][] = '!^PmWiki\.!';
If you want to exclude the PmWiki group from the "normal" page listings (i.e., via list=normal):
$SearchPatterns['normal'][] = '!^PmWiki\.!';
And if you want to create a list=restricted option that excludes a certain set of groups...
$SearchPatterns['restricted'][] = '!^(Secret|XXX|Verboten)\.!';
Question
What is the syntax for excluding pages with the SearchPatterns?
Answer
The pagelist.php script contains:
$SearchPatterns['normal'][] = '!\.(All)?Recent(Changes|Uploads)$!'; $SearchPatterns['normal'][] = '!\.Group(Print)?(Header|Footer|Attributes)$!';
You can add other patterns in local/config.php
$SearchPatterns['default'][] = '!^PmWiki.*\.!';
The use of exclamation points as the pattern delimiters tells PmWiki
this is a pattern to be excluded from the list rather than included.
$SearchPatterns['default'][] = '!^BMIT\.!'; $SearchPatterns['default'][] = '!\.GroupHeader$!'; # exclude all GroupHeaders $SearchPatterns['default'][] = '!\.GroupFooter$!'; $SearchPatterns['default'][] = '!\.Template!'; # exclude all pages starting with "Template"
Question
What can you specify with the list-parameter for these markups?
Answer
The list=
parameter specifies which set of $SearchPatterns
you want to
use. The default is "list=default
", other built-in choices are
"list=all
" and "list=normal
". (List=normal
excludes RecentChanges,
GroupHeader, GroupFooter, etc.)
Question
How can I specify several groups to search (include search) and exclude others?
Answer
$SearchPatterns
[] expects all INCLUSIVE conditions to be in a SINGLE entry while EXCLUSIVE patterns can be in as many array elements as you like. Use | as a delimiter:
$SearchPatterns['default'][] ='/^(Group1|Group2|Group3|Group4|M.*)\\./'; $SearchPatterns['default'][] ='!^Main\.!';