API:Opensearch
Appearance
From mediawiki.org
This page is a translated version of the page API:Opensearch and the translation is 94% complete.
Outdated translations are marked like this.
Languages:
Esta página es parte de la documentación de la API de acciones de MediaWiki.
| API de acciones de MediaWiki |
|---|
| Uso básico |
| Autentificación |
| Cuentas y usuarios |
| Operaciones en páginas |
|
| Búsqueda |
| Herramientas de desarrollador |
| Tutoriales |
| v · d · e |
Solicitud GET para buscar la wiki y obtener resultados en un OpenSearch format. Not to be confused with the OpenSearch software suite.
API Documentación
La siguiente documentación es la salida de Special: ApiHelp/ opensearch, generada automáticamente por la versión de prelanzamiento de MediaWiki que está en ejecución en este sitio (MediaWiki.org).
action=opensearch
(main | opensearch)
- This module requires read rights.
- Source: MediaWiki
- License: GPL-2.0-or-later
Search the wiki using the OpenSearch protocol.
Specific parameters:
Other general parameters are available.
- search
Search string.
- This parameter is required.
- namespace
Namespaces to search. Ignored if search begins with a valid namespace prefix.
- Values (separate with | or alternative): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 90, 91, 92, 93, 100, 101, 102, 103, 104, 105, 106, 107, 710, 711, 828, 829, 1198, 1199, 1728, 1729, 2600, 5500, 5501
- To specify all values, use *.
- Default: 0
- limit
Maximum number of results to return.
- Type: integer or max
- The value must be between 1 and 500.
- Default: 10
- profile
Search profile to use.
- strict
- Strict profile with few punctuation characters removed but diacritics and stress marks are kept.
- normal
- Few punctuation characters, some diacritics and stopwords removed.
- normal-subphrases
- Few punctuation characters, some diacritics and stopwords removed. It will match also subphrases (can be subphrases or subpages depending on internal wiki configuration).
- fuzzy
- Similar to normal with typo correction (two typos supported).
- fast-fuzzy
- Experimental fuzzy profile (may be removed at any time)
- fuzzy-subphrases
- Similar to normal with typo correction (two typos supported). It will match also subphrases (can be subphrases or subpages depending on internal wiki configuration).
- classic
- Classic prefix, few punctuation characters and some diacritics removed.
- engine_autoselect
- Let the search engine decide on the best profile to use.
- One of the following values: classic, engine_autoselect, fast-fuzzy, fuzzy, fuzzy-subphrases, normal, normal-subphrases, strict
- Default: engine_autoselect
- suggest
- Deprecated.
No longer used.
- Type: boolean (details)
- 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 of the following values: resolve, return
- format
The format of the output.
- One of the following values: json, jsonfm, xml, xmlfm
- Default: json
- warningsaserror
If warnings are raised with format=json, return an API error instead of ignoring them.
- Type: boolean (details)
Example:
- Find pages beginning with Te.
- api.php?action=opensearch&search=Te [open in sandbox]
Ejemplo
Solicitud GET
Respuesta
[ "Hampi", [ "Hampi", "Hampi (town)", "Hampi Express", ... ], [ "Hampi, also referred to as the Group of Monuments at Hampi, is a UNESCO World Heritage Site located in east-central Karnataka, India.", "Hampi is a town in Hospet taluk of the Ballari district in the Indian state of Karnataka. Located along the Tungabhadra River in the east and center part of the state, near the border of Andhra Pradesh, Hampi is near the city of Hosapete.", "The Hampi Express is a daily express train running between the Mysooru and Hubballi Junction, the headquarters of the South Western Railway in India.", ... ], [ "https://en.wikipedia.org/wiki/Hampi", "https://en.wikipedia.org/wiki/Hampi_(town)", "https://en.wikipedia.org/wiki/Hampi_Express", ... ] ]
En Wikimedia, las descripciones de wikis están deshabilitadas debido a razones de rendimiento, por lo que la segunda matriz solo contiene cadenas vacías. Ver T241437.
Código de muestra
Python
#!/usr/bin/python3 """ opensearch.py MediaWiki API Demos Demo of `Opensearch` module: Search the wiki and obtain results in an OpenSearch (http://www.opensearch.org) format MIT License """ importrequests S = requests.Session() URL = "https://en.wikipedia.org/w/api.php" PARAMS = { "action": "opensearch", "namespace": "0", "search": "Hampi", "limit": "5", "format": "json" } R = S.get(url=URL, params=PARAMS) DATA = R.json() print(DATA)
PHP
<?php /* opensearch.php MediaWiki API Demos Demo of `Opensearch` module: Search the wiki and obtain results in an OpenSearch (http://www.opensearch.org) format MIT License */ $endPoint = "https://en.wikipedia.org/w/api.php"; $params = [ "action" => "opensearch", "search" => "Hampi", "limit" => "5", "namespace" => "0", "format" => "json" ]; $url = $endPoint . "?" . http_build_query( $params ); $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $output = curl_exec( $ch ); curl_close( $ch ); $result = json_decode( $output, true ); var_dump( $result );
JavaScript
/* opensearch.js MediaWiki API Demos Demo of `Opensearch` module: Search the wiki and obtain results in an OpenSearch (http://www.opensearch.org) format MIT License */ exportasyncfunctiongetWikiSearch(){ constparams={ action:"opensearch", search:"Hampi", limit:"5", namespace:"0", format:"json", }; consturl= "https://en.wikipedia.org/w/api.php?origin=*&"+ newURLSearchParams(params).toString(); try{ constdata=await(awaitfetch(url)).json(); console.log(data); }catch(error){ console.error("Fetch error:",error); } }
MediaWiki JS
/* opensearch.js MediaWiki API Demos Demo of `Opensearch` module: Search the wiki and obtain results in an OpenSearch (http://www.opensearch.org) format MIT License */ varparams={ action:'opensearch', search:'Hampi', limit:'5', namespace:'0', format:'json' }, api=newmw.Api(); api.get(params).done(function(data){ console.log(data); });
Errores posibles
| Código | Info |
|---|---|
| nosearch | Se debe establecer el parámetro search. |
| unknown_format | Valor no reconocido para el parámetro format: aaa. |
Notas adicionales
En relación con esta API, algunos consejos adicionales para MediaWiki administradores de sitio y desarrolladores de extensiones:
- Extension:TitleKey - permita que las sugerencias de búsqueda de esta API no distingan entre mayúsculas y minúsculas.
- Extensión:TextExtracts y
$wgExtractsExtendOpenSearchXmlconfigurados como verdaderos enLocalSettings.phppermitirían que cada elemento en el formato XML incluya una etiqueta<Description>con un extracto de texto del artículo.
- Extension:PageImages y
$wgPageImagesExpandOpenSearchXmlconfigurados como true enLocalSettings.phppermitirían que cada elemento en formato XML incluya una etiqueta<Image>con una imagen en miniatura del artículo.