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

The search context, maintains the state of the current search query. More...

+ Inheritance diagram for CirrusSearch\Search\SearchContext:
+ Collaboration diagram for CirrusSearch\Search\SearchContext:

Public Member Functions

 __construct (SearchConfig $config, array $namespaces=null, CirrusDebugOptions $options=null, FallbackRunner $fallbackRunner=null, FetchPhaseConfigBuilder $fetchPhaseConfigBuilder=null, CirrusSearchHookRunner $cirrusSearchHookRunner=null)
 
 withConfig (SearchConfig $config)
 Return a copy of this context with a new configuration.
 
 __clone ()
 
 isDirty ()
 Have custom options that effect the search results been set outside the defaults from config?
 
 getConfig ()
 
 getNamespaces ()
 mediawiki namespace id's being requested.
 
 setNamespaces ( $namespaces)
 set the mediawiki namespace id's
 
 getProfileContext ()
 
 getProfileContextParams ()
 
 setProfileContext ( $profileContext, array $contextParams=[])
 
 getRescoreProfile ()
 
 setRescoreProfile ( $rescoreProfile)
 
 areResultsPossible ()
 
 setResultsPossible ( $possible)
 
 isSyntaxUsed ( $type=null)
 
 isSpecialKeywordUsed ()
 
 getSyntaxUsed ()
 
 getSyntaxDescription ()
 
 addSyntaxUsed ( $feature, $weight=null)
 
 getSearchType ()
 
 addFilter (AbstractQuery $filter)
 
 addNotFilter (AbstractQuery $filter)
 
 setHighlightQuery (AbstractQuery $query=null)
 
 addNonTextHighlightQuery (AbstractQuery $query)
 
 getFetchPhaseBuilder ()
 
 getHighlight (ResultsType $resultsType, AbstractQuery $mainQuery)
 
 getRescore ()
 rescore_query has to be in array form before we send it to Elasticsearch but it is way easier to work with if we leave it in query form until now
 
 getQuery ()
 
 setMainQuery (AbstractQuery $query)
 
 addNonTextQuery (\Elastica\Query\AbstractQuery $match)
 
 getSearchQuery ()
 
 getLimitSearchToLocalWiki ()
 
 setLimitSearchToLocalWiki ( $localWikiOnly)
 
 getCacheTtl ()
 
 setCacheTtl ( $ttl)
 
 getOriginalSearchTerm ()
 
 setOriginalSearchTerm ( $term)
 
 getCleanedSearchTerm ()
 
 setCleanedSearchTerm ( $term)
 
 escaper ()
 
 getExtraScoreBuilders ()
 
 addCustomRescoreComponent (BoostFunctionBuilder $rescore)
 Add custom scoring function to the context.
 
 addWarning ( $message,... $params)
 
 getWarnings ()
 
 getFulltextQueryBuilderProfile ()
 
 setFulltextQueryBuilderProfile ( $profile)
 
 setResultsType ( $resultsType)
 
 getResultsType ()
 
 getExtraIndices ()
 Get the list of extra indices to query.
 
 getPhraseRescoreQuery ()
 Get the phrase rescore query if available.
 
 setPhraseRescoreQuery ( $phraseRescoreQuery)
 
 addAggregation (AbstractAggregation $agg)
 Add aggregation to perform on search.
 
 getAggregations ()
 Get the list of aggregations.
 
 getDebugOptions ()
 
 getFilters ()
 NOTE: public for testing purposes.
 
 must (AbstractQuery $query)
 
 mustNot (AbstractQuery $query)
 
 getFallbackRunner ()
 
 setTrackTotalHits (bool $trackTotalHits)
 
 getTrackTotalHits ()
 

Static Public Member Functions

static fromSearchQuery (SearchQuery $query, FallbackRunner $fallbackRunner=null, CirrusSearchHookRunner $cirrusSearchHookRunner=null)
 Builds a SearchContext based on a SearchQuery.
 

Detailed Description

The search context, maintains the state of the current search query.

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 The SearchContext stores the various states maintained during the query building process.

Constructor & Destructor Documentation

◆ __construct()

