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

SearchEngine implementation for CirrusSearch. More...

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

Public Member Functions

 __construct (SearchConfig $config=null, CirrusDebugOptions $debugOptions=null, NamespacePrefixParser $namespacePrefixParser=null, InterwikiResolver $interwikiResolver=null, TitleHelper $titleHelper=null)
 
 setConnection (Connection $connection)
 
 getConnection ()
 
 getConfig ()
 Get search config.
 
 supports ( $feature)
 Override supports to shut off updates to Cirrus via the SearchEngine infrastructure.
 
 getValidSorts ()
 Get the sort of sorts we allow.
 
 getLastSearchMetrics ()
 Get the metrics for the last search we performed.
 
 completionSearchWithVariants ( $search)
 Override variants function because we always do variants in the backend.
 
 getProfiles ( $profileType, User $user=null)
 
 extractProfileFromFeatureData ( $profileType)
 (public for testing purposes)
 
 makeSearchFieldMapping ( $name, $type)
 Create a search field definition.
 
 searchArchiveTitle ( $term)
 Perform a title search in the article archive.
 
 updateWeightedTags (ProperPageIdentity $page, string $tagPrefix, $tagNames=null, $tagWeights=null)
 Request the setting of the weighted_tags field for the given tag(s) and weight(s).
 
 resetWeightedTags (ProperPageIdentity $page, string $tagPrefix)
 Request the reset of the weighted_tags field for the category $tagCategory.
 
 countContentWords ()
 

Public Attributes

const AUTOSELECT_PROFILE = 'engine_autoselect'
 Special profile to instruct this class to use profile selection mechanism.
 
const COMPLETION_PREFIX_FALLBACK_PROFILE = 'classic'
 @const string name of the prefixsearch fallback profile
 
const MAX_TITLE_SEARCH = 255
 @const int Maximum title length that we'll check in prefix and keyword searches.
 
const EXTRA_FIELDS_TO_EXTRACT = 'extra-fields-to-extract'
 Name of the feature to extract more fields during a fulltext search request.
 

Protected Member Functions

 doSearchText ( $term)
 Overridden to delegate prefix searching to Searcher.
 
 searchTextReal (SearchQuery $query)
 Do the hard part of the searching - actual Searcher invocation.
 
 getSuggestions ( $search, $variants, SearchConfig $config)
 Look for suggestions using ES completion suggester.
 
 completionSearchBackend ( $search)
 Perform a completion search.
 
 prefixSearch ( $search, $variants)
 Older prefix search.
 
 getUpdater ()
 Helper method to facilitate mocking during tests.
 

Detailed Description

SearchEngine implementation for CirrusSearch.

Delegates to CirrusSearchSearcher for searches and CirrusSearchUpdater for updates. Note that lots of search behavior is hooked in CirrusSearchHooks rather than overridden here.

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

Constructor & Destructor Documentation

◆ __construct()

CirrusSearch\CirrusSearch::__construct ( SearchConfig $config = null,
CirrusDebugOptions $debugOptions = null,
NamespacePrefixParser $namespacePrefixParser = null,
InterwikiResolver $interwikiResolver = null,
TitleHelper $titleHelper = null )
Parameters
SearchConfig | null$config
CirrusDebugOptions | null$debugOptions
NamespacePrefixParser | null$namespacePrefixParser
InterwikiResolver | null$interwikiResolver
TitleHelper | null$titleHelper

Member Function Documentation

◆ completionSearchBackend()

CirrusSearch\CirrusSearch::completionSearchBackend ( $search)
protected

Perform a completion search.

Does not resolve namespaces and does not check variants. We use parent search for:

  • Special: namespace We use old prefix search for:
  • Suggester not enabled
  • Parameters
    string$search
    Returns
    SearchSuggestionSet

◆ completionSearchWithVariants()

CirrusSearch\CirrusSearch::completionSearchWithVariants ( $search)

Override variants function because we always do variants in the backend.

See also
SearchEngine::completionSearchWithVariants()
Parameters
string$search
Returns
SearchSuggestionSet

◆ countContentWords()

CirrusSearch\CirrusSearch::countContentWords ( )
Returns
Status Contains a single integer indicating the number of content words in the wiki

◆ doSearchText()

CirrusSearch\CirrusSearch::doSearchText ( $term)
protected

Overridden to delegate prefix searching to Searcher.

Parameters
string$termtext to search
Returns
Status Value is either SearchResultSet, or null on error.

◆ extractProfileFromFeatureData()

CirrusSearch\CirrusSearch::extractProfileFromFeatureData ( $profileType)

(public for testing purposes)

Parameters
string$profileType
Returns
string|null the profile name set in SearchEngine::features null if none present or equal to self::AUTOSELECT_PROFILE

◆ getConfig()

