Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
ElasticSearchTTMServer Class Reference

TTMServer backed based on ElasticSearch. More...

Inheritance diagram for ElasticSearchTTMServer:
TTMServer ReadableTTMServer WritableTTMServer SearchableTTMServer

Public Member Functions

 isLocalSuggestion (array $suggestion)
 Determines if the suggestion returned by this TTMServer comes from this wiki or any other wiki.
 
 expandLocation (array $suggestion)
 Given suggestion returned by this TTMServer, constructs fully qualified URL to the location of the translation.
 
 query ( $sourceLanguage, $targetLanguage, $text)
 Fetches all relevant suggestions for given text.
 
 update (MessageHandle $handle, $targetText)
 Add / update translations.
 
 createIndex ( $rebuild)
 Create index.
 
 beginBootstrap ()
 Begin the bootstrap process.
 
 beginBatch ()
 Called before every batch (MessageGroup).
 
 batchInsertDefinitions (array $batch)
 
 batchInsertTranslations (array $batch)
 Called multiple times per batch if necessary.
 
 endBatch ()
 Called before every batch (MessageGroup).
 
 endBootstrap ()
 Do any cleanup, optimizing etc.
 
 getClient ()
 
 useWikimediaExtraPlugin ()
 
 getIndex ()
 
 setLogger ( $logger)
 
 setDoReIndex ()
 Force the update of index mappings @inheritDoc.
 
 createSearch ( $queryString, $opts, $highlight)
 Search interface.
 
 search ( $queryString, $opts, $highlight)
 Search interface.
 
 getFacets ( $resultset)
 
 getTotalHits ( $resultset)
 
 getDocuments ( $resultset)
 
- Public Member Functions inherited from TTMServer
 __construct (array $config)
 
 getMirrors ()
 
 isFrozen ()
 
- Public Member Functions inherited from WritableTTMServer
 getMirrors ()
 Get the list of services to duplicate writes to make them "mirrors" of this service.
 
 isFrozen ()
 Check if the service is frozen, attempting to write to a frozen service may lead to errors or unexpected behaviors.
 

Protected Member Functions

 doQuery ( $sourceLanguage, $targetLanguage, $text)
 
 createDocument (MessageHandle $handle, $text, $revId)
 
 getShardCount ()
 
 getReplicaCount ()
 
 getIndexHealth ( $indexName)
 Get index health TODO: Remove this code in the future as we drop support for older versions of the Elastica extension.
 
 waitForGreen ( $indexName, $timeout)
 Wait for the index to go green.
 
 waitUntilReady ()
 
 logOutput ( $text)
 
 parseQueryString ( $queryString, array $opts)
 Parse query string and build the search query.
 

Protected Attributes

 $client
 
 $logger
 Reference to the maintenance script to relay logging output.
 
 $updateMapping = false
 Used for Reindex.
 
- Protected Attributes inherited from TTMServer
 $config
 

Additional Inherited Members

- Static Public Member Functions inherited from TTMServer
static factory (array $config)
 
static primary ()
 Returns the primary server instance, useful for chaining.
 
static sortSuggestions (array $suggestions)
 
static levenshtein ( $str1, $str2, $length1, $length2)
 PHP implementation of Levenshtein edit distance algorithm.
 
static onDelete (WikiPage $wikipage)
 Hook: ArticleDeleteComplete.
 
static onChange (MessageHandle $handle)
 Called from TranslateEditAddons::onSave.
 
static onGroupChange (MessageHandle $handle, $old)
 

Detailed Description

TTMServer backed based on ElasticSearch.

Depends on Elastica.

Since
2014.04

Definition at line 29 of file ElasticSearchTTMServer.php.

Member Function Documentation

◆ batchInsertDefinitions()

ElasticSearchTTMServer::batchInsertDefinitions ( array $batch)
Parameters
array[]$batch@phan-param array<int,array{0:MessageHandle,1:string,2:string}> $batch

Implements WritableTTMServer.

Definition at line 433 of file ElasticSearchTTMServer.php.

◆ batchInsertTranslations()

