Extension:SearchParserFunction
SearchParserFunction Release status: stable |
|
---|---|
Implementation | Parser function |
Description | Adds a parser function to search, format and display search results in wiki pages |
Author(s) | Sophivorustalk |
Latest version | 2.1 |
MediaWiki | >= 1.39.0 |
Database changes | No |
License | GNU General Public License 3.0 or later |
Download | |
Example | [1] |
Quarterly downloads | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
Public wikis using | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
Translate the SearchParserFunction extension if it is available at translatewiki.net |
The SearchParserFunction extension adds a parser function to search, format and display search results in wiki pages.
Installation
- <translate> [[<tvar name=2>Special:ExtensionDistributor/SearchParserFunction</tvar>|Download]] and move the extracted <tvar name=name>
SearchParserFunction
</tvar> folder to your <tvar name=ext>extensions/
</tvar> directory.</translate>
<translate> Developers and code contributors should install the extension [[<tvar name=git>Special:MyLanguage/Download from Git</tvar>|from Git]] instead, using:</translate>cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/SearchParserFunction - <translate> Add the following code at the bottom of your <tvar name=1>LocalSettings.php </tvar> file:</translate>
wfLoadExtension( 'SearchParserFunction' );
- File:OOjs UI icon check-constructive.svg <translate> Done</translate> – <translate> Navigate to <tvar name=special>Special:Version</tvar> on your wiki to verify that the extension is successfully installed.</translate>
Usage
Basic usage
{{#search:foo}}
This will search for pages that contain "foo" and return the results as a list of links, like so:
You can use all available search operators. For example, if you're using CirrusSearch:
{{#search:foo incategory:Bar linksto:Baz}}
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
- Namespace to search, defaults to 0 (see namespace constants). Separate multiple values with commas.limit
- Max number of results, either an integer or 'max', defaults to 10.offset
- Number of results to skip, defaults to 0, useful to access results beyond the 'max' limit.profile
- Ranking algorithm to use, defaults to let the engine decide.what
- Type of search to perform, either 'text', 'title' or 'nearmatch', defaults to 'text'.interwiki
- Include interwiki results in the search, if available.rewrites
- Enable internal query rewriting, for example to correct spelling mistakes.sort
- Sorting criteria, defaults to 'relevance'.format
- 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:
{{#search: foo | namespace = 6 | limit = 1 | what = title | sort = create_timestamp_asc | format = plain }}
Formats
List
Returns an unordered list (<ul>) of search results, linked to their pages. For example:
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:
{{#arraymap: {{#search:foo}} | , | @ | [[@]] | <br> }}
This would output the search results one below the other and linked to their pages, like so:
If some of the titles contain commas, you can change the separator like so:
{{#search:foo|separator=;}}
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 {{{1}}} and may be used or ignored.
For example, if a template named "Search result" contained the following:
<div style="border: 1px solid #aaa; border-radius: 10px; margin: 1em 0; padding: 1em; max-width: 600px;"> <big>[[{{{1}}}]]</big> <p>{{fullurl:{{{1}}}}}</p> </div>
Then a query like the following:
{{#search: foo | format = template | template = Search result }}
Would output the following:
Hooks
SearchParserFunctionQuery
Use this hook to customize the query to the Search API.
SearchParserFunctionOutput
Use this hook to add or modify search result formats.
See also
- Extension:SemanticMediaWiki - Much more sophisticated and powerful, but also much more complicated and difficult to maintain. #ask queries can do much than #search can't, but #search can also do some things that #ask can't, such as simple full-text search.
- Extension:DynamicPageList - List pages by category and other criteria
- Appropedia:Template:Search results - Real use case of this extension