*!
Normalizes the text \a $text so that it is easily parsable
\param $isMetaData If \c true then it expects the text to be meta data from objects,
if not it is the search text and needs special handling.
public normalizeText ( $text, $isMetaData = false ) |
/** * Normalizes the text so that it is easily parsable * * Used only by legacy search engine. * * @param string $text * * @return string */ public function normalizeText($text) { if ($this->searchEngine == 'legacy') { $searchEngine = new eZSearchEngine(); return $searchEngine->normalizeText($text); } return $text; }
/** * Adds object $contentObject to the search database. * * @param eZContentObject $contentObject Object to add to search engine * @param bool $commit Whether to commit after adding the object * @return bool True if the operation succeed. */ public function addObject($contentObject, $commit = true) { $contentObjectID = $contentObject->attribute('id'); $currentVersion = $contentObject->currentVersion(); if (!$currentVersion) { $errCurrentVersion = $contentObject->attribute('current_version'); eZDebug::writeError("Failed to fetch \"current version\" ({$errCurrentVersion})" . " of content object (ID: {$contentObjectID})", 'eZSearchEngine'); return false; } $indexArray = array(); $indexArrayOnlyWords = array(); $wordCount = 0; $placement = 0; $previousWord = ''; eZContentObject::recursionProtectionStart(); foreach ($currentVersion->contentObjectAttributes() as $attribute) { $metaData = array(); $classAttribute = $attribute->contentClassAttribute(); if ($classAttribute->attribute("is_searchable") == 1) { // Fetch attribute translations $attributeTranslations = $attribute->fetchAttributeTranslations(); foreach ($attributeTranslations as $translation) { $tmpMetaData = $translation->metaData(); if (!is_array($tmpMetaData)) { $tmpMetaData = array(array('id' => $attribute->attribute('contentclass_attribute_identifier'), 'text' => $tmpMetaData)); } $metaData = array_merge($metaData, $tmpMetaData); } foreach ($metaData as $metaDataPart) { $text = eZSearchEngine::normalizeText(htmlspecialchars($metaDataPart['text'], ENT_NOQUOTES, 'UTF-8'), true); // Split text on whitespace if (is_numeric(trim($text))) { $integerValue = (int) $text; } else { $integerValue = 0; } $wordArray = explode(' ', $text); foreach ($wordArray as $word) { if (trim($word) != "") { // words stored in search index are limited to 150 characters if (strlen($word) > 150) { $word = substr($word, 0, 150); } $indexArray[] = array('Word' => $word, 'ContentClassAttributeID' => $attribute->attribute('contentclassattribute_id'), 'identifier' => $metaDataPart['id'], '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 (substr(strtolower($word), 0, 4) == 'www.') { $additionalUrlWord = substr($word, 4); $indexArray[] = array('Word' => $additionalUrlWord, 'ContentClassAttributeID' => $attribute->attribute('contentclassattribute_id'), 'identifier' => $metaDataPart['id'], 'integer_value' => $integerValue); $indexArrayOnlyWords[$additionalUrlWord] = 1; $wordCount++; } } } } } } eZContentObject::recursionProtectionEnd(); $wordIDArray = $this->buildWordIDArray(array_keys($indexArrayOnlyWords)); $db = eZDB::instance(); $db->begin(); for ($arrayCount = 0; $arrayCount < $wordCount; $arrayCount += 1000) { $placement = $this->indexWords($contentObject, array_slice($indexArray, $arrayCount, 1000), $wordIDArray, $placement); } $db->commit(); return true; }
/** * Normalizes the text so that it is easily parsable * * Used only by legacy search engine (eZSearchEngine class). * * @param string $text * * @return string */ public function normalizeText($text) { if ($this->searchHandler instanceof LegacyHandler) { $searchEngine = new eZSearchEngine(); return $searchEngine->normalizeText($text); } return $text; }