ElasticSearchTTMServer::batchInsertTranslations ( array $batch)

Called multiple times per batch if necessary.

Parameters
array$batch

Implements WritableTTMServer.

Definition at line 443 of file ElasticSearchTTMServer.php.

◆ beginBatch()

ElasticSearchTTMServer::beginBatch ( )

Called before every batch (MessageGroup).

Implements WritableTTMServer.

Definition at line 425 of file ElasticSearchTTMServer.php.

◆ beginBootstrap()

ElasticSearchTTMServer::beginBootstrap ( )

Begin the bootstrap process.

Exceptions
RuntimeException

Implements WritableTTMServer.

Definition at line 363 of file ElasticSearchTTMServer.php.

◆ createDocument()

ElasticSearchTTMServer::createDocument ( MessageHandle $handle,
$text,
$revId )
protected
Parameters
MessageHandle$handle
string$text
int$revId
Returns
Document

Definition at line 298 of file ElasticSearchTTMServer.php.

◆ createIndex()

ElasticSearchTTMServer::createIndex ( $rebuild)

Create index.

Parameters
bool$rebuildDeletes index first if already exists

Definition at line 321 of file ElasticSearchTTMServer.php.

◆ createSearch()

ElasticSearchTTMServer::createSearch ( $queryString,
$opts,
$highlight )

Search interface.

Parameters
string$queryString
array$opts
array$highlight
Returns
\Elastica\Search

Definition at line 673 of file ElasticSearchTTMServer.php.

◆ doQuery()

ElasticSearchTTMServer::doQuery ( $sourceLanguage,
$targetLanguage,
$text )
protected

Definition at line 74 of file ElasticSearchTTMServer.php.

◆ endBatch()

ElasticSearchTTMServer::endBatch ( )

Called before every batch (MessageGroup).

Implements WritableTTMServer.

Definition at line 465 of file ElasticSearchTTMServer.php.

◆ endBootstrap()

ElasticSearchTTMServer::endBootstrap ( )

Do any cleanup, optimizing etc.

Implements WritableTTMServer.

Definition at line 469 of file ElasticSearchTTMServer.php.

◆ expandLocation()

ElasticSearchTTMServer::expandLocation ( array $suggestion)

Given suggestion returned by this TTMServer, constructs fully qualified URL to the location of the translation.

Parameters
array$suggestion
Returns
string URL

Implements ReadableTTMServer.

Definition at line 62 of file ElasticSearchTTMServer.php.

◆ getClient()

ElasticSearchTTMServer::getClient ( )

Definition at line 476 of file ElasticSearchTTMServer.php.

◆ getDocuments()

ElasticSearchTTMServer::getDocuments ( $resultset)
Parameters
\Elastica\ResultSet$resultset
Returns
array

Implements SearchableTTMServer.

Definition at line 785 of file ElasticSearchTTMServer.php.

◆ getFacets()

ElasticSearchTTMServer::getFacets ( $resultset)
Parameters
\Elastica\ResultSet$resultset
Returns
array

Implements SearchableTTMServer.

Definition at line 755 of file ElasticSearchTTMServer.php.

◆ getIndex()

ElasticSearchTTMServer::getIndex ( )

Definition at line 497 of file ElasticSearchTTMServer.php.

◆ getIndexHealth()

ElasticSearchTTMServer::getIndexHealth ( $indexName)
protected

Get index health TODO: Remove this code in the future as we drop support for older versions of the Elastica extension.

Parameters
string$indexName
Returns
array the index health status

Definition at line 518 of file ElasticSearchTTMServer.php.

◆ getReplicaCount()

ElasticSearchTTMServer::getReplicaCount ( )
protected

Definition at line 506 of file ElasticSearchTTMServer.php.

◆ getShardCount()

ElasticSearchTTMServer::getShardCount ( )
protected

Definition at line 502 of file ElasticSearchTTMServer.php.

◆ getTotalHits()

ElasticSearchTTMServer::getTotalHits ( $resultset)
Parameters
\Elastica\ResultSet$resultset
Returns
int

Implements SearchableTTMServer.

