diff --git a/src/lib/eZ/FieldType/RichText/SearchField.php b/src/lib/eZ/FieldType/RichText/SearchField.php index dfbf3dab..7e814744 100644 --- a/src/lib/eZ/FieldType/RichText/SearchField.php +++ b/src/lib/eZ/FieldType/RichText/SearchField.php @@ -36,7 +36,7 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition) return [ new Search\Field( 'value', - $this->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): string { $result = null; + // try to extract first paragraph/tag if ($section = $document->documentElement->firstChild) { $textDom = $section->firstChild; @@ -93,7 +96,10 @@ 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/src/lib/eZ/FieldType/RichText/Type.php b/src/lib/eZ/FieldType/RichText/Type.php index 94782c9d..787b7647 100644 --- a/src/lib/eZ/FieldType/RichText/Type.php +++ b/src/lib/eZ/FieldType/RichText/Type.php @@ -164,17 +164,17 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $value) } /** - * Returns sortKey information. + * Returns information for FieldValue->$sortKey relevant to the field type. * * @see \eZ\Publish\Core\FieldType * * @param \EzSystems\EzPlatformRichText\eZ\FieldType\RichText\Value $value * - * @return array|bool + * @return string|null */ protected function getSortInfo(BaseValue $value) { - return false; + return SearchField::extractShortText($value->xml); } /** diff --git a/src/lib/eZ/Persistence/Legacy/RichTextFieldValueConverter.php b/src/lib/eZ/Persistence/Legacy/RichTextFieldValueConverter.php index 57622964..0fe78ea5 100644 --- a/src/lib/eZ/Persistence/Legacy/RichTextFieldValueConverter.php +++ b/src/lib/eZ/Persistence/Legacy/RichTextFieldValueConverter.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'; } }