SearchVectorIndexer
in package
Builds and stores the search vector of records whose table registered a SearchVectorField.
Format: the tokens of one value are joined by a space, values are separated by | and the whole string is
wrapped in | … |, e.g. | fuhrung durch die altstadt | sommer | stadtrundgange | (without stemmer). The space
keeps word adjacency for quoted phrase searches, the pipe stops a phrase from matching across two unrelated values.
With a stemmer, each value is followed by its unstemmed words if they differ, e.g. | imkerhon | imkerhonig |, so a
compound is also found by its last word if the stemmer cuts the compound differently than the word on its own.
Option labels are resolved and words are stemmed in the language of the record (see SearchVectorFieldConfiguration::setLanguage() and setLanguageField()), never in the language of the current user.
Table of Contents
Constants
- TRANSPORT = 'contao_prio_normal'
- The messenger transport of asynchronous rebuilds, configured by the Contao Managed Edition.
- ARRAY_JOINER = "\x1f"
- Joins array values in the formatter output, so each array value stays a separate value of the vector.
- VALUE_SEPARATOR = ' | '
Properties
- $configurationResolver : SearchVectorConfigurationResolver
- $connection : Connection
- $eventDispatcher : EventDispatcherInterface
- $formatterUtil : FormatterUtil
- $languageSwitcher : SearchVectorLanguageSwitcher
- $logger : LoggerInterface
- $messageBus : MessageBusInterface|null
- $messengerTransports : ContainerInterface|null
- $virtualFieldsHandler : VirtualFieldsHandler|null
Methods
- __construct() : mixed
- buildVector() : string
- Builds the search vector from a raw database row.
- index() : bool
- Rebuilds the search vector of a single record.
- indexAll() : int
- Rebuilds the search vector of every record of a table.
- queue() : void
- Rebuilds the search vector of a single record asynchronously.
- formatValues() : array<int, string>
- Resolves the field values like the backend does: option labels, foreign keys, plain text instead of HTML.
- toPlainText() : string
Constants
TRANSPORT
The messenger transport of asynchronous rebuilds, configured by the Contao Managed Edition.
public
mixed
TRANSPORT
= 'contao_prio_normal'
ARRAY_JOINER
Joins array values in the formatter output, so each array value stays a separate value of the vector.
private
mixed
ARRAY_JOINER
= "\x1f"
VALUE_SEPARATOR
private
mixed
VALUE_SEPARATOR
= ' | '
Properties
$configurationResolver read-only
private
SearchVectorConfigurationResolver
$configurationResolver
$connection read-only
private
Connection
$connection
$eventDispatcher read-only
private
EventDispatcherInterface
$eventDispatcher
$formatterUtil read-only
private
FormatterUtil
$formatterUtil
$languageSwitcher read-only
private
SearchVectorLanguageSwitcher
$languageSwitcher
$logger read-only
private
LoggerInterface
$logger
$messageBus read-only
private
MessageBusInterface|null
$messageBus
= null
$messengerTransports read-only
private
ContainerInterface|null
$messengerTransports
= null
$virtualFieldsHandler read-only
private
VirtualFieldsHandler|null
$virtualFieldsHandler
= null
Methods
__construct()
public
__construct(Connection $connection, SearchVectorConfigurationResolver $configurationResolver, FormatterUtil $formatterUtil, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger, SearchVectorLanguageSwitcher $languageSwitcher[, MessageBusInterface|null $messageBus = null ][, ContainerInterface|null $messengerTransports = null ][, VirtualFieldsHandler|null $virtualFieldsHandler = null ]) : mixed
Parameters
- $connection : Connection
- $configurationResolver : SearchVectorConfigurationResolver
- $formatterUtil : FormatterUtil
- $eventDispatcher : EventDispatcherInterface
- $logger : LoggerInterface
- $languageSwitcher : SearchVectorLanguageSwitcher
- $messageBus : MessageBusInterface|null = null
- $messengerTransports : ContainerInterface|null = null
- $virtualFieldsHandler : VirtualFieldsHandler|null = null
buildVector()
Builds the search vector from a raw database row.
public
buildVector(string $table, array<string, mixed> $row[, DataContainer|null $dc = null ]) : string
Parameters
- $table : string
- $row : array<string, mixed>
- $dc : DataContainer|null = null
Return values
stringindex()
Rebuilds the search vector of a single record.
public
index(string $table, int $id[, DataContainer|null $dc = null ]) : bool
The record is read from the database, so this can be called from any save path after the record was written. The record is locked while its vector is rebuilt, so a concurrent rebuild of the same record waits and then reads the newer data instead of being overwritten with an outdated vector.
Parameters
- $table : string
- $id : int
- $dc : DataContainer|null = null
-
The data container passed to options callbacks. If omitted, a minimal one holding table, id and record is used.
Return values
bool —Whether the stored value changed
indexAll()
Rebuilds the search vector of every record of a table.
public
indexAll(string $table[, callable(int $id, bool $changed): void|null $onProgress = null ]) : int
Parameters
- $table : string
- $onProgress : callable(int $id, bool $changed): void|null = null
Return values
int —The number of records whose vector changed
queue()
Rebuilds the search vector of a single record asynchronously.
public
queue(string $table, int $id) : void
Sends a message to the contao_prio_normal transport, which a messenger worker or, without a running worker, Contao's web worker at the end of the request processes. Rebuilds the vector right away if the transport is not available.
Parameters
- $table : string
- $id : int
Tags
formatValues()
Resolves the field values like the backend does: option labels, foreign keys, plain text instead of HTML.
private
formatValues(string $table, array<string, mixed> $row, array<int, string> $fields, DataContainer $dc) : array<int, string>
Parameters
- $table : string
- $row : array<string, mixed>
- $fields : array<int, string>
- $dc : DataContainer
Return values
array<int, string>toPlainText()
private
toPlainText(string $value) : string
Parameters
- $value : string