Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Lib\Store\Sql\TermSqlIndex Class Reference

Term lookup cache. More...

+ Inheritance diagram for Wikibase\Lib\Store\Sql\TermSqlIndex:
+ Collaboration diagram for Wikibase\Lib\Store\Sql\TermSqlIndex:

Public Member Functions

 __construct (StringNormalizer $stringNormalizer, EntityIdParser $entityIdParser, EntitySource $entitySource)
 
 setUseSearchFields ( $useSearchFields)
 Set whether to read and write fields that are only useful for searching entities (term_search_key and term_weight).
 
 setForceWriteSearchFields ( $forceWriteSearchFields)
 If true, write search-related fields even if they are not used according to $useSearchFields.
 
 getTableName ()
 Returns the name of the database table used to store the terms.
 
 saveTermsOfEntity (EntityDocument $entity)
 
 getEntityTerms (EntityDocument $entity)
 
 deleteTermsOfEntity (EntityId $entityId)
 
 getTermsOfEntity (EntityId $entityId, array $termTypes=null, array $languageCodes=null)
 Returns the terms stored for the given entity.
 
 getTermsOfEntities (array $entityIds, array $termTypes=null, array $languageCodes=null)
 Returns the terms stored for the given entities.
 
 getReadDb ()
 Returns the IDatabase connection from which to read.
 
 getWriteDb ()
 Returns the IDatabase connection to which to write.
 
 getMatchingTerms (array $criteria, $termType=null, $entityType=null, array $options=[])
 
 getTopMatchingTerms (array $criteria, $termType=null, $entityType=null, array $options=[])
 
 clear ()
 
 getLabelConflicts ( $entityType, array $labels, array $aliases=null)
 
 getLabelWithDescriptionConflicts ( $entityType, array $labels, array $descriptions)
 
 getSearchKey ( $text)
 

Private Member Functions

 assertCanHandleEntityId (EntityId $id)
 
 assertEntityIdFromKnownSource (EntityId $id)
 
 insertTerms (EntityDocument $entity, array $terms, IDatabase $dbw)
 
 insertTerm (array $entityIdentifiers, TermIndexEntry $term, IDatabase $dbw)
 
 getTermListTerms ( $termType, TermList $termList, EntityId $entityId)
 
 getAliasGroupListTerms (AliasGroupList $aliasGroupList, EntityId $entityId)
 
 deleteTerms (EntityId $entityId, array $terms, IDatabase $dbw)
 
 getWeight (EntityDocument $entity)
 Calculate a weight the given entity to be used for ranking.
 
 getTermFields (TermIndexEntry $term)
 Returns an array with the database table fields for the provided term.
 
 fetchTerms (array $entityIds, array $termTypes=null, array $languageCodes=null)
 
 getRowsOrderedByWeight (Traversable $rows, $limit=0)
 
 criteriaToConditions (IDatabase $db, array $criteria, $termType=null, $entityType=null, array $options=[])
 
 getTermMatchConditions (IDatabase $db, TermIndexSearchCriteria $mask, $termType=null, $entityType=null, array $options=[])
 
 buildTermResult ( $obtainedTerms)
 Modifies the provided terms to use the field names expected by the interface rather then the table field names.
 
 getEntityId ( $termRow)
 
 assertEntityTypeKnown ( $entityType)
 
 makeQueryTerms ( $textsByLanguage, array $types)
 

Private Attributes

 $tableName
 
 $stringNormalizer
 
 $entityIdParser
 
 $logger
 
 $useSearchFields = true
 
 $forceWriteSearchFields = false
 
 $maxConflicts = 500
 
 $entitySource
 

Detailed Description

Term lookup cache.

Deprecated:
As wb_terms is going away, See https://phabricator.wikimedia.org/T208425

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Lib\Store\Sql\TermSqlIndex::__construct ( StringNormalizer  $stringNormalizer,
EntityIdParser  $entityIdParser,
EntitySource  $entitySource 
)
Parameters
StringNormalizer$stringNormalizer
EntityIdParser$entityIdParser
EntitySource$entitySource

Member Function Documentation

◆ assertCanHandleEntityId()

