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

Service to manage and access search profiles. More...

Public Member Functions

 __construct (UserOptionsLookup $userOptionsLookup, ?WebRequest $request=null, ?UserIdentity $user=null)
 
 hasProfile ( $type, $name)
 
 supportsContext ( $type, $context)
 
 loadProfileByName ( $type, $name, $failIfMissing=true)
 Load a profile by its name.
 
 loadProfile ( $type, $context=self::CONTEXT_DEFAULT, $name=null, $contextParams=[])
 Load a profile for the context or by its name if name is provided.
 
 getProfileName ( $type, $context=self::CONTEXT_DEFAULT, array $contextParams=[])
 
 registerRepository (SearchProfileRepository $repository)
 Register a new profile repository.
 
 registerArrayRepository ( $repoType, $repoName, array $profiles)
 Register a new repository backed by a simple array.
 
 registerFileRepository ( $type, $name, $phpFile)
 Register a new repository backed by a PHP file returning an array.
 
 listExposedProfiles ( $type)
 List profiles under type $type that are suited to be exposed to the users.
 
 registerDefaultProfile ( $type, $profileContext, $profileName)
 Register a default profile named $profileName for $type in context $profileContext It must be an existing profile otherwise it will always fail when trying to determine the profile name.
 
 registerProfileOverride ( $type, $profileContext, SearchProfileOverride $override)
 Register a new profile overrider.
 
 registerConfigOverride ( $type, $profileContext, Config $config, $configEntry)
 Register a new overrider using the ConfigSearchProfileOverride implementation.
 
 registerUriParamOverride ( $type, $profileContext, $uriParam)
 
 registerUserPrefOverride ( $type, $profileContext, $userPref)
 
 registerContextualOverride ( $type, $profileContext, $template, array $params)
 
 registerSearchQueryRoute (SearchQueryRoute $route)
 Register a new route to be used by the SearchQueryDispatchService.
 
 registerFTSearchQueryRoute ( $profileContext, $score, array $supportedNamespaces, array $acceptableQueryClasses=[])
 Register a new static route for fulltext search queries.
 
 getDispatchService ()
 Return the service responsible for dispatching a SearchQuery to its preferred profile context.
 
 freeze ()
 Freeze the service, any attempt to declare a new repository will fail.
 
 listProfileTypes ()
 
 listProfileContexts ( $type)
 List default profile per context.
 
 listProfileRepositories ( $type)
 List profile repositories.
 
 listProfileOverrides ( $type, $context)
 L.
 

Public Attributes

const CROSS_PROJECT_BLOCK_SCORER = 'crossproject_block_scorer'
 Profile type for ordering crossproject result blocks.
 
const SIMILARITY = 'similarity'
 Profile type for similarity configuration Used when building the indices.
 
const RESCORE = 'rescore'
 Profile type for rescoring components Used at query when building elastic queries.
 
const RESCORE_FUNCTION_CHAINS = 'rescore_function_chains'
 Profile type used to build function chains Used at query time by rescore builders.
 
const COMPLETION = 'completion'
 Profile type used by the completion suggester.
 
const PHRASE_SUGGESTER = 'phrase_suggester'
 Profile type used by the phrase suggester (fulltext search only)
 
const INDEX_LOOKUP_FALLBACK = 'index_lookup_fallback'
 Profile type used by the index lookup fallback method method.
 
const SANEITIZER = 'saneitizer'
 Profile type used by saneitizer.
 
const DOCUMENT_SIZE_LIMITER = 'document_size_limiter'
 Profile type used by the document size limiter.
 
const FT_QUERY_BUILDER = 'ft_query_builder'
 Profiles used for building fulltext search queries.
 
const FALLBACKS = 'fallbacks'
 Profile type used by FallbackRunner.
 
const CONTEXT_PREFIXSEARCH = 'prefixsearch'
 Profile context used for prefix search queries.
 
const CONTEXT_DEFAULT = 'default'
 Default profile context (used by fulltext queries)
 

Detailed Description

Service to manage and access search profiles.

Search profiles are arranged by type identified by a string constant:

  • COMPLETION: profiles used for autocomplete search when running the completion suggester
  • CROSS_PROJECT_BLOCK_SCORER: used when reordering blocks of crossproject search results
  • FT_QUERY_BUILDER: used when building fulltext search queries
  • PHRASE_SUGGESTER: Controls the behavior of the phrase suggester (did you mean suggestions)
  • INDEX_LOOKUP_FALLBACK: Controls the behavior of the index lookup fallback method (did you mean suggestions)
  • RESCORE: Controls how elasticsearch rescore queries are built
  • RESCORE_FUNCTION_CHAINS: Controls the list of functions used by a rescore profile
  • SANEITIZER: Controls the saneitizer
  • SIMILARITY: Defines similarity profiles used when building the index

Multiple repository per type can be declared, in general we have:

  • the cirrus_base repository holding the default profiles contained in cirrus code
  • the cirrus_config repository holding the profiles customized using $wgCirrusSearch config vars.

