Action: search
Search — the {{search}} action searches the content of the wiki.
Union search: the results include the pages that match any of the whitespace-separated keywords (MATCH … AGAINST … IN BOOLEAN MODE for the body, combined with LIKE lower for title, tag, description and keywords).
Attention: the union behaviour depends on the database engine.
- MySQL / MariaDB: the body is searched with the full-text index in boolean mode, where several words without operators are combined with OR. The operators
+,-,>,<,~,*,",(,)are effective here. - SQLite: the body is searched in the FTS5 virtual table
page_fts, where the search phrase is inserted as a quoted literal phrase. Several words must therefore occur consecutively, and no boolean operators are supported. The tablepage_ftsmust exist; it is created by theadminupdateaction. - In both cases title, tag, description and keywords are additionally searched with a case-insensitive substring comparison of the whole phrase (
LIKE lower). The boolean operators do not work there – the phrase is used literally.
Other details:
- The search is executed only from 3 characters of the search phrase; with a shorter phrase neither results nor a message are displayed.
- In MySQL mode the results are sorted by relevance (
ORDER BY score DESC); in SQLite mode they are returned unsorted. - The number of results shown is the total number of matches, also including pages the current user may not be allowed to read.
- The preview of the matching passage is generated only in the full-text mode, shows up to 4 matching lines and is truncated to 500 characters.
1. Syntax
- Call:
{{search [phrase="Term"] [page="PageName"] [options=0|1] [topic=1] [form=1] [lang="en"] [hl_simple=0] [max=10] [nomark=0] [style=one of ("br","ul","ol","comma")] [scope=one of ("pages", "all")]}} -
phrasesearch term (at least 3 characters); can also be given in the query string as?phrase=... -
pagerestricts the search to the subpages of the specified namespace/cluster; the cluster page itself is not part of the result. Usepage="/"(or leave it empty) to search all clusters. -
options- with the value 0 only the search field is displayed, other options and filters are hidden (default is 1: language selection and the "only in page names" option are shown) -
topicif it is advanced into 1, the search occurs only on the names (tag) and titles of pages; otherwise both on the names/titles and on the texts of the pages. The option is also switched on by the mere presence of?topicin the query string. -
formthe search form is displayed when no search phrase is given; as soon as a phrase is present the form is hidden automatically (the parameter itself has no effect). -
langsearches only in pages of the given language (also possible via?lang=…); an unknown language code is ignored. -
hl_simplewith the value 1 the whole search phrase is highlighted (including partial matches); by default (0) only complete words are highlighted. -
scopeanswers for that, where to search: only in the pages ("pages") or in the commentaries also ("all", default). Every value other than "pages" is treated as "all". -
max- overwrites the system default value (default is 10) -
nomark, advanced in one, makes it possible to hide the frame (and the result header) around the results of the search. -
styleanswers for the exterior view of results:"br","ul","ol"(default) or"comma"; an unknown value falls back to"ol". - All parameters are optional.
Further filters passed through the query string and used by the search form: ?category_id=… (restrict to pages of a category), ?lang=…, ?topic.
To display the built-in help of this action use {{search help=1}}.
2. Boolean Search Operators
The MATCH AGAINST clause in MySQL, when used with the IN BOOLEAN MODE modifier, supports several operators to refine search queries. These operators include:
-
+(mandatory inclusion): The word following the plus sign must be present in the result. -
-(exclusion): The word following the minus sign must not be present in the result. -
>(increase ranking): The word following the greater-than sign is included, and its ranking value is increased. -
<(decrease ranking): The word following the less-than sign is included, and its ranking value is decreased. -
()(grouping): Parentheses are used to group words into subexpressions, allowing them to be treated as a single unit for inclusion, exclusion, or ranking. -
~(negate ranking): The ranking value of the word following the tilde is negated. -
*(wildcard): The asterisk serves as a truncation (or wildcard) operator, where words matching the prefix of the word preceding the asterisk are included. For example,sql*finds words like "sql", "sqlite", etc.. -
"(phrase matching): Double quotes are used to define a phrase, requiring the entire phrase to be matched for inclusion or exclusion. - [no operator] implies OR
These operators allow for complex and powerful searches, making the boolean mode suitable for experienced users who need precise control over search results.
Caveats:
- The operators are effective only in the full-text (body) part of the MySQL/MariaDB query. In the title/tag/description/keywords part the phrase is used as a literal substring, so an expression like
+wordwill not match anything there. - With SQLite (FTS5) the phrase is searched as a literal quoted phrase; none of the operators is interpreted.
- MySQL/MariaDB may ignore very frequent words (stopword-like behaviour), depending on the storage engine and the content of the wiki.
- The operator characters have a special meaning only in the body search; to look for them literally use the quoted phrase or the plain (non-regex) search.
2.1. Resources
- Boolean Full-Text Searches
- MariaDB: Regular Expressions
- https://mariadb.com/docs/serve[...]-text-index-overview
3. Examples
{{search phrase="BadBehaviour" page="/"}}
Search results for «BadBehaviour» (1):
-
Action: search
action, search
4. See also
- Binary string search - allows users to do a string search using exact or regex search.