Wikibase\Lib\Store\Sql\TermSqlIndex::assertCanHandleEntityId ( EntityId  $id)
private

◆ assertEntityIdFromKnownSource()

Wikibase\Lib\Store\Sql\TermSqlIndex::assertEntityIdFromKnownSource ( EntityId  $id)
private

◆ assertEntityTypeKnown()

Wikibase\Lib\Store\Sql\TermSqlIndex::assertEntityTypeKnown (   $entityType)
private

◆ buildTermResult()

Wikibase\Lib\Store\Sql\TermSqlIndex::buildTermResult (   $obtainedTerms)
private

Modifies the provided terms to use the field names expected by the interface rather then the table field names.

Also ensures the values are of the correct type.

Parameters
object[] | Traversable$obtainedTerms
Returns
TermIndexEntry[]

◆ clear()

Wikibase\Lib\Store\Sql\TermSqlIndex::clear ( )
See also
TermIndex::clear
Returns
bool Success indicator

Implements Wikibase\Lib\Store\TermIndex.

◆ criteriaToConditions()

Wikibase\Lib\Store\Sql\TermSqlIndex::criteriaToConditions ( IDatabase  $db,
array  $criteria,
  $termType = null,
  $entityType = null,
array  $options = [] 
)
private
Parameters
IDatabase$db
TermIndexSearchCriteria[]$criteria
string | string[] | null$termType
string | string[] | null$entityType
array$options
Returns
string[]

◆ deleteTerms()

Wikibase\Lib\Store\Sql\TermSqlIndex::deleteTerms ( EntityId  $entityId,
array  $terms,
IDatabase  $dbw 
)
private
Parameters
EntityId$entityId
TermIndexEntry[]$terms
IDatabase$dbw
Returns
bool Success indicator

◆ deleteTermsOfEntity()

Wikibase\Lib\Store\Sql\TermSqlIndex::deleteTermsOfEntity ( EntityId  $entityId)
See also
TermIndex::deleteTermsOfEntity
Parameters
EntityId$entityId
Returns
bool Success indicator

Implements Wikibase\Lib\Store\EntityTermStoreWriter.

◆ fetchTerms()

Wikibase\Lib\Store\Sql\TermSqlIndex::fetchTerms ( array  $entityIds,
array  $termTypes = null,
array  $languageCodes = null 
)
private
Parameters
EntityId[]$entityIds
string[] | null$termTypes
string[] | null$languageCodes
Exceptions
MWException
Returns
TermIndexEntry[]

◆ getAliasGroupListTerms()

Wikibase\Lib\Store\Sql\TermSqlIndex::getAliasGroupListTerms ( AliasGroupList  $aliasGroupList,
EntityId  $entityId 
)
private
Parameters
AliasGroupList$aliasGroupList
EntityId$entityId
Returns
TermIndexEntry[]

◆ getEntityId()

Wikibase\Lib\Store\Sql\TermSqlIndex::getEntityId (   $termRow)
private
Parameters
object$termRow
Returns
EntityId|null

◆ getEntityTerms()

Wikibase\Lib\Store\Sql\TermSqlIndex::getEntityTerms ( EntityDocument  $entity)
Parameters
EntityDocument$entity
Returns
TermIndexEntry[]
Exceptions
MWException

◆ getLabelConflicts()

Wikibase\Lib\Store\Sql\TermSqlIndex::getLabelConflicts (   $entityType,
array  $labels,
array  $aliases = null 
)
See also
LabelConflictFinder::getLabelConflicts
Note
This implementation does not guarantee that all matches are returned. The maximum number of conflicts returned is controlled by $this->maxConflicts.
Parameters
string$entityType
string[]$labels
array[] | null$aliases
Exceptions
InvalidArgumentException
Returns
TermIndexEntry[]

Implements Wikibase\Lib\Store\LabelConflictFinder.

◆ getLabelWithDescriptionConflicts()

Wikibase\Lib\Store\Sql\TermSqlIndex::getLabelWithDescriptionConflicts (   $entityType,
array  $labels,
array  $descriptions 
)
See also
LabelConflictFinder::getLabelWithDescriptionConflicts
Note
This implementation does not guarantee that all matches are returned. The maximum number of conflicts returned is controlled by $this->maxConflicts.
Parameters
string$entityType
string[]$labels
string[]$descriptions
Exceptions
InvalidArgumentException
Returns
TermIndexEntry[]