The service is bound to a SearchConfig instance which means that the profiles may vary depending on the SearchConfig being used. The cirrus_base repository will always hold the same set of profiles but the cirrus_config may change according to SearchConfig content.

The service is also responsible for determining the name of the default profile for a given context. The profile context is a notion introduced to allow using the same profile for multiple purposes. For example the rescore profiles may be used for different kind of queries (fulltext vs prefixsearch). While they share the same set of profiles we may prefer to use different defaults depending on the type of the query. The profile context allows to distinguish between these use cases.

Then in order to customize the default profile the service allows to define a list of "overriders":

  • ConfigSearchProfileOverride: overrides the default profile by reading a config var
  • UriParamSearchProfileOverride: overrides the default profile by inspecting the URI params
  • UserPrefSearchProfileOverride: overrides the default profile by inspecting the user prefs

Constructor & Destructor Documentation

◆ __construct()

CirrusSearch\Profile\SearchProfileService::__construct ( UserOptionsLookup $userOptionsLookup,
?WebRequest $request = null,
?UserIdentity $user = null )
Parameters
UserOptionsLookup$userOptionsLookup
WebRequest | null$requestobtained from \RequestContext::getMain()->getRequest() if null
UserIdentity | null$userobtained from \RequestContext::getMain()->getUser() if null

Member Function Documentation

◆ getDispatchService()

CirrusSearch\Profile\SearchProfileService::getDispatchService ( )

Return the service responsible for dispatching a SearchQuery to its preferred profile context.

Returns
SearchQueryDispatchService

◆ getProfileName()

CirrusSearch\Profile\SearchProfileService::getProfileName ( $type,
$context = self::CONTEXT_DEFAULT,
array $contextParams = [] )
Parameters
string$typethe type of the profile (see class doc)
string$context
string[]$contextParamsParameters of the context, for determining the profile name. Some overriders use these to decide if an override is appropriate.
Returns
string

◆ hasProfile()

CirrusSearch\Profile\SearchProfileService::hasProfile ( $type,
$name )
Parameters
string$type
string$name
Returns
bool

◆ listExposedProfiles()

CirrusSearch\Profile\SearchProfileService::listExposedProfiles ( $type)

List profiles under type $type that are suited to be exposed to the users.

This method is provided for convenience and to help users to discover existing profile. It's possible that an existing profile may not be listed here so this method must not be used to verify the existence of a given profile. Use hasProfile instead.

Parameters
string$type
Returns
array

◆ listProfileContexts()

CirrusSearch\Profile\SearchProfileService::listProfileContexts ( $type)

List default profile per context.

Parameters
string$type
Returns
string[] context is the key, the default profile name

◆ listProfileOverrides()

CirrusSearch\Profile\SearchProfileService::listProfileOverrides ( $type,
$context )

L.

Parameters
string$type
string$context
Returns
SearchProfileOverride[]

◆ listProfileRepositories()

CirrusSearch\Profile\SearchProfileService::listProfileRepositories ( $type)

List profile repositories.

Parameters
string$type
Returns
SearchProfileRepository[]

◆ listProfileTypes()

CirrusSearch\Profile\SearchProfileService::listProfileTypes ( )
Returns
string[]

◆ loadProfile()

CirrusSearch\Profile\SearchProfileService::loadProfile ( $type,
$context = self::CONTEXT_DEFAULT,
$name = null,
$contextParams = [] )

Load a profile for the context or by its name if name is provided.

Parameters
string$type
string$contextused to determine the name of the profile if $name is not provided
string | null$nameforce the name of the profile to use
string[]$contextParamsParameters of the context, for determining the profile name. Some overriders use these to decide if an override is appropriate.
Returns
array
See also
self::getProfileName()

◆ loadProfileByName()

CirrusSearch\Profile\SearchProfileService::loadProfileByName ( $type,
$name,
$failIfMissing = true )

Load a profile by its name.

It's better to use self::loadProfile and let the service determine the proper profile to use in a given context.

Parameters
string$typethe type of the profile (see class doc)
string$name
bool$failIfMissingwhen true will throw SearchProfileException
Returns
array|null

◆ registerArrayRepository()

CirrusSearch\Profile\SearchProfileService::registerArrayRepository ( $repoType,
$repoName,
array $profiles )

Register a new repository backed by a simple array.

Parameters
string$repoType
string$repoName
array$profiles

◆ registerConfigOverride()

CirrusSearch\Profile\SearchProfileService::registerConfigOverride ( $type,
$profileContext,
Config $config,
$configEntry )

Register a new overrider using the ConfigSearchProfileOverride implementation.

Parameters
string$type
string | string[]$profileContextone or multiple contexts
Config$config
string$configEntry
See also
ConfigSearchProfileOverride

◆ registerContextualOverride()

CirrusSearch\Profile\SearchProfileService::registerContextualOverride ( $type,
$profileContext,
$template,
array $params )
Parameters
string$type
string | string[]$profileContextone or multiple contexts
string$templateA templated profile name
string[]$paramsMap from string in $template to context parameter to replace with. All params must be available in the context parameters or no override will be applied.

◆ registerDefaultProfile()

CirrusSearch\Profile\SearchProfileService::registerDefaultProfile ( $type,
$profileContext,
$profileName )

Register a default profile named $profileName for $type in context $profileContext It must be an existing profile otherwise it will always fail when trying to determine the profile name.

Parameters
string$type
string$profileContext
string$profileName

◆ registerFileRepository()

CirrusSearch\Profile\SearchProfileService::registerFileRepository ( $type,
$name,
$phpFile )

Register a new repository backed by a PHP file returning an array.

NOTE: $phpFile is loaded with PHP's require keyword.

Parameters
string$type
string$name
string$phpFile
See also
FileProfileRepository

◆ registerFTSearchQueryRoute()

CirrusSearch\Profile\SearchProfileService::registerFTSearchQueryRoute ( $profileContext,
$score,
array $supportedNamespaces,
array $acceptableQueryClasses = [] )

Register a new static route for fulltext search queries.

Parameters
string$profileContext
float$scorescore of the route
int[]$supportedNamespaces
string[]$acceptableQueryClasses
See also
SearchProfileService::getDispatchService()
SearchQueryDispatchService::CIRRUS_DEFAULTS_SCORE

◆ registerProfileOverride()

CirrusSearch\Profile\SearchProfileService::registerProfileOverride ( $type,
$profileContext,
SearchProfileOverride $override )

Register a new profile overrider.

It allows to override the default profile based on the implementation of SearchProfileOverride.

Parameters
string$type
string | string[]$profileContextone or multiple contexts
SearchProfileOverride$override

◆ registerRepository()

CirrusSearch\Profile\SearchProfileService::registerRepository ( SearchProfileRepository $repository)

Register a new profile repository.

Parameters
SearchProfileRepository$repository

◆ registerSearchQueryRoute()

CirrusSearch\Profile\SearchProfileService::registerSearchQueryRoute ( SearchQueryRoute $route)

Register a new route to be used by the SearchQueryDispatchService.

Parameters
SearchQueryRoute$route
See also
SearchQueryDispatchService
SearchProfileService::getDispatchService()

◆ registerUriParamOverride()

CirrusSearch\Profile\SearchProfileService::registerUriParamOverride ( $type,
$profileContext,
$uriParam )
Parameters
string$type
string | string[]$profileContextone or multiple contexts
string$uriParam

◆ registerUserPrefOverride()

CirrusSearch\Profile\SearchProfileService::registerUserPrefOverride ( $type,
$profileContext,
$userPref )
Parameters
string$type
string | string[]$profileContextone or multiple contexts
string$userPrefthe name of the key used to store this user preference

◆ supportsContext()

CirrusSearch\Profile\SearchProfileService::supportsContext ( $type,
$context )
Parameters
string$type
string$context
Returns
bool

Member Data Documentation

◆ COMPLETION

const CirrusSearch\Profile\SearchProfileService::COMPLETION = 'completion'

Profile type used by the completion suggester.

See also
\CirrusSearch\CompletionSuggester

◆ DOCUMENT_SIZE_LIMITER

const CirrusSearch\Profile\SearchProfileService::DOCUMENT_SIZE_LIMITER = 'document_size_limiter'

Profile type used by the document size limiter.

See also
DocumentSizeLimiter

◆ FALLBACKS

const CirrusSearch\Profile\SearchProfileService::FALLBACKS = 'fallbacks'

Profile type used by FallbackRunner.

See also
\CirrusSearch\Fallbacks\FallbackRunner::create()

◆ FT_QUERY_BUILDER

const CirrusSearch\Profile\SearchProfileService::FT_QUERY_BUILDER = 'ft_query_builder'

Profiles used for building fulltext search queries.

See also
\CirrusSearch\Search\SearchContext::getFulltextQueryBuilderProfile()

◆ INDEX_LOOKUP_FALLBACK

const CirrusSearch\Profile\SearchProfileService::INDEX_LOOKUP_FALLBACK = 'index_lookup_fallback'

Profile type used by the index lookup fallback method method.

See also
\CirrusSearch\Fallbacks\IndexLookupFallbackMethod

◆ PHRASE_SUGGESTER

const CirrusSearch\Profile\SearchProfileService::PHRASE_SUGGESTER = 'phrase_suggester'

Profile type used by the phrase suggester (fulltext search only)

See also
\CirrusSearch\Fallbacks\PhraseSuggestFallbackMethod

◆ RESCORE

const CirrusSearch\Profile\SearchProfileService::RESCORE = 'rescore'

Profile type for rescoring components Used at query when building elastic queries.

See also
\CirrusSearch\Search\Rescore\RescoreBuilder

◆ RESCORE_FUNCTION_CHAINS

const CirrusSearch\Profile\SearchProfileService::RESCORE_FUNCTION_CHAINS = 'rescore_function_chains'

Profile type used to build function chains Used at query time by rescore builders.

See also
\CirrusSearch\Search\Rescore\RescoreBuilder

◆ SANEITIZER

const CirrusSearch\Profile\SearchProfileService::SANEITIZER = 'saneitizer'

Profile type used by saneitizer.

See also
\CirrusSearch\Maintenance\SaneitizeJobs

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