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

Performs searches using Elasticsearch. More...

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

Public Member Functions

 __construct (Connection $conn, $offset, $limit, SearchConfig $config, array $namespaces=null, User $user=null, $index=false, CirrusDebugOptions $options=null, NamespacePrefixParser $namespacePrefixParser=null, InterwikiResolver $interwikiResolver=null, TitleHelper $titleHelper=null, CirrusSearchHookRunner $cirrusSearchHookRunner=null)
 
 search (SearchQuery $query)
 Unified search public entry-point.
 
 setResultsType ( $resultsType)
 
 isReturnRaw ()
 Is this searcher used to return debugging info?
 
 setSort ( $sort)
 Set the type of sort to perform.
 
 limitSearchToLocalWiki ( $limitSearchToLocalWiki)
 Should this search limit results to the local wiki? If not called the default is false.
 
 nearMatchTitleSearch ( $term)
 Perform a "near match" title search which is pretty much a prefix match without the prefixes.
 
 countContentWords ()
 Perform a sum over the number of words in the content index.
 
 prefixSearch ( $term, $variants=[])
 Perform a prefix search.
 
 get (array $docIds, $sourceFiltering, $usePoolCounter=true)
 Get the page with $docId.
 
 updateNamespacesFromQuery (&$query)
 Attempt to suck a leading namespace followed by a colon from the query string.
 
 getSearchContext ()
 
 processRawReturn ( $result, WebRequest $request)
 If we're supposed to create raw result, create and return it, or output it and finish.
 
 searchArchive ( $term)
 Search titles in archive.
 
 applyDebugOptionsToQuery (Query $query)
 Apply debug options to the elastica query.
 
 makeSearcher (SearchQuery $query)
 
 getOffsetLimit ()
 Visible for testing.
 
- Public Member Functions inherited from CirrusSearch\ElasticsearchIntermediary
 start (RequestLog $log)
 Mark the start of a request to Elasticsearch.
 
 success ( $result=null, Connection $connection=null)
 Log a successful request and return the provided result in a good Status.
 
 successViaCache (RequestLog $log)
 Log a successful request when the response comes from a cache outside elasticsearch.
 
 failure (ExceptionInterface $exception=null, Connection $connection=null)
 Log a failure and return an appropriate status.
 
 getSearchMetrics ()
 Get the search metrics we have.
 

Public Attributes

const SUGGESTION_HIGHLIGHT_PRE = '<em>'
 
const SUGGESTION_HIGHLIGHT_POST = '</em>'
 
const HIGHLIGHT_PRE_MARKER = ''
 
const HIGHLIGHT_PRE = '<span class="searchmatch">'
 
const HIGHLIGHT_POST_MARKER = ''
 
const HIGHLIGHT_POST = '</span>'
 
const MAINSEARCH_MSEARCH_KEY = '__main__'
 Identifies the main search in MSearchRequests/MSearchResponses.
 

Protected Member Functions

 buildFullTextSearch ( $term)
 Build full text search for articles with provided term.
 
 buildSearch ()
 
 searchOne ()
 Perform a single-query search.
 
 getQueryCacheStatsKey ()
 
 newLog ( $description, $queryType, array $extra=[])
 
- Protected Member Functions inherited from CirrusSearch\ElasticsearchIntermediary
 __construct (Connection $connection, UserIdentity $user=null, $slowSeconds=null, $extraBackendLatency=0)
 
 startNewLog ( $description, $queryType, array $extra=[])
 
 getTimeout ( $searchType='default')
 
 getClientTimeout ( $searchType='default')
 
 appendMetrics (SearchMetricsProvider $provider)
 
 runMSearch (Search $search, RequestLog $log, Connection $connection=null, callable $resultsTransformer=null)
 

Protected Attributes

 $offset
 
 $limit
 
 $indexBaseName
 
 $config
 
 $searchContext
 
 $interwikiResolver
 
 $titleHelper
 
 $cirrusSearchHookRunner
 
- Protected Attributes inherited from CirrusSearch\ElasticsearchIntermediary
 $connection
 
 $user
 
 $currentRequestLog = null
 

Additional Inherited Members

- Static Public Member Functions inherited from CirrusSearch\ElasticsearchIntermediary
static setResultPages (array $matches)
 This is set externally because we don't have complete control, from the SearchEngine interface, of what is actually sent to the user.
 
static getQueryTypesUsed ()
 Report the types of queries that were issued within the current request.
 
static hasQueryLogs ()
 
static appendLastLogPayload ( $key, $value)
 
static isMSearchResultSetOK (MultiResultSet $multiResultSet)
 check validity of the multisearch response
 
- Static Protected Attributes inherited from CirrusSearch\ElasticsearchIntermediary
static $requestLogger
 

Detailed Description

Performs searches using Elasticsearch.