Implements Wikibase\Lib\Store\LabelConflictFinder.

◆ getMatchingTerms()

Wikibase\Lib\Store\Sql\TermSqlIndex::getMatchingTerms ( array  $criteria,
  $termType = null,
  $entityType = null,
array  $options = [] 
)
See also
TermIndex::getMatchingTerms
Parameters
TermIndexSearchCriteria[]$criteria
string | string[] | null$termType
string | string[] | null$entityType
array$options
Returns
TermIndexEntry[]

Implements Wikibase\Lib\Store\MatchingTermsLookup.

◆ getReadDb()

Wikibase\Lib\Store\Sql\TermSqlIndex::getReadDb ( )

Returns the IDatabase connection from which to read.

Returns
IDatabase

◆ getRowsOrderedByWeight()

Wikibase\Lib\Store\Sql\TermSqlIndex::getRowsOrderedByWeight ( Traversable  $rows,
  $limit = 0 
)
private
Parameters
Traversable$rows
int$limit
Returns
object[]

◆ getSearchKey()

Wikibase\Lib\Store\Sql\TermSqlIndex::getSearchKey (   $text)
Parameters
string$text
Returns
string

◆ getTableName()

Wikibase\Lib\Store\Sql\TermSqlIndex::getTableName ( )

Returns the name of the database table used to store the terms.

This is the logical table name, subject to prefixing by the IDatabase object.

Returns
string

◆ getTermFields()

Wikibase\Lib\Store\Sql\TermSqlIndex::getTermFields ( TermIndexEntry  $term)
private

Returns an array with the database table fields for the provided term.

Parameters
TermIndexEntry$term
Returns
string[]

◆ getTermListTerms()

Wikibase\Lib\Store\Sql\TermSqlIndex::getTermListTerms (   $termType,
TermList  $termList,
EntityId  $entityId 
)
private
Parameters
string$termType
TermList$termList
EntityId$entityId
Returns
TermIndexEntry[]

◆ getTermMatchConditions()

Wikibase\Lib\Store\Sql\TermSqlIndex::getTermMatchConditions ( IDatabase  $db,
TermIndexSearchCriteria  $mask,
  $termType = null,
  $entityType = null,
array  $options = [] 
)
private
Parameters
IDatabase$db
TermIndexSearchCriteria$mask
string | string[] | null$termType
string | string[] | null$entityType
array$options
Returns
array

◆ getTermsOfEntities()

Wikibase\Lib\Store\Sql\TermSqlIndex::getTermsOfEntities ( array  $entityIds,
array  $termTypes = null,
array  $languageCodes = null 
)

Returns the terms stored for the given entities.

See also
TermIndex::getTermsOfEntities
Parameters
EntityId[]$entityIds
string[] | null$termTypes
string[] | null$languageCodes
Exceptions
MWException
Returns
TermIndexEntry[]

Implements Wikibase\Lib\Store\LegacyEntityTermStoreReader.

◆ getTermsOfEntity()

Wikibase\Lib\Store\Sql\TermSqlIndex::getTermsOfEntity ( EntityId  $entityId,
array  $termTypes = null,
array  $languageCodes = null 
)

Returns the terms stored for the given entity.

See also
TermIndex::getTermsOfEntity
Parameters
EntityId$entityId
string[] | null$termTypes
string[] | null$languageCodes
Returns
TermIndexEntry[]
Exceptions
MWException

Implements Wikibase\Lib\Store\LegacyEntityTermStoreReader.

◆ getTopMatchingTerms()

Wikibase\Lib\Store\Sql\TermSqlIndex::getTopMatchingTerms ( array  $criteria,
  $termType = null,
  $entityType = null,
array  $options = [] 
)
See also
TermIndex::getTopMatchingTerms
Parameters
TermIndexSearchCriteria[]$criteria
string | string[] | null$termType
string | string[] | null$entityType
array$optionsIn this implementation at most 2500 terms will be retrieved. As we only return a single TermIndexEntry per Entity the return count may be lower.
Returns
TermIndexEntry[]

