Extension:SearchParserFunction

The SearchParserFunction extension adds a parser function to search, format and display search results in wiki pages.

Basic usage
This will search for pages that contain "foo" and return the results as a list of links, like so:


 * Foo
 * Bar
 * Baz

You can use all available search operators. For example, if you're using CirrusSearch:

See Help:CirrusSearch for all available search operators (or Help:Searching if you're not using CirrusSearch).

Note! The current page will be excluded from the search results.

Parameters

 * - Namespace to search, defaults to 0 (see namespace constants). Separate multiple values with commas.
 * - Max number of results, either an integer or 'max', defaults to 10.
 * - Number of results to skip, defaults to 0, useful to access results beyond the 'max' limit.
 * - Ranking algorithm to use, defaults to let the engine decide.
 * - Type of search to perform, either 'text', 'title' or 'nearmatch', defaults to 'text'.
 * - Include interwiki results in the search, if available.
 * - Enable internal query rewriting, for example to correct spelling mistakes.
 * - Sorting criteria, defaults to 'relevance'.
 * - Format of the search results, defaults to 'list' (see below for more).

For example, to get the name of the latest file that has "foo" in the title:

List
Returns an unordered list (  ) of search results, linked to their pages. For example:


 * Foo
 * Bar
 * Baz

Count
Returns the total number of search results as a plain number.

Plain
Returns a comma-separated list of plain titles, for example:

Foo, Bar, Baz

This format is designed for further processing. For example, using the #arraymap function of Extension:PageForms:

This would output the search results one below the other and linked to their pages, like so:

Foo Bar Baz

If some of the titles contain commas, you can change the separator like so:

JSON
Returns a JSON object for further processing, for example in a Lua module.

Note that this format returns the entire output from the Search API, not just the search results.

Template
Returns the search results wrapped in a template. The search result title is passed to the template as an unnamed parameter and may be used or ignored.

For example, if a template named "Search result" contained the following:



Then a query like the following:

Would output the following:

Foo https://www.mediawiki.org/wiki/Foo Bar https://www.mediawiki.org/wiki/Bar Baz https://www.mediawiki.org/wiki/Baz

SearchParserFunctionQuery
Use this hook to customize the query to the Search API.

SearchParserFunctionOutput
Use this hook to add or modify search result formats.