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

Base class with useful functions for communicating with Elasticsearch. More...

+ Inheritance diagram for CirrusSearch\ElasticsearchIntermediary:

Public Member Functions

 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.
 

Static Public Member Functions

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
 

Protected Member Functions

 __construct (Connection $connection, UserIdentity $user=null, $slowSeconds=null, $extraBackendLatency=0)
 
 startNewLog ( $description, $queryType, array $extra=[])
 
 newLog ( $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

 $connection
 
 $user
 
 $currentRequestLog = null
 

Static Protected Attributes

static $requestLogger
 

Detailed Description

Base class with useful functions for communicating with Elasticsearch.

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\ElasticsearchIntermediary::__construct ( Connection $connection,
UserIdentity $user = null,
$slowSeconds = null,
$extraBackendLatency = 0 )
protected
Parameters
Connection$connection
UserIdentity | null$useruser for which this search is being performed. Attached to slow request logs. Note that null isn't for anonymous users
  • those are still User objects and should be provided if possible. Null is for when the action is being performed in some context where the user that caused it isn't available. Like when an action is being performed during a job.
float | null$slowSecondshow many seconds a request through this intermediary needs to take before it counts as slow. 0 means none count as slow. Defaults to CirrusSearchSlowSearch config option.
int$extraBackendLatencyartificial backend latency.

Member Function Documentation

◆ appendLastLogPayload()

static CirrusSearch\ElasticsearchIntermediary::appendLastLogPayload ( $key,
$value )
static
Parameters
string$key
string$value

◆ appendMetrics()

CirrusSearch\ElasticsearchIntermediary::appendMetrics ( SearchMetricsProvider $provider)
protected
Parameters
SearchMetricsProvider$provider

◆ failure()

CirrusSearch\ElasticsearchIntermediary::failure ( ExceptionInterface $exception = null,
Connection $connection = null )

Log a failure and return an appropriate status.

Public so it can be called from pool counter methods.

Parameters
ExceptionInterface | null$exceptionif the request failed
Connection | null$connectionThe connection that the failed request was performed against. Will use $this->connection when not provided.
Returns
Status representing a backend failure

◆ getClientTimeout()

CirrusSearch\ElasticsearchIntermediary::getClientTimeout ( $searchType = 'default')
protected
Parameters
string$searchType
Returns
int the client side timeout

◆ getQueryTypesUsed()

static CirrusSearch\ElasticsearchIntermediary::getQueryTypesUsed ( )
static

Report the types of queries that were issued within the current request.

Returns
string[]

◆ getSearchMetrics()

CirrusSearch\ElasticsearchIntermediary::getSearchMetrics ( )

Get the search metrics we have.

Returns
array

◆ getTimeout()

CirrusSearch\ElasticsearchIntermediary::getTimeout ( $searchType = 'default')
protected
Parameters
string$searchType
Returns
string search retrieval timeout

◆ hasQueryLogs()

static CirrusSearch\ElasticsearchIntermediary::hasQueryLogs ( )
static
Returns
bool True when query logs have been generated by the current php execution.

◆ isMSearchResultSetOK()

static CirrusSearch\ElasticsearchIntermediary::isMSearchResultSetOK ( MultiResultSet $multiResultSet)
static

check validity of the multisearch response

Parameters
MultiResultSet$multiResultSet
Returns
bool

◆ newLog()

CirrusSearch\ElasticsearchIntermediary::newLog ( $description,
$queryType,
array $extra = [] )
abstractprotected
Parameters
string$descriptionA psr-3 compliant string describing the request
string$queryTypeThe type of search being performed such as fulltext, get, etc.
array$extraA map of additional request-specific data
Returns
RequestLog

Reimplemented in CirrusSearch\BuildDocument\RedirectsAndIncomingLinks, CirrusSearch\CompletionSuggester, CirrusSearch\DataSender, CirrusSearch\Searcher, CirrusSearch\Updater, and CirrusSearch\Version.

◆ runMSearch()

CirrusSearch\ElasticsearchIntermediary::runMSearch ( Search $search,
RequestLog $log,
Connection $connection = null,
callable $resultsTransformer = null )
protected
Parameters
Search$search
RequestLog$log
Connection | null$connection
callable | null$resultsTransformerthat accepts a Multi/ResultSets
Returns
Status

◆ setResultPages()

static CirrusSearch\ElasticsearchIntermediary::setResultPages ( array $matches)
static

This is set externally because we don't have complete control, from the SearchEngine interface, of what is actually sent to the user.

Instead hooks receive the final results that will be sent to the user and set them here.

Accepts two result sets because some places (Special:Search) perform multiple searches. This can be called multiple times, but only that last call wins. For API's that is correct, for Special:Search a hook catches the final results and sets them here.

Parameters
ISearchResultSet[]$matches

◆ start()

CirrusSearch\ElasticsearchIntermediary::start ( RequestLog $log)

Mark the start of a request to Elasticsearch.

Public so it can be called from pool counter methods.

Parameters
RequestLog$log

◆ startNewLog()

CirrusSearch\ElasticsearchIntermediary::startNewLog ( $description,
$queryType,
array $extra = [] )
protected
Parameters
string$descriptionA psr-3 compliant string describing the request
string$queryTypeThe type of search being performed such as fulltext, get, etc.
array$extraA map of additional request-specific data
Returns
RequestLog

◆ success()

CirrusSearch\ElasticsearchIntermediary::success ( $result = null,
Connection $connection = null )

Log a successful request and return the provided result in a good Status.

If you don't need the status just ignore the return. Public so it can be called from pool counter methods.

Parameters
mixed | null$resultresult of the request. defaults to null in case the request doesn't have a result
Connection | null$connectionThe connection the succesful request was performed against. Will use $this->connection when not provided.
Returns
Status wrapping $result

◆ successViaCache()

CirrusSearch\ElasticsearchIntermediary::successViaCache ( RequestLog $log)

Log a successful request when the response comes from a cache outside elasticsearch.

This is a combination of self::start() and self::success().

Parameters
RequestLog$log

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