CirrusSearch
Elasticsearch-powered search for MediaWiki
Loading...
Searching...
No Matches
CirrusSearch\CompletionSuggester Class Reference

Performs search as you type queries using Completion Suggester. More...

+ Inheritance diagram for CirrusSearch\CompletionSuggester:
+ Collaboration diagram for CirrusSearch\CompletionSuggester:

Public Member Functions

 __construct (Connection $conn, $limit, $offset=0, SearchConfig $config=null, array $namespaces=null, User $user=null, $index=false, $profileName=null, CirrusDebugOptions $debugOptions=null)
 
 suggest ( $text, $variants=null)
 Produce a set of completion suggestions for text using _suggest See https://www.elastic.co/guide/en/elasticsearch/reference/1.6/search-suggesters-completion.html.
 
 getCompletionIndex ()
 
- Public Member Functions inherited from CirrusSearch\ElasticsearchIntermediary
 start (RequestLog $log)
 Mark the start of a request to Elasticsearch.
 
 success ( $result=null, Connection $connection=null)
 Log a successful request and return the provided result in a good Status.
 
 successViaCache (RequestLog $log)
 Log a successful request when the response comes from a cache outside elasticsearch.
 
 failure (ExceptionInterface $exception=null, Connection $connection=null)
 Log a failure and return an appropriate status.
 
 getSearchMetrics ()
 Get the search metrics we have.
 

Protected Member Functions

 newLog ( $description, $queryType, array $extra=[])
 
- Protected Member Functions inherited from CirrusSearch\ElasticsearchIntermediary
 __construct (Connection $connection, UserIdentity $user=null, $slowSeconds=null, $extraBackendLatency=0)
 
 startNewLog ( $description, $queryType, array $extra=[])
 
 getTimeout ( $searchType='default')
 
 getClientTimeout ( $searchType='default')
 
 appendMetrics (SearchMetricsProvider $provider)
 
 runMSearch (Search $search, RequestLog $log, Connection $connection=null, callable $resultsTransformer=null)
 

Additional Inherited Members

- Static Public Member Functions inherited from CirrusSearch\ElasticsearchIntermediary
static setResultPages (array $matches)
 This is set externally because we don't have complete control, from the SearchEngine interface, of what is actually sent to the user.
 
static getQueryTypesUsed ()
 Report the types of queries that were issued within the current request.
 
static hasQueryLogs ()
 
static appendLastLogPayload ( $key, $value)
 
static isMSearchResultSetOK (MultiResultSet $multiResultSet)
 check validity of the multisearch response
 
- Protected Attributes inherited from CirrusSearch\ElasticsearchIntermediary
 $connection
 
 $user
 
 $currentRequestLog = null
 
- Static Protected Attributes inherited from CirrusSearch\ElasticsearchIntermediary
static $requestLogger
 

Detailed Description

Performs search as you type queries using Completion Suggester.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/copyleft/gpl.html Completion Suggester Searcher

NOTES: The CompletionSuggester is built on top of the ElasticSearch Completion Suggester. (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html).

This class is used at query time, see CirrusSearch\BuildDocument\SuggestBuilder for index time logic.

Document model: Cirrus documents are indexed with 2 suggestions:

  1. The title suggestion (and close redirects). This helps to avoid displaying redirects with typos (e.g. Albert Enstein, Unietd States) where we make the assumption that if the redirect is close enough it's likely a typo and it's preferable to display the canonical title. This decision is made at index-time in SuggestBuilder::extractTitleAndSimilarRedirects.
  2. The redirect suggestions Because the same canonical title can be returned twice we support fetch_limit_factor in suggest profiles to fetch more than what the use asked.

Additionally if the namespaces request include non NS_MAIN a prefix search query is sent to the main index. Results are appended to the suggest results. Appending is far from ideal but in the current state scores between the suggest index and prefix search are not comparable. TODO: investigate computing the comp suggest score on main indices to properly merge results.

Constructor & Destructor Documentation

◆ __construct()

CirrusSearch\CompletionSuggester::__construct ( Connection $conn,
$limit,
$offset = 0,
SearchConfig $config = null,
array $namespaces = null,
User $user = null,
$index = false,
$profileName = null,
CirrusDebugOptions $debugOptions = null )
Parameters
Connection$conn
int$limitLimit the results to this many
int$offset
SearchConfig | null$configConfiguration settings
int[] | null$namespacesArray of namespace numbers to search or null to search all namespaces.
User | null$useruser for which this search is being performed. Attached to slow request logs.
string | bool$indexBase name for index to search from, defaults to $wgCirrusSearchIndexBaseName
string | null$profileNameforce the profile to use otherwise SearchProfileService defaults will be used
CirrusDebugOptions | null$debugOptions

Member Function Documentation

◆ getCompletionIndex()

CirrusSearch\CompletionSuggester::getCompletionIndex ( )
Returns
Index

◆ newLog()

CirrusSearch\CompletionSuggester::newLog ( $description,
$queryType,
array $extra = [] )
protected
Parameters
string$description
string$queryType
array$extra
Returns
CompletionRequestLog

Reimplemented from CirrusSearch\ElasticsearchIntermediary.

◆ suggest()

CirrusSearch\CompletionSuggester::suggest ( $text,
$variants = null )

Produce a set of completion suggestions for text using _suggest See https://www.elastic.co/guide/en/elasticsearch/reference/1.6/search-suggesters-completion.html.

WARNING: experimental API

Parameters
string$textSearch term
string[] | null$variantsSearch term variants Usually issued via LanguageConverter::autoConvertToAllVariants( $text ) for the content language.
Returns
Status

The documentation for this class was generated from the following file: