MediaWiki master
MediaWiki\Search\SearchEngine Class Reference

Contain a class for special pages. More...

Inherited by MediaWiki\Search\SearchDatabase, and MediaWiki\Search\SearchEngineDummy.

Public Member Functions

 augmentSearchResults (ISearchResultSet $resultSet)
 Augment search results with extra data.
 
 completionSearch ( $search)
 Perform a completion search.
 
 completionSearchWithVariants ( $search)
 Perform a completion search with variants.
 
 defaultPrefixSearch ( $search)
 Simple prefix search for subpages.
 
 delete ( $id, $title)
 Delete an indexed page Title should be pre-processed.
 
 extractTitles (SearchSuggestionSet $completionResults)
 Extract titles from completion results.
 
 getFeatureData ( $feature)
 Way to retrieve custom data set by setFeatureData or by the engine itself.
 
 getNearMatcher (Config $config)
 Get service class to finding near matches.
 
 getProfiles ( $profileType, ?User $user=null)
 Get a list of supported profiles.
 
 getSearchIndexFields ()
 Get fields for search index.
 
 getSort ()
 Get the sort direction of the search results.
 
 getValidSorts ()
 Get the valid sort directions.
 
 legalSearchChars ( $type=self::CHARS_ALL)
 Get chars legal for search.
 
 makeSearchFieldMapping ( $name, $type)
 Create a search field definition.
 
 normalizeText ( $string)
 When overridden in derived class, performs database-specific conversions on text to be used for searching or updating search index.
 
 searchArchiveTitle ( $term)
 Perform a title search in the article archive.
 
 searchText ( $term)
 Perform a full text search query and return a result set.
 
 searchTitle ( $term)
 Perform a title-only search query and return a result set.
 
 setFeatureData ( $feature, $data)
 Way to pass custom data for engines.
 
 setHookContainer (HookContainer $hookContainer)
 
 setLimitOffset ( $limit, $offset=0)
 Set the maximum number of results to return and how many to skip before returning the first.
 
 setNamespaces ( $namespaces)
 Set which namespaces the search should include.
 
 setShowSuggestion ( $showSuggestion)
 Set whether the searcher should try to build a suggestion.
 
 setSort ( $sort)
 Set the sort direction of the search results.
 
 supports ( $feature)
 
 update ( $id, $title, $text)
 Create or update the search index record for the given page.
 
 updateTitle ( $id, $title)
 Update a search index record's title only.
 

Static Public Member Functions

static parseNamespacePrefixes ( $query, $withAllKeyword=true, $withPrefixSearchExtractNamespaceHook=false)
 Parse some common prefixes: all (search everything) or namespace names.
 
static userHighlightPrefs ()
 Find snippet highlight settings for all users.
 

Public Attributes

int[] null $namespaces = [ NS_MAIN ]
 
string $prefix = ''
 
const COMPLETION_PROFILE_TYPE = 'completionSearchProfile'
 Profile type for completionSearch.
 
const DEFAULT_SORT = 'relevance'
 
const FT_QUERY_DEP_PROFILE_TYPE = 'fulltextQueryDepProfile'
 Profile type for query dependent ranking features (ex: field weights)
 
const FT_QUERY_INDEP_PROFILE_TYPE = 'fulltextQueryIndepProfile'
 Profile type for query independent ranking features (ex: article popularity)
 

Protected Member Functions

 completionSearchBackend ( $search)
 Perform a completion search.
 
 completionSearchBackendOverfetch ( $search)
 Perform an overfetch of completion search results.
 
 doSearchArchiveTitle ( $term)
 Perform a title search in the article archive.
 
 doSearchText ( $term)
 Perform a full text search query and return a result set.
 
 doSearchTitle ( $term)
 Perform a title-only search query and return a result set.
 
 getHookContainer ()
 Get a HookContainer, for running extension hooks or for hook metadata.
 
 getHookRunner ()
 Get a HookRunner for running core hooks.
 
 normalizeNamespaces ( $search)
 Makes search simple string if it was namespaced.
 
 processCompletionResults ( $search, SearchSuggestionSet $suggestions)
 Process completion search results.
 
 simplePrefixSearch ( $search)
 Call out to simple search backend.
 

Static Protected Member Functions

static defaultNearMatcher ()
 Get near matcher for default SearchEngine.
 

Protected Attributes

array $features = []
 Feature values.
 
int $limit = 10
 
int $offset = 0
 
string[] $searchTerms = []
 
bool $showSuggestion = true
 
const CHARS_ALL = 1
 Integer flag for legalSearchChars: includes all chars allowed in a search query.
 
const CHARS_NO_SYNTAX = 2
 Integer flag for legalSearchChars: includes all chars allowed in a search term.
 

Detailed Description

Contain a class for special pages.

Stability: stable
to extend

Definition at line 33 of file SearchEngine.php.

Member Function Documentation

◆ augmentSearchResults()

MediaWiki\Search\SearchEngine::augmentSearchResults ( ISearchResultSet $resultSet)

Augment search results with extra data.

Definition at line 801 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\getHookRunner(), and MediaWiki\Search\ISearchResultSet\setAugmentedData().

◆ completionSearch()

MediaWiki\Search\SearchEngine::completionSearch ( $search)

◆ completionSearchBackend()

MediaWiki\Search\SearchEngine::completionSearchBackend ( $search)
protected

Perform a completion search.

Does not resolve namespaces and does not check variants. Search engine implementations may want to override this function.

Stability: stable
to override
Parameters
string$search
Returns
SearchSuggestionSet

Definition at line 529 of file SearchEngine.php.

References MediaWiki\Search\SearchSuggestionSet\fromStrings(), MediaWiki\Search\SearchSuggestionSet\fromTitles(), MediaWiki\Search\SearchEngine\getHookRunner(), NS_SPECIAL, and MediaWiki\Search\SearchEngine\simplePrefixSearch().

Referenced by MediaWiki\Search\SearchEngine\completionSearchBackendOverfetch().

◆ completionSearchBackendOverfetch()

MediaWiki\Search\SearchEngine::completionSearchBackendOverfetch ( $search)
protected

Perform an overfetch of completion search results.

This allows determining if another page of results is available.

Parameters
string$search
Returns
SearchSuggestionSet

Definition at line 510 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\completionSearchBackend().

Referenced by MediaWiki\Search\SearchEngine\completionSearch(), and MediaWiki\Search\SearchEngine\completionSearchWithVariants().

◆ completionSearchWithVariants()

◆ defaultNearMatcher()

static MediaWiki\Search\SearchEngine::defaultNearMatcher ( )
staticprotected

Get near matcher for default SearchEngine.

Returns
TitleMatcher
Deprecated
since 1.40, MediaWikiServices::getInstance()->getTitleMatcher()

Definition at line 274 of file SearchEngine.php.

References MediaWiki\MediaWikiServices\getInstance(), and wfDeprecated().

◆ defaultPrefixSearch()

MediaWiki\Search\SearchEngine::defaultPrefixSearch ( $search)

Simple prefix search for subpages.

Parameters
string$search
Returns
Title[]

Definition at line 698 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\normalizeNamespaces(), and MediaWiki\Search\SearchEngine\simplePrefixSearch().

◆ delete()

MediaWiki\Search\SearchEngine::delete ( $id,
$title )

Delete an indexed page Title should be pre-processed.

STUB

Parameters
int$idPage id that was deleted
string$titleTitle of page that was deleted

Reimplemented in MediaWiki\Search\SearchMySQL.

Definition at line 484 of file SearchEngine.php.

◆ doSearchArchiveTitle()

MediaWiki\Search\SearchEngine::doSearchArchiveTitle ( $term)
protected

Perform a title search in the article archive.

Stability: stable
to override
Parameters
string$termRaw search term
Returns
Status
Since
1.32

Definition at line 139 of file SearchEngine.php.

Referenced by MediaWiki\Search\SearchEngine\searchArchiveTitle().

◆ doSearchText()

MediaWiki\Search\SearchEngine::doSearchText ( $term)
protected

Perform a full text search query and return a result set.

Stability: stable
to override
Parameters
string$termRaw search term
Returns
ISearchResultSet|Status<ISearchResultSet>|null
Since
1.32

Reimplemented in MediaWiki\Search\SearchDatabase.

Definition at line 108 of file SearchEngine.php.

Referenced by MediaWiki\Search\SearchEngine\searchText().

◆ doSearchTitle()

MediaWiki\Search\SearchEngine::doSearchTitle ( $term)
protected

Perform a title-only search query and return a result set.

Stability: stable
to override
Parameters
string$termRaw search term
Returns
ISearchResultSet|null
Since
1.32

Reimplemented in MediaWiki\Search\SearchDatabase.

Definition at line 169 of file SearchEngine.php.

Referenced by MediaWiki\Search\SearchEngine\searchTitle().

◆ extractTitles()

MediaWiki\Search\SearchEngine::extractTitles ( SearchSuggestionSet $completionResults)

Extract titles from completion results.

Parameters
SearchSuggestionSet$completionResults
Returns
Title[]

Definition at line 609 of file SearchEngine.php.

References MediaWiki\Search\SearchSuggestion\getSuggestedTitle(), and MediaWiki\Search\SearchSuggestionSet\map().

◆ getFeatureData()

MediaWiki\Search\SearchEngine::getFeatureData ( $feature)

Way to retrieve custom data set by setFeatureData or by the engine itself.

Since
1.29
Parameters
string$featurefeature name
Returns
mixed the feature value or null if unset

Definition at line 241 of file SearchEngine.php.

◆ getHookContainer()

MediaWiki\Search\SearchEngine::getHookContainer ( )
protected

Get a HookContainer, for running extension hooks or for hook metadata.

Since
1.35
Returns
HookContainer

Definition at line 846 of file SearchEngine.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ getHookRunner()

MediaWiki\Search\SearchEngine::getHookRunner ( )
protected

Get a HookRunner for running core hooks.

Access: internal
This is for use by core only. Hook interfaces may be removed without notice.
Since
1.35
Returns
HookRunner

Definition at line 864 of file SearchEngine.php.

Referenced by MediaWiki\Search\SearchEngine\augmentSearchResults(), MediaWiki\Search\SearchEngine\completionSearchBackend(), and MediaWiki\Search\SearchEngine\getSearchIndexFields().

◆ getNearMatcher()

MediaWiki\Search\SearchEngine::getNearMatcher ( Config $config)

Get service class to finding near matches.

Returns
TitleMatcher
Deprecated
since 1.40, use MediaWikiServices::getInstance()->getTitleMatcher()

Definition at line 264 of file SearchEngine.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ getProfiles()

MediaWiki\Search\SearchEngine::getProfiles ( $profileType,
?User $user = null )

Get a list of supported profiles.

Some search engine implementations may expose specific profiles to fine-tune its behaviors. The profile can be passed as a feature data with setFeatureData( $profileType, $profileName ) The array returned by this function contains the following keys:

  • name: the profile name to use with setFeatureData
  • desc-message: the i18n description
  • default: set to true if this profile is the default
Since
1.28
Stability: stable
to override
Parameters
string$profileTypethe type of profiles
User | null$userthe user requesting the list of profiles
Returns
array|null the list of profiles or null if none available

Definition at line 737 of file SearchEngine.php.

◆ getSearchIndexFields()

MediaWiki\Search\SearchEngine::getSearchIndexFields ( )

Get fields for search index.

Since
1.28
Returns
SearchIndexField[] Index field definitions for all content handlers

Definition at line 760 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\getHookRunner(), and MediaWiki\MediaWikiServices\getInstance().

◆ getSort()

MediaWiki\Search\SearchEngine::getSort ( )

Get the sort direction of the search results.

Since
1.25
Returns
string

Definition at line 365 of file SearchEngine.php.

◆ getValidSorts()

MediaWiki\Search\SearchEngine::getValidSorts ( )

Get the valid sort directions.

All search engines support 'relevance' but others might support more. The default in all implementations must be 'relevance.'

Since
1.25
Stability: stable
to override
Returns
string[] the valid sort directions for setSort

Definition at line 340 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\DEFAULT_SORT.

Referenced by MediaWiki\Search\SearchEngine\setSort().

◆ legalSearchChars()

MediaWiki\Search\SearchEngine::legalSearchChars ( $type = self::CHARS_ALL)

Get chars legal for search.

Parameters
int$typetype of search chars (see self::CHARS_ALL and self::CHARS_NO_SYNTAX). Defaults to CHARS_ALL
Returns
string

Reimplemented in MediaWiki\Search\SearchMySQL, and MediaWiki\Search\SearchSqlite.

Definition at line 285 of file SearchEngine.php.

Referenced by MediaWiki\Search\SearchDatabase\filter().

◆ makeSearchFieldMapping()

MediaWiki\Search\SearchEngine::makeSearchFieldMapping ( $name,
$type )

Create a search field definition.

Specific search engines should override this method to create search fields.

Stability: stable
to override
Parameters
string$name
string$typeOne of the types in SearchIndexField::INDEX_TYPE_*
Returns
SearchIndexField
Since
1.28

Definition at line 751 of file SearchEngine.php.

Referenced by MediaWiki\Content\ContentHandler\addSearchField(), MediaWiki\Content\ContentHandler\getFieldsForSearchIndex(), MediaWiki\Content\FileContentHandler\getFieldsForSearchIndex(), MediaWiki\Content\TextContentHandler\getFieldsForSearchIndex(), and MediaWiki\Content\WikitextContentHandler\getFieldsForSearchIndex().

◆ normalizeNamespaces()

MediaWiki\Search\SearchEngine::normalizeNamespaces ( $search)
protected

Makes search simple string if it was namespaced.

Sets namespaces of the search to namespaces extracted from string.

Parameters
string$search
Returns
string Simplified search string

Definition at line 494 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\parseNamespacePrefixes(), and MediaWiki\Search\SearchEngine\setNamespaces().

Referenced by MediaWiki\Search\SearchEngine\completionSearch(), MediaWiki\Search\SearchEngine\completionSearchWithVariants(), and MediaWiki\Search\SearchEngine\defaultPrefixSearch().

◆ normalizeText()

MediaWiki\Search\SearchEngine::normalizeText ( $string)

When overridden in derived class, performs database-specific conversions on text to be used for searching or updating search index.

Default implementation does nothing (simply returns $string).

Parameters
string$stringString to process
Returns
string

Reimplemented in MediaWiki\Search\SearchMySQL.

Definition at line 253 of file SearchEngine.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ parseNamespacePrefixes()

static MediaWiki\Search\SearchEngine::parseNamespacePrefixes ( $query,
$withAllKeyword = true,
$withPrefixSearchExtractNamespaceHook = false )
static

Parse some common prefixes: all (search everything) or namespace names.

Parameters
string$query
bool$withAllKeywordactivate support of the "all:" keyword and its translations to activate searching on all namespaces.
bool$withPrefixSearchExtractNamespaceHookcall the PrefixSearchExtractNamespace hook if classic namespace identification did not match.
Returns
false|array false if no namespace was extracted, an array with the parsed query at index 0 and an array of namespaces at index 1 (or null for all namespaces).

Definition at line 382 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\$prefix, MediaWiki\MediaWikiServices\getInstance(), NS_MAIN, and wfMessage().

Referenced by MediaWiki\Search\SearchDatabase\extractNamespacePrefix(), MediaWiki\Search\SearchEngine\normalizeNamespaces(), and MediaWiki\Search\PrefixSearch\search().

◆ processCompletionResults()

◆ searchArchiveTitle()

MediaWiki\Search\SearchEngine::searchArchiveTitle ( $term)

Perform a title search in the article archive.

NOTE: these results still should be filtered by matching against PageArchive, permissions checks etc The results returned by this methods are only suggestions and may not end up being shown to the user.

Note
As of 1.32 overriding this function is deprecated. It will be converted to final in 1.34. Override self::doSearchArchiveTitle().
Parameters
string$termRaw search term
Returns
Status
Since
1.29

Definition at line 126 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\doSearchArchiveTitle().

◆ searchText()

MediaWiki\Search\SearchEngine::searchText ( $term)

Perform a full text search query and return a result set.

If full text searches are not supported or disabled, return null.

Note
As of 1.32 overriding this function is deprecated. It will be converted to final in 1.34. Override self::doSearchText().
Parameters
string$termRaw search term
Returns
ISearchResultSet|Status<ISearchResultSet>|null

Definition at line 93 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\doSearchText().

◆ searchTitle()

MediaWiki\Search\SearchEngine::searchTitle ( $term)

Perform a title-only search query and return a result set.

If title searches are not supported or disabled, return null. STUB

Note
As of 1.32 overriding this function is deprecated. It will be converted to final in 1.34. Override self::doSearchTitle().
Parameters
string$termRaw search term
Returns
ISearchResultSet|null

Definition at line 154 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\doSearchTitle().

◆ setFeatureData()

MediaWiki\Search\SearchEngine::setFeatureData ( $feature,
$data )

Way to pass custom data for engines.

Since
1.18
Parameters
string$feature
mixed$data

Definition at line 230 of file SearchEngine.php.

◆ setHookContainer()

MediaWiki\Search\SearchEngine::setHookContainer ( HookContainer $hookContainer)
Since
1.35
Access: internal
Parameters
HookContainer$hookContainer

Definition at line 835 of file SearchEngine.php.

◆ setLimitOffset()

MediaWiki\Search\SearchEngine::setLimitOffset ( $limit,
$offset = 0 )

Set the maximum number of results to return and how many to skip before returning the first.

Parameters
int$limit
int$offset

Definition at line 296 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\$limit, and MediaWiki\Search\SearchEngine\$offset.

Referenced by MediaWiki\Search\SearchEngine\completionSearchWithVariants().

◆ setNamespaces()

MediaWiki\Search\SearchEngine::setNamespaces ( $namespaces)

Set which namespaces the search should include.

Give an array of namespace index numbers.

Parameters
int[] | null$namespaces

Definition at line 307 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\$namespaces, and MediaWiki\MediaWikiServices\getInstance().

Referenced by MediaWiki\Search\SearchEngine\normalizeNamespaces().

◆ setShowSuggestion()

MediaWiki\Search\SearchEngine::setShowSuggestion ( $showSuggestion)

Set whether the searcher should try to build a suggestion.

Note: some searchers don't support building a suggestion in the first place and others don't respect this flag.

Parameters
bool$showSuggestionShould the searcher try to build suggestions

Definition at line 327 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\$showSuggestion.

◆ setSort()

MediaWiki\Search\SearchEngine::setSort ( $sort)

Set the sort direction of the search results.

Must be one returned by SearchEngine::getValidSorts()

Since
1.25
Parameters
string$sortsort direction for query result

Definition at line 351 of file SearchEngine.php.

References MediaWiki\Search\SearchEngine\getValidSorts().

◆ simplePrefixSearch()

MediaWiki\Search\SearchEngine::simplePrefixSearch ( $search)
protected

Call out to simple search backend.

Defaults to TitlePrefixSearch.

Parameters
string$search
Returns
Title[]

Definition at line 713 of file SearchEngine.php.

References MediaWiki\Search\PrefixSearch\defaultSearchBackend().

Referenced by MediaWiki\Search\SearchEngine\completionSearchBackend(), and MediaWiki\Search\SearchEngine\defaultPrefixSearch().

◆ supports()

MediaWiki\Search\SearchEngine::supports ( $feature)
Since
1.18
Stability: stable
to override
Parameters
string$feature
Returns
bool

Reimplemented in MediaWiki\Search\SearchMySQL.

Definition at line 214 of file SearchEngine.php.

◆ update()

MediaWiki\Search\SearchEngine::update ( $id,
$title,
$text )

Create or update the search index record for the given page.

Title and text should be pre-processed. STUB

Parameters
int$id
string$title
string$text

Reimplemented in MediaWiki\Search\SearchMySQL, MediaWiki\Search\SearchSqlite, and MediaWiki\Search\SearchPostgres.

Definition at line 460 of file SearchEngine.php.

◆ updateTitle()

MediaWiki\Search\SearchEngine::updateTitle ( $id,
$title )

Update a search index record's title only.

Title should be pre-processed. STUB

Parameters
int$id
string$title

Reimplemented in MediaWiki\Search\SearchMySQL, MediaWiki\Search\SearchPostgres, and MediaWiki\Search\SearchSqlite.

Definition at line 472 of file SearchEngine.php.

◆ userHighlightPrefs()

static MediaWiki\Search\SearchEngine::userHighlightPrefs ( )
static

Find snippet highlight settings for all users.

Returns
array Contextlines, contextchars
Deprecated
since 1.34; use the SearchHighlighter constants directly
See also
SearchHighlighter::DEFAULT_CONTEXT_CHARS
SearchHighlighter::DEFAULT_CONTEXT_LINES

Definition at line 445 of file SearchEngine.php.

References MediaWiki\Search\SearchHighlighter\DEFAULT_CONTEXT_CHARS, and MediaWiki\Search\SearchHighlighter\DEFAULT_CONTEXT_LINES.

Member Data Documentation

◆ $features

array MediaWiki\Search\SearchEngine::$features = []
protected

Feature values.

Definition at line 60 of file SearchEngine.php.

◆ $limit

int MediaWiki\Search\SearchEngine::$limit = 10
protected

◆ $namespaces

int [] null MediaWiki\Search\SearchEngine::$namespaces = [ NS_MAIN ]

Definition at line 40 of file SearchEngine.php.

Referenced by MediaWiki\Search\SearchEngine\setNamespaces().

◆ $offset

int MediaWiki\Search\SearchEngine::$offset = 0
protected

◆ $prefix

string MediaWiki\Search\SearchEngine::$prefix = ''

◆ $searchTerms

string [] MediaWiki\Search\SearchEngine::$searchTerms = []
protected
Deprecated
since 1.34

Definition at line 52 of file SearchEngine.php.

◆ $showSuggestion

bool MediaWiki\Search\SearchEngine::$showSuggestion = true
protected

Definition at line 55 of file SearchEngine.php.

Referenced by MediaWiki\Search\SearchEngine\setShowSuggestion().

◆ CHARS_ALL

const MediaWiki\Search\SearchEngine::CHARS_ALL = 1
protected

Integer flag for legalSearchChars: includes all chars allowed in a search query.

Definition at line 78 of file SearchEngine.php.

◆ CHARS_NO_SYNTAX

const MediaWiki\Search\SearchEngine::CHARS_NO_SYNTAX = 2
protected

Integer flag for legalSearchChars: includes all chars allowed in a search term.

Definition at line 81 of file SearchEngine.php.

◆ COMPLETION_PROFILE_TYPE

const MediaWiki\Search\SearchEngine::COMPLETION_PROFILE_TYPE = 'completionSearchProfile'

Profile type for completionSearch.

Definition at line 69 of file SearchEngine.php.

◆ DEFAULT_SORT

const MediaWiki\Search\SearchEngine::DEFAULT_SORT = 'relevance'

Definition at line 34 of file SearchEngine.php.

Referenced by MediaWiki\Search\SearchEngine\getValidSorts().

◆ FT_QUERY_DEP_PROFILE_TYPE

const MediaWiki\Search\SearchEngine::FT_QUERY_DEP_PROFILE_TYPE = 'fulltextQueryDepProfile'

Profile type for query dependent ranking features (ex: field weights)

Definition at line 75 of file SearchEngine.php.

◆ FT_QUERY_INDEP_PROFILE_TYPE

const MediaWiki\Search\SearchEngine::FT_QUERY_INDEP_PROFILE_TYPE = 'fulltextQueryIndepProfile'

Profile type for query independent ranking features (ex: article popularity)

Definition at line 72 of file SearchEngine.php.


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