Definition at line 777 of file ElasticSearchTTMServer.php.

◆ isLocalSuggestion()

ElasticSearchTTMServer::isLocalSuggestion ( array $suggestion)

Determines if the suggestion returned by this TTMServer comes from this wiki or any other wiki.

Parameters
array$suggestion
Returns
bool

Implements ReadableTTMServer.

Definition at line 58 of file ElasticSearchTTMServer.php.

◆ logOutput()

ElasticSearchTTMServer::logOutput ( $text)
protected

Definition at line 581 of file ElasticSearchTTMServer.php.

◆ parseQueryString()

ElasticSearchTTMServer::parseQueryString ( $queryString,
array $opts )
protected

Parse query string and build the search query.

Parameters
string$queryString
array$opts
Returns
array

Definition at line 601 of file ElasticSearchTTMServer.php.

◆ query()

ElasticSearchTTMServer::query ( $sourceLanguage,
$targetLanguage,
$text )

Fetches all relevant suggestions for given text.

Parameters
string$sourceLanguagelanguage code for the provide text
string$targetLanguagelanguage code for the suggestions
string$textthe text for which to search suggestions
Returns
array List: unordered suggestions, which each has fields:
  • source: String: the original text of the suggestion
  • target: String: the suggestion
  • context: String: title of the page where the suggestion comes from
  • quality: Float: the quality of suggestion, 1 is perfect match

Implements ReadableTTMServer.

Definition at line 66 of file ElasticSearchTTMServer.php.

◆ search()

ElasticSearchTTMServer::search ( $queryString,
$opts,
$highlight )

Search interface.

Parameters
string$queryString
array$opts
array$highlight
Exceptions
TTMServerException
Returns
\Elastica\ResultSet

Implements SearchableTTMServer.

Definition at line 741 of file ElasticSearchTTMServer.php.

◆ setDoReIndex()

ElasticSearchTTMServer::setDoReIndex ( )

Force the update of index mappings @inheritDoc.

Implements WritableTTMServer.

Definition at line 591 of file ElasticSearchTTMServer.php.

◆ setLogger()

ElasticSearchTTMServer::setLogger ( $logger)

Definition at line 576 of file ElasticSearchTTMServer.php.

◆ update()

ElasticSearchTTMServer::update ( MessageHandle $handle,
$targetText )

Add / update translations.

Parameters
MessageHandle$handle
?string$targetText
Returns
bool
Exceptions
RuntimeException

Implements WritableTTMServer.

Definition at line 235 of file ElasticSearchTTMServer.php.

◆ useWikimediaExtraPlugin()

ElasticSearchTTMServer::useWikimediaExtraPlugin ( )
Returns
true if the backend is configured with the wikimedia extra plugin

Definition at line 488 of file ElasticSearchTTMServer.php.

◆ waitForGreen()

ElasticSearchTTMServer::waitForGreen ( $indexName,
$timeout )
protected

Wait for the index to go green.

NOTE: This method has been copied and adjusted from CirrusSearch/includes/Maintenance/ConfigUtils.php. Ideally we'd like to make these utility methods available in the Elastica extension, but this one requires some refactoring in cirrus first. TODO: Remove this code in the future as we drop support for older versions of the Elastica extension.

Parameters
string$indexName
int$timeout
Returns
bool true if the index is green false otherwise.

Definition at line 541 of file ElasticSearchTTMServer.php.

◆ waitUntilReady()

ElasticSearchTTMServer::waitUntilReady ( )
protected

Definition at line 560 of file ElasticSearchTTMServer.php.

Member Data Documentation

◆ $client

ElasticSearchTTMServer::$client
protected

Definition at line 48 of file ElasticSearchTTMServer.php.

◆ $logger

ElasticSearchTTMServer::$logger
protected

Reference to the maintenance script to relay logging output.

Definition at line 52 of file ElasticSearchTTMServer.php.

◆ $updateMapping

ElasticSearchTTMServer::$updateMapping = false
protected

Used for Reindex.

Definition at line 56 of file ElasticSearchTTMServer.php.


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