Skip to content

Commit

Permalink
Add LegacySE search Field Criteria support for Author FieldType
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Jan 7, 2019
1 parent a887a49 commit c4a47b0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,19 +411,6 @@ public function providerForTestIsNotEmptyValue()
);
}

/**
* @todo Drop this once Legacy Engine is able to do basic searching on this, basically same value as "sort_value"
* field as sort_key_string (- as separator between author names).
*/
protected function checkSearchEngineSupport()
{
if (ltrim(get_class($this->getSetupFactory()), '\\') === 'eZ\\Publish\\API\\Repository\\Tests\\SetupFactory\\Legacy') {
$this->markTestSkipped(
"'ezauthor' field type is not searchable with Legacy Search Engine"
);
}
}

protected function getValidSearchValueOne()
{
return array(
Expand Down
14 changes: 12 additions & 2 deletions eZ/Publish/Core/FieldType/Author/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function checkValueStructure(BaseValue $value)
if (!$value->authors instanceof AuthorCollection) {
throw new InvalidArgumentType(
'$value->authors',
'eZ\\Publish\\Core\\FieldType\\Author\\AuthorCollection',
AuthorCollection::class,
$value->authors
);
}
Expand All @@ -96,7 +96,17 @@ protected function checkValueStructure(BaseValue $value)
*/
protected function getSortInfo(BaseValue $value)
{
return false;
if (empty($value->authors)) {
return false;
}

return implode(',', array_map(
function(Author $author){
return str_replace(',', '.', $author->name);
},
$value->authors->getArrayCopy()
));

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function create()
public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
{
$storageFieldValue->dataText = $this->generateXmlString($value->data);
$storageFieldValue->sortKeyString = $value->sortKey;
}

/**
Expand All @@ -51,6 +52,7 @@ public function toStorageValue(FieldValue $value, StorageFieldValue $storageFiel
public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
{
$fieldValue->data = $this->restoreValueFromXmlString($value->dataText);
$fieldValue->sortKey = $value->sortKeyString;
}

/**
Expand Down Expand Up @@ -86,7 +88,7 @@ public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefin
*/
public function getIndexColumn()
{
return false;
return 'sort_key_string';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ services:
arguments:
- ,
tags:
- {name: ezpublish.search.legacy.gateway.criterion_field_value_handler, alias: ezauthor}
- {name: ezpublish.search.legacy.gateway.criterion_field_value_handler, alias: ezcountry}
- {name: ezpublish.search.legacy.gateway.criterion_field_value_handler, alias: ezobjectrelationlist}
- {name: ezpublish.search.legacy.gateway.criterion_field_value_handler, alias: ezkeyword}
Expand Down

0 comments on commit c4a47b0

Please sign in to comment.