API:Opensearch

From MediaWiki.org
Jump to: navigation, search
MediaWiki version: 1.9
Tools clipart.png This page is part of the MediaWiki API documentation.
MediaWiki API

Quick overview:

v · d · e

This API is provided by MediaWiki core starting with MediaWiki version 1.25 (gerrit:171573) Prior to MediaWiki 1.25, you needed to install the OpenSearch extension.

Module documentation[edit | edit source]

action=opensearch

(main | opensearch)
  • This module requires read rights.

Search the wiki using the OpenSearch protocol.

Parameters:
search

Search string.

limit

Maximum number of results to return.

No more than 100 (100 for bots) allowed.
Default: 10
namespace

Namespaces to search.

Values (separate with |): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101, 102, 103, 104, 105, 106, 107, 2500, 2501, 90, 91, 92, 93, 1198, 1199, 2600, 828, 829, 484, 485, 486, 487
Default: 0
suggest

Do nothing if $wgEnableOpenSearchSuggest is false.

redirects

How to handle redirects:

return
Return the redirect itself.
resolve
Return the target page. May return fewer than limit results.

For historical reasons, the default is "return" for format=json and "resolve" for other formats.

One value: return, resolve
format

The format of the output.

One value: json, jsonfm, xml, xmlfm
Default: json
Example:
Find pages beginning with Te.
api.php?action=opensearch&search=Te

Note on case sensitivity[edit | edit source]

Page name searches are case-sensitive. If $wgCapitalLinks is true (this is the default), the first letter is case-insensitive. If the TitleKey extension is enabled, page name searches are entirely case-insensitive.

Result format[edit | edit source]

The opensearch API module handles formats differently. It only recognizes XML and JSON (and their *fm formatted versions); every other valid format parameter results in JSON. The JSON format returns an array containing the search query and an array of result titles.

Example of API response in jsonfm format

If the wiki loads the OpenSearchXml extension or is running MediaWiki version 1.25 or greater, which merged this extension into core, then the XML format returns an OpenSearch XML document with titles and URLs. Furthermore

  • if the wiki loads the TextExtracts extension and configures $wgExtractsExtendOpenSearchXml true, then each Item in the XML format may include a <Description> tag with a text extract from the article.
  • likewise, if the wiki loads the PageImages extension and configures $wgPageImagesExpandOpenSearchXml true, then each Item in the XML format may include an <Image> tag with a thumbnail image from the article.

Example API response in xmlfm format

See also[edit | edit source]