Implements Wikibase\Lib\Store\MatchingTermsLookup.

◆ getWeight()

Wikibase\Lib\Store\Sql\TermSqlIndex::getWeight ( EntityDocument  $entity)
private

Calculate a weight the given entity to be used for ranking.

Should be normalized between 0 and 1, but that's not a strong constraint. This implementation uses the max of the number of labels and the number of sitelinks.

TODO Should be moved to its own object and be added via dependency injection

Parameters
EntityDocument$entity
Returns
float

◆ getWriteDb()

Wikibase\Lib\Store\Sql\TermSqlIndex::getWriteDb ( )

Returns the IDatabase connection to which to write.

Returns
IDatabase

◆ insertTerm()

Wikibase\Lib\Store\Sql\TermSqlIndex::insertTerm ( array  $entityIdentifiers,
TermIndexEntry  $term,
IDatabase  $dbw 
)
private
Parameters
array$entityIdentifiersTerm table fields identifying an entity
TermIndexEntry$term
IDatabase$dbw
Returns
bool Success indicator

◆ insertTerms()

Wikibase\Lib\Store\Sql\TermSqlIndex::insertTerms ( EntityDocument  $entity,
array  $terms,
IDatabase  $dbw 
)
private
Parameters
EntityDocument$entity
TermIndexEntry[]$terms
IDatabase$dbw
Returns
bool Success indicator

◆ makeQueryTerms()

Wikibase\Lib\Store\Sql\TermSqlIndex::makeQueryTerms (   $textsByLanguage,
array  $types 
)
private
Parameters
string[] | array[]$textsByLanguageA list of texts, or a list of lists of texts (keyed by language on the top level).
string[]$types
Exceptions
InvalidArgumentException
Returns
TermIndexSearchCriteria[]

◆ saveTermsOfEntity()

Wikibase\Lib\Store\Sql\TermSqlIndex::saveTermsOfEntity ( EntityDocument  $entity)
See also
TermIndex::saveTermsOfEntity
Parameters
EntityDocument$entityMust have an ID, and optionally any combination of terms as declared by the TermIndexEntry::TYPE_... constants.
Exceptions
InvalidArgumentExceptionwhen $entity does not have an ID.
MWException
Returns
bool Success indicator

Implements Wikibase\Lib\Store\EntityTermStoreWriter.

◆ setForceWriteSearchFields()

Wikibase\Lib\Store\Sql\TermSqlIndex::setForceWriteSearchFields (   $forceWriteSearchFields)

If true, write search-related fields even if they are not used according to $useSearchFields.

(This flag has no effect if $useSearchFields is true.)

Parameters
bool$forceWriteSearchFields

◆ setUseSearchFields()

Wikibase\Lib\Store\Sql\TermSqlIndex::setUseSearchFields (   $useSearchFields)

Set whether to read and write fields that are only useful for searching entities (term_search_key and term_weight).

This should only be used if search is provided by some other service (e. g. ElasticSearch) – if this is disabled, any search requests to this TermIndex will use the term_text (not normalized) instead of the term_search_key.

Parameters
bool$useSearchFields

Member Data Documentation

◆ $entityIdParser

Wikibase\Lib\Store\Sql\TermSqlIndex::$entityIdParser
private

◆ $entitySource

Wikibase\Lib\Store\Sql\TermSqlIndex::$entitySource
private

◆ $forceWriteSearchFields

Wikibase\Lib\Store\Sql\TermSqlIndex::$forceWriteSearchFields = false
private

◆ $logger

Wikibase\Lib\Store\Sql\TermSqlIndex::$logger
private

◆ $maxConflicts

Wikibase\Lib\Store\Sql\TermSqlIndex::$maxConflicts = 500
private

◆ $stringNormalizer

Wikibase\Lib\Store\Sql\TermSqlIndex::$stringNormalizer
private

◆ $tableName

Wikibase\Lib\Store\Sql\TermSqlIndex::$tableName
private

◆ $useSearchFields

Wikibase\Lib\Store\Sql\TermSqlIndex::$useSearchFields = true
private

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