CirrusSearch\CirrusSearch::getConfig ( )

Get search config.

Returns
SearchConfig

◆ getConnection()

CirrusSearch\CirrusSearch::getConnection ( )
Returns
Connection

◆ getLastSearchMetrics()

CirrusSearch\CirrusSearch::getLastSearchMetrics ( )

Get the metrics for the last search we performed.

Null if we haven't done any.

Returns
array

◆ getProfiles()

CirrusSearch\CirrusSearch::getProfiles ( $profileType,
User $user = null )
Parameters
string$profileType
User | null$user
Returns
array|null
See also
SearchEngine::getProfiles()

◆ getSuggestions()

CirrusSearch\CirrusSearch::getSuggestions ( $search,
$variants,
SearchConfig $config )
protected

Look for suggestions using ES completion suggester.

Parameters
string$searchSearch string
string[] | null$variantsSearch term variants
SearchConfig$configsearch configuration
Returns
SearchSuggestionSet Set of suggested names

◆ getUpdater()

CirrusSearch\CirrusSearch::getUpdater ( )
protected

Helper method to facilitate mocking during tests.

Returns
Updater

◆ getValidSorts()

CirrusSearch\CirrusSearch::getValidSorts ( )

Get the sort of sorts we allow.

Returns
string[]

◆ makeSearchFieldMapping()

CirrusSearch\CirrusSearch::makeSearchFieldMapping ( $name,
$type )

Create a search field definition.

Parameters
string$name
string$type
Returns
SearchIndexField

◆ prefixSearch()

CirrusSearch\CirrusSearch::prefixSearch ( $search,
$variants )
protected

Older prefix search.

Parameters
string$searchsearch text
string[]$variants
Returns
SearchSuggestionSet

◆ resetWeightedTags()

CirrusSearch\CirrusSearch::resetWeightedTags ( ProperPageIdentity $page,
string $tagPrefix )

Request the reset of the weighted_tags field for the category $tagCategory.

Parameters
ProperPageIdentity$page
string$tagPrefix

◆ searchArchiveTitle()

CirrusSearch\CirrusSearch::searchArchiveTitle ( $term)

Perform a title search in the article archive.

Parameters
string$termRaw search term
Returns
Status<Title[]>

◆ searchTextReal()

CirrusSearch\CirrusSearch::searchTextReal ( SearchQuery $query)
protected

Do the hard part of the searching - actual Searcher invocation.

Parameters
SearchQuery$query
Returns
Status

◆ supports()

CirrusSearch\CirrusSearch::supports ( $feature)

Override supports to shut off updates to Cirrus via the SearchEngine infrastructure.

Page updates and additions are chained on the end of the links update job. Deletes are noticed via the ArticleDeleteComplete hook.

Parameters
string$featurefeature name
Returns
bool is this feature supported?

◆ updateWeightedTags()

CirrusSearch\CirrusSearch::updateWeightedTags ( ProperPageIdentity $page,
string $tagPrefix,
$tagNames = null,
$tagWeights = null )

Request the setting of the weighted_tags field for the given tag(s) and weight(s).

Will set a "$tagPrefix/$tagName" tag for each element of $tagNames, and will unset all other tags with the same prefix (in other words, this will replace the existing tag set for a given prefix). When $tagName is omitted, 'exists' will be used - this is canonical for tag types where the tag is fully determined by the prefix.

This is meant for testing and non-production setups. For production a more efficient batched update process can be implemented outside MediaWiki.

Parameters
ProperPageIdentity$page
string$tagPrefix
string | string[] | null$tagNames
int | int[] | null$tagWeightsTag weights (between 1-1000). When $tagNames is omitted, $tagWeights should be a single number; otherwise it should be a tagname => weight map.

Member Data Documentation

◆ AUTOSELECT_PROFILE

const CirrusSearch\CirrusSearch::AUTOSELECT_PROFILE = 'engine_autoselect'

Special profile to instruct this class to use profile selection mechanism.

This allows to defer profile selection to when we actually perform the search. The reason is that the list of possible profiles is returned by self::getProfiles so instead of assigning a default profile at this point we use this special profile.

◆ EXTRA_FIELDS_TO_EXTRACT

const CirrusSearch\CirrusSearch::EXTRA_FIELDS_TO_EXTRACT = 'extra-fields-to-extract'

Name of the feature to extract more fields during a fulltext search request.

Expected value is a list of strings identifying the fields to extract out of the source document.

See also
SearchEngine::supports() and SearchEngine::setFeatureData()

◆ MAX_TITLE_SEARCH

const CirrusSearch\CirrusSearch::MAX_TITLE_SEARCH = 255

@const int Maximum title length that we'll check in prefix and keyword searches.

Since titles can be 255 bytes in length we're setting this to 255 characters.


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