CirrusSearch\Search\SearchContext::__construct ( SearchConfig $config,
array $namespaces = null,
CirrusDebugOptions $options = null,
FallbackRunner $fallbackRunner = null,
FetchPhaseConfigBuilder $fetchPhaseConfigBuilder = null,
CirrusSearchHookRunner $cirrusSearchHookRunner = null )
Parameters
SearchConfig$config
int[] | null$namespaces
CirrusDebugOptions | null$options
FallbackRunner | null$fallbackRunner
FetchPhaseConfigBuilder | null$fetchPhaseConfigBuilder
CirrusSearchHookRunner | null$cirrusSearchHookRunner

Member Function Documentation

◆ addAggregation()

CirrusSearch\Search\SearchContext::addAggregation ( AbstractAggregation $agg)

Add aggregation to perform on search.

Parameters
AbstractAggregation$agg

◆ addCustomRescoreComponent()

CirrusSearch\Search\SearchContext::addCustomRescoreComponent ( BoostFunctionBuilder $rescore)

Add custom scoring function to the context.

The rescore builder will pick it up.

Parameters
BoostFunctionBuilder$rescore

◆ addFilter()

CirrusSearch\Search\SearchContext::addFilter ( AbstractQuery $filter)
Parameters
AbstractQuery$filterQuery results must match this filter

◆ addNonTextHighlightQuery()

CirrusSearch\Search\SearchContext::addNonTextHighlightQuery ( AbstractQuery $query)
Parameters
AbstractQuery$queryqueries that don't use Elastic's "query string" query, for more advanced highlighting (e.g. match_phrase_prefix for regular quoted strings).

◆ addNonTextQuery()

CirrusSearch\Search\SearchContext::addNonTextQuery ( \Elastica\Query\AbstractQuery $match)
Parameters
\Elastica\Query\AbstractQuery$matchQueries that don't use Elastic's "query string" query, for more advanced searching (e.g. match_phrase_prefix for regular quoted strings).

◆ addNotFilter()

CirrusSearch\Search\SearchContext::addNotFilter ( AbstractQuery $filter)
Parameters
AbstractQuery$filterQuery results must not match this filter

◆ addSyntaxUsed()

CirrusSearch\Search\SearchContext::addSyntaxUsed ( $feature,
$weight = null )
Parameters
string$featureName of a syntax feature used in the query string
int | null$weightHow "complex" is this feature.

◆ addWarning()

CirrusSearch\Search\SearchContext::addWarning ( $message,
$params )
Parameters
string$messagei18n message key
mixed...$params

Implements CirrusSearch\WarningCollector.

◆ areResultsPossible()

CirrusSearch\Search\SearchContext::areResultsPossible ( )
Returns
bool Could this query possibly return results?

◆ escaper()

CirrusSearch\Search\SearchContext::escaper ( )
Returns
Escaper

◆ fromSearchQuery()

static CirrusSearch\Search\SearchContext::fromSearchQuery ( SearchQuery $query,
FallbackRunner $fallbackRunner = null,
CirrusSearchHookRunner $cirrusSearchHookRunner = null )
static

Builds a SearchContext based on a SearchQuery.

Helper function used for building blocks that still work on top of the SearchContext+queryString instead of SearchQuery.

States initialized:

  • limitSearchToLocalWiki

suggestion

  • custom rescoreProfile/fulltextQueryBuilderProfile
  • contextual filters: (eg. SearchEngine::$prefix)
  • SuggestPrefix (DYM prefix: ~ and/or namespace header)
Parameters
SearchQuery$query
FallbackRunner | null$fallbackRunner
CirrusSearchHookRunner | null$cirrusSearchHookRunner
Returns
SearchContext
Exceptions

CirrusSearch\Parser\ParsedQueryClassifierException

◆ getAggregations()

CirrusSearch\Search\SearchContext::getAggregations ( )

Get the list of aggregations.

Returns
AbstractAggregation[]

◆ getCacheTtl()

CirrusSearch\Search\SearchContext::getCacheTtl ( )
Returns
int The number of seconds to cache results for

◆ getCleanedSearchTerm()

