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

Suggest (Completion) query builder. More...

Public Member Functions

 __construct (SearchContext $context, array $profile, $limit, $offset=0)
 
 areResultsPossible ()
 Check the builder settings to determine if results are possible.
 
 build ( $term, $variants=null)
 Build the suggest query.
 
 postProcess (CompletionResultsCollector $collector, ResultSet $results, $indexName)
 Post process the response from elastic to build the SearchSuggestionSet.
 
 getMergedProfiles ()
 (public for tests)
 
 getLimit ()
 Number of results we could display.
 

Static Public Member Functions

static computeHardLimit ( $limit, $offset, SearchConfig $config)
 Get the hard limit The completion api does not supports offset we have to add a hack here to work around this limitation.
 

Public Attributes

const VARIANT_EXTRA_DISCOUNT = 0.0001
 

Protected Member Functions

 buildVariantProfile (array $profile, $extraDiscount=0.0001)
 Creates a copy of $profile[$name] with a custom '-variant-SEQ' suffix.
 

Detailed Description

Suggest (Completion) query builder.

Unlike classic query builders it will :

  • handle limit differently as offsets are not accepted during suggest queries
  • store a mutable state in mergedProfiles

Constructor & Destructor Documentation

◆ __construct()

CirrusSearch\Query\CompSuggestQueryBuilder::__construct ( SearchContext $context,
array $profile,
$limit,
$offset = 0 )
Parameters
SearchContext$context
array$profilesettings as definied in profiles/SuggestProfiles.config.php
int$limitthe number of results to display
int$offset

Member Function Documentation

◆ areResultsPossible()

CirrusSearch\Query\CompSuggestQueryBuilder::areResultsPossible ( )

Check the builder settings to determine if results are possible.

If this method returns false the query must not have to be sent to elastic

Returns
bool true if results are possible false otherwise

◆ build()

CirrusSearch\Query\CompSuggestQueryBuilder::build ( $term,
$variants = null )

Build the suggest query.

Parameters
string$term
string[] | null$variants
Returns
Suggest

◆ buildVariantProfile()

CirrusSearch\Query\CompSuggestQueryBuilder::buildVariantProfile ( array $profile,
$extraDiscount = 0.0001 )
protected

Creates a copy of $profile[$name] with a custom '-variant-SEQ' suffix.

And applies an extra discount factor of 0.0001. The copy is added to the profiles container.

Parameters
array$profileprofile to copy
float$extraDiscountextra discount factor to rank variant suggestion lower.
Returns
array

◆ computeHardLimit()

static CirrusSearch\Query\CompSuggestQueryBuilder::computeHardLimit ( $limit,
$offset,
SearchConfig $config )
static

Get the hard limit The completion api does not supports offset we have to add a hack here to work around this limitation.

To avoid ridiculously large queries we set also a hard limit. Note that this limit will be changed by fetch_limit_factor set to 2 or 1.5 depending on the profile.

Parameters
int$limitlimit requested
int$offsetoffset requested
SearchConfig$config
Returns
int the number of results to fetch from elastic

◆ getLimit()

CirrusSearch\Query\CompSuggestQueryBuilder::getLimit ( )

Number of results we could display.

Returns
int

◆ getMergedProfiles()

CirrusSearch\Query\CompSuggestQueryBuilder::getMergedProfiles ( )

(public for tests)

Returns
array

◆ postProcess()

CirrusSearch\Query\CompSuggestQueryBuilder::postProcess ( CompletionResultsCollector $collector,
ResultSet $results,
$indexName )

Post process the response from elastic to build the SearchSuggestionSet.

Merge top level multi-queries and resolve returned pageIds into Title objects.

Parameters
CompletionResultsCollector$collector
ResultSet$results
string$indexName
Returns
int total hits

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