API:Search
From MediaWiki.org
| This page is part of the MediaWiki action API documentation. |
MediaWiki action API
- Introduction and quick start
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Searching (by title, content, coordinates...)
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
- Asserting
| Search | ||
|---|---|---|
| Perform a full text search This module cannot be used as a Generator. |
||
| Prefix | sr | |
| Required rights | none | |
| Post only? | No | |
| Generated help | Current | |
| Version added |
|
Search titles and text.
Contents
Parameters[edit]
srsearch: Search for all page titles (or content) that have this value.srnamespace: The namespace(s) to enumerate. No more than 50 (500 for bots) allowed. (Default: 0)srwhat: Search inside the text or titles. (Default:title(if search engine doesn't support title searches, such as Lucene which was previously used by Wikipedia, thensrwhat=titlefalls back totext))title: Search in page titlestext: Search in page textnearmatch: Search for a near match in the title 1.17+
srinfo: What metadata to return. Possible values:totalhits,suggestion. (Default:totalhits|suggestion) 1.16+srprop: What properties to return. (Default:size|wordcount|timestamp|snippet) 1.16+size: Adds the size of the page in byteswordcount: Adds the word count of the pagetimestamp: Adds the timestamp of when the page was last editedscore: Adds the score (if any) from the search engine 1.17+ (deprecated in 1.24)snippet: Adds a parsed snippet of the pagetitlesnippet: Adds a parsed snippet of the page title 1.17+redirecttitle: Adds a parsed snippet of the redirect title 1.17+redirectsnippet: Adds a parsed snippet of the redirect 1.17+sectiontitle: Adds a parsed snippet of the matching section title 1.17+sectionsnippet: Adds a parsed snippet of the matching section 1.17+hasrelated: Indicates whether a related search is available 1.17+ (deprecated in 1.24)
srredirects: Include redirect pages in the search. From 1.23 onwards, redirects are always included. (Default: false) (removed in 1.23)sroffset: Use this value to continue paging (returned by query).srlimit: How many total pages to return. No more than 50 (500 for bots) allowed. (Default: 10)srinterwiki: Include interwiki results in the search, if available. (Default: false) 1.23+srbackend: Class name of search backend to use (Default: $wgSearchType) 1.22+
Depending on which search backend is in use, how
srsearch is interpreted may vary. On Wikimedia wikis which use CirrusSearch, see Help:CirrusSearch for information about the search syntax.Error codes[edit]
| Result | Meaning |
|---|---|
| nosearch | The search parameter must be set. This was param-search before 1.17 |
| search-text-disabled | text search is disabled. |
| search-title-disabled | title search is disabled. |
| search-error | search error has occurred. |
Example[edit]
Search for "Albert Einstein" (defaults to title search), returning default search information with UTF8 characters
| Result |
|---|
{
"query": {
"searchinfo": {
"totalhits": 4152
},
"search": [
{
"ns": 0,
"title": "Albert Einstein",
"snippet": ""<span class=\"searchmatch\">Einstein</span>" redirects here. For other uses, see <span class=\"searchmatch\">Albert</span> <span class=\"searchmatch\">Einstein</span> (disambiguation) and <span class=\"searchmatch\">Einstein</span> (disambiguation). <span class=\"searchmatch\">Albert</span> <span class=\"searchmatch\">Einstein</span> (/ˈælbərt ˈaɪnʃtaɪn/; German:",
"size": 124479,
"wordcount": 13398,
"timestamp": "2015-05-10T12:37:14Z"
},
{
"ns": 0,
"title": "Albert Einstein Medal",
"snippet": "The <span class=\"searchmatch\">Albert</span> <span class=\"searchmatch\">Einstein</span> Medal is an award presented by the <span class=\"searchmatch\">Albert</span> <span class=\"searchmatch\">Einstein</span> Society in Bern. First given in 1979, the award is presented to people for "scientific",
"size": 2280,
"wordcount": 207,
"timestamp": "2015-04-15T03:03:46Z"
},
...
}
|
Show a list of 10 pages that contain the word "wikipedia", returning their timestamp; request information to search for the next 10 matches
api.php? action=query& list=search& srsearch=wikipedia& srwhat=text& srprop=timestamp& continue= [try in ApiSandbox]
| Result |
|---|
{
"batchcomplete": "",
"continue": {
"sroffset": 10,
"continue": "-||"
},
"query": {
"searchinfo": {
"totalhits": 2392055
},
"search": [
{
"ns": 0,
"title": "Wikipedia",
"timestamp": "2015-05-11T21:48:40Z"
},
{
"ns": 0,
"title": "List of Wikipedias",
"timestamp": "2015-05-05T20:55:34Z"
},
{
"ns": 0,
"title": "English Wikipedia",
"timestamp": "2015-05-14T01:13:08Z"
},
{
"ns": 0,
"title": "Wikipedia community",
"timestamp": "2015-04-22T23:59:50Z"
},
{
"ns": 0,
"title": "Simple English Wikipedia",
"timestamp": "2015-02-22T23:00:51Z"
},
{
"ns": 0,
"title": "French Wikipedia",
"timestamp": "2015-03-16T17:53:18Z"
},
{
"ns": 0,
"title": "Wikipedia Ambassador Program",
"timestamp": "2015-03-05T20:03:55Z"
},
{
"ns": 0,
"title": "Nepal Bhasa Wikipedia",
"timestamp": "2014-10-14T22:15:01Z"
},
{
"ns": 0,
"title": "Wikipedia for Schools",
"timestamp": "2015-04-24T13:54:59Z"
},
{
"ns": 0,
"title": "Persian Wikipedia",
"timestamp": "2014-12-19T20:51:27Z"
}
]
}
}
|
See also[edit]
- API:Opensearch
- API:Search and discovery overview of search APIs