CirrusSearch\Search\SearchContext::getCleanedSearchTerm ( )
Returns
string The search term with keywords removed

◆ getConfig()

CirrusSearch\Search\SearchContext::getConfig ( )
Returns
SearchConfig the Cirrus config object

◆ getDebugOptions()

CirrusSearch\Search\SearchContext::getDebugOptions ( )
Returns
CirrusDebugOptions

◆ getExtraIndices()

CirrusSearch\Search\SearchContext::getExtraIndices ( )

Get the list of extra indices to query.

Generally needed to query externilized file index. Must be called only once the list of namespaces has been set.

Returns
ExternalIndex[]
See also
OtherIndexesUpdater::getExtraIndexesForNamespaces()

◆ getExtraScoreBuilders()

CirrusSearch\Search\SearchContext::getExtraScoreBuilders ( )
Returns
BoostFunctionBuilder[]

◆ getFallbackRunner()

CirrusSearch\Search\SearchContext::getFallbackRunner ( )
Returns
FallbackRunner

◆ getFetchPhaseBuilder()

CirrusSearch\Search\SearchContext::getFetchPhaseBuilder ( )
Returns
FetchPhaseConfigBuilder

◆ getFilters()

CirrusSearch\Search\SearchContext::getFilters ( )

NOTE: public for testing purposes.

Returns
AbstractQuery[]

◆ getFulltextQueryBuilderProfile()

CirrusSearch\Search\SearchContext::getFulltextQueryBuilderProfile ( )
Returns
string the name of the fulltext query builder profile

◆ getHighlight()

CirrusSearch\Search\SearchContext::getHighlight ( ResultsType $resultsType,
AbstractQuery $mainQuery )
Parameters
ResultsType$resultsType
AbstractQuery$mainQueryWill be combined with highlighting query to provide highlightable terms.
Returns
array|null Fetch portion of query to be sent to elasticsearch

◆ getLimitSearchToLocalWiki()

CirrusSearch\Search\SearchContext::getLimitSearchToLocalWiki ( )
Returns
bool Should this search limit results to the local wiki? If not called the default is false.

◆ getNamespaces()

CirrusSearch\Search\SearchContext::getNamespaces ( )

mediawiki namespace id's being requested.

NOTE: this value may change during the Searcher process.

Returns
int[]|null

◆ getOriginalSearchTerm()

CirrusSearch\Search\SearchContext::getOriginalSearchTerm ( )
Returns
string the original search term

◆ getPhraseRescoreQuery()

CirrusSearch\Search\SearchContext::getPhraseRescoreQuery ( )

Get the phrase rescore query if available.

Returns
AbstractQuery|null

◆ getProfileContext()

CirrusSearch\Search\SearchContext::getProfileContext ( )
Returns
string

◆ getProfileContextParams()

CirrusSearch\Search\SearchContext::getProfileContextParams ( )
Returns
string[]

◆ getQuery()

CirrusSearch\Search\SearchContext::getQuery ( )
Returns
AbstractQuery The primary query to be sent to elasticsearch. Includes the main quedry, non text queries, and any additional filters.

◆ getRescore()

CirrusSearch\Search\SearchContext::getRescore ( )

rescore_query has to be in array form before we send it to Elasticsearch but it is way easier to work with if we leave it in query form until now

Returns
array[] Rescore configurations as used by elasticsearch.

◆ getRescoreProfile()

CirrusSearch\Search\SearchContext::getRescoreProfile ( )
Returns
string the rescore profile to use

◆ getResultsType()

CirrusSearch\Search\SearchContext::getResultsType ( )
Returns
ResultsType

◆ getSearchQuery()

CirrusSearch\Search\SearchContext::getSearchQuery ( )
Returns
SearchQuery

◆ getSearchType()

CirrusSearch\Search\SearchContext::getSearchType ( )
Returns
string The type of search being performed, ex: full_text, near_match, prefix, etc. Using getSyntaxUsed() is better in most cases.

◆ getSyntaxDescription()

CirrusSearch\Search\SearchContext::getSyntaxDescription ( )
Returns
string Text description of syntax used by query.

