Extension:WikiSearch/api

Performing a search requires:


 * A search configuration page on your wiki containing a search configuration created by ;
 * An API request performing the actual search, pointing to the page ID of your page containing the configuration.

Configuration page
See Extension:WikiSearch/usage for this documentation.

Performing a search
Performs a search and returns the list of search results. If the API is in debug mode, this endpoint also returns the raw ElasticSearch query that was used to perform the search.

cURL
curl https://wiki.example.org/api.php \ -d action=query \ -d format=json \ -d meta=WikiSearch \ -d filter=[{"value":"5","key":"Average rating","range":{"gte":5,"lte":6}}] \ -d from=0 \ -d limit=10 \ -d pageid=698 \ -d aggregations=[ {"type":"range","ranges":[ {"from":1,"to":6,"key":"1"}, {"from":2,"to":6,"key":"2"}, {"from":3,"to":6,"key":"3"}, {"from":4,"to":6,"key":"4"}, {"from":5,"to":6,"key":"5"} ],"property":"Average rating"} ]

Parsing the response
This section assumes you have successfully made a request to the API using PHP and have stored the raw API result in the variable.

The  object is a JSON encoded string, and needs to be decoded before it can be used:

After having decoded the  object, the response usually contains two keys (three if debug mode is enabled):

Generally, we are only interested in the API result object, so we can create a new variable only containing that field:

This  field will look something like this:

The field
The  field contains a JSON-encoded string of the ElasticSearch search results. This field needs to be decoded using  before it can be used. The field directly corresponds to the  field from the ElasticSearch response. See the ElasticSearch documentation for very detailed documentation about what this field looks like.

To get the associated page name of any search result, the  and   hit-field in the   field may be concatenated using a colon, like so:

The  hit-field contains the name of the namespace in which the search result lives, and the   hit-field contains the name of the page that matched the search (without a namespace prefix). To get the full URL for this page, you can prepend  to the page name.

The  field also contains the generated highlighted snippets, if they are available. These can be accessed through the  hit-field, like so:

See also the ElasticSearch Highlighting documentation.

The field
The  field directly corresponds to the   field from the ElasticSearch response. See the ElasticSearch documentation for further details.

The field
The  field contains the total number of results found by ElasticSearch. This field is not influenced by the limit and always displays the total number of results available, regardless of how many were actually returned.

Filters syntax
The  parameter takes a list of objects. These objects have the following form:

PropertyRangeFilter
This filter only returns pages that have the specified property with a value in the specified range.

The above filter only includes pages where property  has a value that is greater than or equal to , but strictly less than.

The  parameter takes an object that allows the following properties:


 * : Greater-than or equal to
 * : Strictly greater-than
 * : Less-than or equal to
 * : Strictly less-than

PropertyValueFilter
This filter only returns pages that have the specified property with the specified value.

The above filter only includes pages where the property  has the value. The  may be any of the following data types:


 * string
 * boolean
 * integer
 * float
 * double

PropertyValuesFilter
This filter only returns pages that have the specified property with any of the specified values.

The above filter only includes pages where the property  has the value   or.

HasPropertyFilter
This filter only returns pages that have the specified property with any value.

The above filter only includes pages that have the property. It does not take the value of the property into account.

PropertyTextFilter
This filter only returns pages that have the specified property with a value that matches the given search query string.

The above filter executes the given query and only includes pages that matched the executed query. The query syntax is identical to the simple query syntax used by ElasticSearch.

Aggregations syntax
The  parameter takes a list of objects. These objects have the following form:

Sortings syntax
The  parameter takes a list of objects. These objects have the following form:

PropertySort
The above filter sorts the results based on the value of the property  in an  ending order. It is also possible to sort in a ending order.

Highlight API
The highlight API has the following properties:


 * : The query to generate highlighted terms from
 * : The properties over which the highlights need to be calculated
 * : The page ID of the page on which the highlights need to be calculated
 * : The number of highlighted terms to calculate; this does not always correspond directly with the number of terms returned, since duplicates are removed after the query to ElasticSearch
 * : The (approximate) size of snippets to generate, leave blank to highlight individual words