Note that each instance of this class is single use only.

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\Searcher::__construct ( Connection $conn,
$offset,
$limit,
SearchConfig $config,
array $namespaces = null,
User $user = null,
$index = false,
CirrusDebugOptions $options = null,
NamespacePrefixParser $namespacePrefixParser = null,
InterwikiResolver $interwikiResolver = null,
TitleHelper $titleHelper = null,
CirrusSearchHookRunner $cirrusSearchHookRunner = null )
Parameters
Connection$conn
int$offsetOffset the results by this much
int$limitLimit the results to this many
SearchConfig$configConfiguration settings
int[] | null$namespacesArray of namespace numbers to search or null to search all namespaces.
User | null$useruser for which this search is being performed. Attached to slow request logs.
string | bool$indexBase name for index to search from, defaults to $wgCirrusSearchIndexBaseName
CirrusDebugOptions | null$optionsthe debugging options to use or null to use defaults
NamespacePrefixParser | null$namespacePrefixParser
InterwikiResolver | null$interwikiResolver
TitleHelper | null$titleHelper
CirrusSearchHookRunner | null$cirrusSearchHookRunner
See also
CirrusDebugOptions::defaultOptions()

Member Function Documentation

◆ applyDebugOptionsToQuery()

CirrusSearch\Searcher::applyDebugOptionsToQuery ( Query $query)

Apply debug options to the elastica query.

Parameters
Query$query
Returns
Query

◆ buildFullTextSearch()

CirrusSearch\Searcher::buildFullTextSearch ( $term)
protected

Build full text search for articles with provided term.

All the state is applied to $this->searchContext. The returned query builder can be used to build a degraded query if necessary.

Parameters
string$termterm to search
Returns
FullTextQueryBuilder

◆ buildSearch()

CirrusSearch\Searcher::buildSearch ( )
protected
Returns
\Elastica\Search

◆ countContentWords()

CirrusSearch\Searcher::countContentWords ( )

Perform a sum over the number of words in the content index.

Returns
Status status containing a single integer

◆ get()

CirrusSearch\Searcher::get ( array $docIds,
$sourceFiltering,
$usePoolCounter = true )

Get the page with $docId.

Note that the result is a status containing all pages found. It is possible to find more then one page if the page is in multiple indexes.

Parameters
string[]$docIdsarray of document ids
string[] | bool$sourceFilteringsource filtering to apply
bool$usePoolCounterfalse to disable the pool counter
Returns
Status containing pages found, containing an empty array if not found, or an error if there was an error

◆ getOffsetLimit()

CirrusSearch\Searcher::getOffsetLimit ( )

Visible for testing.

Returns
int[] 2 elements array

◆ getQueryCacheStatsKey()

CirrusSearch\Searcher::getQueryCacheStatsKey ( )
protected
Returns
string The stats key used for reporting hit/miss rates of the application side query cache.

Reimplemented in CirrusSearch\InterwikiSearcher.

◆ getSearchContext()

CirrusSearch\Searcher::getSearchContext ( )
Returns
SearchContext

◆ isReturnRaw()

CirrusSearch\Searcher::isReturnRaw ( )

Is this searcher used to return debugging info?

Returns
bool true if the search will return raw output

◆ limitSearchToLocalWiki()

CirrusSearch\Searcher::limitSearchToLocalWiki ( $limitSearchToLocalWiki)

Should this search limit results to the local wiki? If not called the default is false.

Parameters
bool$limitSearchToLocalWikishould the results be limited?

◆ makeSearcher()

CirrusSearch\Searcher::makeSearcher ( SearchQuery $query)
Parameters
SearchQuery$query
Returns
Searcher

Implements CirrusSearch\Fallbacks\SearcherFactory.

◆ nearMatchTitleSearch()

CirrusSearch\Searcher::nearMatchTitleSearch ( $term)

Perform a "near match" title search which is pretty much a prefix match without the prefixes.

Parameters
string$termtext by which to search
Returns
Status status containing results defined by resultsType on success

◆ newLog()

CirrusSearch\Searcher::newLog ( $description,
$queryType,
array $extra = [] )
protected
Parameters
string$description
string$queryType
string[]$extra
Returns
SearchRequestLog

Reimplemented from CirrusSearch\ElasticsearchIntermediary.

◆ prefixSearch()

CirrusSearch\Searcher::prefixSearch ( $term,
$variants = [] )

Perform a prefix search.

Parameters
string$termtext by which to search
string[]$variantsvariants to search for
Returns
Status status containing results defined by resultsType on success

◆ processRawReturn()

CirrusSearch\Searcher::processRawReturn ( $result,
WebRequest $request )

If we're supposed to create raw result, create and return it, or output it and finish.

Parameters
mixed$resultSearch result data
WebRequest$requestRequest context
Returns
string The new raw result.

◆ search()

CirrusSearch\Searcher::search ( SearchQuery $query)

Unified search public entry-point.

NOTE: only fulltext search supported for now.

Parameters
SearchQuery$query
Returns
Status

◆ searchArchive()

CirrusSearch\Searcher::searchArchive ( $term)

Search titles in archive.

Parameters
string$term
Returns
Status<Title[]>

◆ searchOne()

CirrusSearch\Searcher::searchOne ( )
protected

Perform a single-query search.

Returns
Status

◆ setResultsType()

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

◆ setSort()

CirrusSearch\Searcher::setSort ( $sort)

Set the type of sort to perform.

Must be 'relevance', 'title_asc', 'title_desc'.

Parameters
string$sortsort type

◆ updateNamespacesFromQuery()

CirrusSearch\Searcher::updateNamespacesFromQuery ( & $query)

Attempt to suck a leading namespace followed by a colon from the query string.

Reaches out to Elasticsearch to perform normalized lookup against the namespaces. Should be fast but for the network hop.

Parameters
string&$query

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