◆ getSyntaxUsed()

CirrusSearch\Search\SearchContext::getSyntaxUsed ( )
Returns
string[] List of syntax used in the query

◆ getWarnings()

CirrusSearch\Search\SearchContext::getWarnings ( )
Returns
array[] Array of arrays. Each sub array is a set of values suitable for creating an i18n message. @phan-return non-empty-array[]

◆ isDirty()

CirrusSearch\Search\SearchContext::isDirty ( )

Have custom options that effect the search results been set outside the defaults from config?

Returns
bool

◆ isSpecialKeywordUsed()

CirrusSearch\Search\SearchContext::isSpecialKeywordUsed ( )
Returns
bool true if a special keyword or syntax was used in the query

◆ isSyntaxUsed()

CirrusSearch\Search\SearchContext::isSyntaxUsed ( $type = null)
Parameters
string | null$typetype of syntax to check, null for any type
Returns
bool True when the query uses $type kind of syntax

◆ must()

CirrusSearch\Search\SearchContext::must ( AbstractQuery $query)
Parameters
AbstractQuery$query

Implements CirrusSearch\Query\Builder\FilterBuilder.

◆ mustNot()

CirrusSearch\Search\SearchContext::mustNot ( AbstractQuery $query)
Parameters
AbstractQuery$query

Implements CirrusSearch\Query\Builder\FilterBuilder.

◆ setCacheTtl()

CirrusSearch\Search\SearchContext::setCacheTtl ( $ttl)
Parameters
int$ttlThe number of seconds to cache results for

◆ setCleanedSearchTerm()

CirrusSearch\Search\SearchContext::setCleanedSearchTerm ( $term)
Parameters
string$termThe search term with keywords removed

◆ setFulltextQueryBuilderProfile()

CirrusSearch\Search\SearchContext::setFulltextQueryBuilderProfile ( $profile)
Parameters
string$profileset the name of the fulltext query builder profile

◆ setHighlightQuery()

CirrusSearch\Search\SearchContext::setHighlightQuery ( AbstractQuery $query = null)
Parameters
AbstractQuery | null$queryQuery that should be used for highlighting if different from the query used for selecting.

◆ setLimitSearchToLocalWiki()

CirrusSearch\Search\SearchContext::setLimitSearchToLocalWiki ( $localWikiOnly)
Parameters
bool$localWikiOnlyShould this search limit results to the local wiki? If not called the default is false.

◆ setMainQuery()

CirrusSearch\Search\SearchContext::setMainQuery ( AbstractQuery $query)
Parameters
AbstractQuery$queryThe primary query to be passed to elasticsearch.

◆ setNamespaces()

CirrusSearch\Search\SearchContext::setNamespaces ( $namespaces)

set the mediawiki namespace id's

Parameters
int[] | null$namespacesarray of integer

◆ setOriginalSearchTerm()

CirrusSearch\Search\SearchContext::setOriginalSearchTerm ( $term)
Parameters
string$term

◆ setPhraseRescoreQuery()

CirrusSearch\Search\SearchContext::setPhraseRescoreQuery ( $phraseRescoreQuery)
Parameters
AbstractQuery | null$phraseRescoreQuery

◆ setProfileContext()

CirrusSearch\Search\SearchContext::setProfileContext ( $profileContext,
array $contextParams = [] )
Parameters
string$profileContext
string[]$contextParams

◆ setRescoreProfile()

CirrusSearch\Search\SearchContext::setRescoreProfile ( $rescoreProfile)
Parameters
string$rescoreProfilethe rescore profile to use

◆ setResultsPossible()

CirrusSearch\Search\SearchContext::setResultsPossible ( $possible)
Parameters
bool$possibleCould this query possible return results? Defaults to true if not called.

◆ setResultsType()

CirrusSearch\Search\SearchContext::setResultsType ( $resultsType)
Parameters
ResultsType$resultsTyperesults type to return

◆ withConfig()

CirrusSearch\Search\SearchContext::withConfig ( SearchConfig $config)

Return a copy of this context with a new configuration.

Parameters
SearchConfig$configThe new configuration
Returns
SearchContext

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