public function index(FullTextData $fullTextData)
{
$indexArray = [];
$indexArrayOnlyWords = [];
$wordCount = 0;
$placement = 0;
// Remove previously indexed content if exists to avoid keeping in index removed field values
$this->remove($fullTextData->id);
foreach ($fullTextData->values as $fullTextValue) {
/** @var \eZ\Publish\Core\Search\Legacy\Content\FullTextValue $fullTextValue */
if (is_numeric(trim($fullTextValue->value))) {
$integerValue = (int) $fullTextValue->value;
if ($integerValue > self::DB_INT_MAX) {
$integerValue = 0;
}
} else {
$integerValue = 0;
}
$text = $this->transformationProcessor->transform($fullTextValue->value, $this->fullTextSearchConfiguration['commands']);
// split by non-words
$wordArray = preg_split('/\\W/u', $text, -1, PREG_SPLIT_NO_EMPTY);
foreach ($wordArray as $word) {
if (trim($word) === '') {
continue;
}
// words stored in search index are limited to 150 characters
if (mb_strlen($word) > 150) {
$word = mb_substr($word, 0, 150);
}
$indexArray[] = ['Word' => $word, 'ContentClassAttributeID' => $fullTextValue->fieldDefinitionId, 'identifier' => $fullTextValue->fieldDefinitionIdentifier, 'integer_value' => $integerValue];
$indexArrayOnlyWords[$word] = 1;
++$wordCount;
// if we have "www." before word than
// treat it as url and add additional entry to the index
if (mb_substr(mb_strtolower($word), 0, 4) === 'www.') {
$additionalUrlWord = substr($word, 4);
$indexArray[] = ['Word' => $additionalUrlWord, 'ContentClassAttributeID' => $fullTextValue->fieldDefinitionId, 'identifier' => $fullTextValue->fieldDefinitionIdentifier, 'integer_value' => $integerValue];
$indexArrayOnlyWords[$additionalUrlWord] = 1;
++$wordCount;
}
}
}
$wordIDArray = $this->buildWordIDArray(array_keys($indexArrayOnlyWords));
$this->dbHandler->beginTransaction();
for ($arrayCount = 0; $arrayCount < $wordCount; $arrayCount += 1000) {
$placement = $this->indexWords($fullTextData, array_slice($indexArray, $arrayCount, 1000), $wordIDArray, $placement);
}
$this->dbHandler->commit();
}