Extension:WikiSearch/advanced
This page describes more advanced features of the WikiSearch extension, such as how to use property chains and how to extend WikiSearch.
Chained properties
[edit]WikiSearch provides support for creating filters with chained properties. Chained properties can be used in any filter. They can also be used as a search term property.
{
"key": "Subpage.Foobar",
"value": "+"
}
For instance, the above filter matches any page for which the value of the property "Subpage" is a page that contains the property "Foobar".
Special properties
[edit]There are a number of special properties defined by Semantic MediaWiki that are worth pointing out. These properties act just like regular properties, but do not appear in Special:Browse. Some of them are:
text_copy: (from SemanticMediaWiki documentation) this mapping is used to enable wide proximity searches on textual annotated elements. Thetext_copyfield is a compound field for all strings to be searched when a specific property is unknown.text_raw: this mapping contains unstructured, unprocessed raw text from an article.attachment-title: this mapping contains the title of a file attachment.attachment-content: this mapping contains the content of a file attachment.
Hooks
[edit]WikiSearchBeforeElasticQuery
[edit]This hook is called right before the query is sent to ElasticSearch. It has the following signature:
function onWikiSearchBeforeElasticQuery( array &$query, array &$hosts ) {}
The hook has access to and can alter the given $query. It can also add or remove hosts from the $hosts array.
WikiSearchApplyResultTranslations
[edit]This hook is called right before returning the final results to the API. It can be used to alter the $results array. This can be useful to filter any pages the user is not allowed to see or add additional data to the query result.
It has the following signature:
function onWikiSearchApplyResultTranslations( array &$results ) {}
WikiSearchOnLoadFrontend
[edit]This hook must be implemented by any WikiSearch frontend. It gets called when the #WikiSearchFrontend parser function is called. It has the following signature:
function onWikiSearchOnLoadFrontend(
string &$result,
\WikiSearch\SearchEngineConfig $config,
Parser $parser,
array $parameters
) {}
string &$result: The result of the call to the parser function. This is the text that will be transcluded on the page.SearchEngineConfig $config: The SearchEngineConfig object of the current page. The SearchEngineConfig object exposes the following methods:getTitle(): Title: The Title associated with this SearchEngineConfiggetConditionProperty(): PropertyInfo: The PropertyInfo object associated with the property in the search condition (e.g.ClassforClass=Foobar)- The
PropertyInfoclass exposes the following methods:getPropertyID(): int: Returns the property IDgetPropertyType(): string: Returns the property type (e.g.txtFieldorwpgField)getPropertyName(): string: Returns the name of the property (e.g.Class)
- The
getConditionValue(): string: Returns the value in the condition (e.g.FoobarinClass=Foobar)getFacetProperties(): array: Returns the facet properties in the config (facet properties are the properties that are **not** prefixed with?). May be the name of a property (e.g. "Foobar") or a translation pair (e.g. "Foobar=Boofar")getFacetPropertyIDs(): array: Returns a key-value pair list where the key is the ID of the facet property and the value the type of that propertygetResultProperties(): array: Returns the result properties in the config as PropertyInfo objects (result properties are the properties prefixed with?)getResultPropertyIDs(): array: Returns a key-value pair list where the key is the name of the result property and the value the ID of that propertygetSearchParameters(): array: Returns a key-value pair list of additional search parameters
Parser $parser: The current Parser objectarray $parameters: The parameters passed to the#WSSearchFrontendcall
Debug mode
[edit]To enable debug mode, set $wgWikiSearchEnableDebugMode to true. With debug mode enabled, the raw ElasticSearch query will be returned with each API request.