diff --git a/eZ/Publish/API/Repository/Tests/FieldType/RichTextIntegrationTest.php b/eZ/Publish/API/Repository/Tests/FieldType/RichTextIntegrationTest.php index 06305ab5e94..ab8b12bb8e2 100644 --- a/eZ/Publish/API/Repository/Tests/FieldType/RichTextIntegrationTest.php +++ b/eZ/Publish/API/Repository/Tests/FieldType/RichTextIntegrationTest.php @@ -772,18 +772,6 @@ private function getDocumentWithLocationLink(Location $location) return $document; } - /** - * @todo Drop this once Legacy Engine is able to do basic searching on this; shortened text like Search on sort_key_string. - */ - protected function checkSearchEngineSupport() - { - if (ltrim(get_class($this->getSetupFactory()), '\\') === 'eZ\\Publish\\API\\Repository\\Tests\\SetupFactory\\Legacy') { - $this->markTestSkipped( - "'ezrichtext' field type is not searchable with Legacy Search Engine" - ); - } - } - protected function getValidSearchValueOne() { return <<extractShortText($document), + self::extractShortText($document), new Search\FieldType\StringField() ), new Search\Field( @@ -72,13 +72,16 @@ private function extractText(DOMNode $node) /** * Extracts short text content of the given $document. * + * @internal Only for use by RichText FieldType itself. + * * @param \DOMDocument $document * * @return string */ - private function extractShortText(DOMDocument $document) + public static function extractShortText(DOMDocument $document) { $result = null; + // try to extract first paragraph/tag if ($section = $document->documentElement->firstChild) { $textDom = $section->firstChild; @@ -93,7 +96,11 @@ private function extractShortText(DOMDocument $document) $result = $document->documentElement->textContent; } - return trim($result); + + // In case of newlines, extract first line. Also limit size to 255 which is maxsize on sql impl. + $lines = preg_split('/\r\n|\n|\r/', trim($result), -1, PREG_SPLIT_NO_EMPTY); + + return empty($lines) ? '' : trim(mb_substr($lines[0], 0, 255)); } /** diff --git a/eZ/Publish/Core/FieldType/RichText/Type.php b/eZ/Publish/Core/FieldType/RichText/Type.php index a3f34f8f4e7..3ed67f1d227 100644 --- a/eZ/Publish/Core/FieldType/RichText/Type.php +++ b/eZ/Publish/Core/FieldType/RichText/Type.php @@ -279,7 +279,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $value) */ protected function getSortInfo(BaseValue $value) { - return false; + return SearchField::extractShortText($value->xml); } /** diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/FieldValue/Converter/RichTextConverter.php b/eZ/Publish/Core/Persistence/Legacy/Content/FieldValue/Converter/RichTextConverter.php index 319fa91b539..9b6b8deda00 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/FieldValue/Converter/RichTextConverter.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/FieldValue/Converter/RichTextConverter.php @@ -40,6 +40,7 @@ public static function create() public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue) { $storageFieldValue->dataText = $value->data; + $storageFieldValue->sortKeyString = $value->sortKey; } /** @@ -51,6 +52,7 @@ public function toStorageValue(FieldValue $value, StorageFieldValue $storageFiel public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue) { $fieldValue->data = $value->dataText ?: Value::EMPTY_VALUE; + $fieldValue->sortKey = $value->sortKeyString; } /** @@ -86,6 +88,6 @@ public function toFieldDefinition(StorageFieldDefinition $storageDefinition, Fie */ public function getIndexColumn() { - return false; + return 'sort_key_string'; } }