Skip to content

Commit

Permalink
Add LegacySE search Field Criteria support for RelationList FieldType
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Jan 7, 2019
1 parent 522b9ca commit a887a49
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,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 relation ids).
*/
protected function checkSearchEngineSupport()
{
if (ltrim(get_class($this->getSetupFactory()), '\\') === 'eZ\\Publish\\API\\Repository\\Tests\\SetupFactory\\Legacy') {
$this->markTestSkipped(
"'ezobjectrelationlist' field type is not searchable with Legacy Search Engine"
);
}
}

protected function getValidSearchValueOne()
{
return array(11);
Expand Down
5 changes: 3 additions & 2 deletions eZ/Publish/Core/FieldType/RelationList/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,16 @@ protected function checkValueStructure(BaseValue $value)

/**
* Returns information for FieldValue->$sortKey relevant to the field type.
* For this FieldType, the related object's name is returned.
*
* For this FieldType, the related object's name is returned, separated by ",".
*
* @param \eZ\Publish\Core\FieldType\RelationList\Value $value
*
* @return string
*/
protected function getSortInfo(BaseValue $value)
{
return false;
return implode(',', $value->destinationContentIds);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function toStorageValue(FieldValue $value, StorageFieldValue $storageFiel
$doc->appendChild($root);

$storageFieldValue->dataText = $doc->saveXML();
$storageFieldValue->sortKeyString = $value->sortKey;
}

/**
Expand Down Expand Up @@ -106,6 +107,7 @@ public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
asort($priorityByContentId, SORT_NUMERIC);

$fieldValue->data['destinationContentIds'] = array_keys($priorityByContentId);
$fieldValue->sortKey = $value->sortKeyString;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,30 @@ public function __construct(DatabaseHandler $dbHandler, TransformationProcessor
public function handle(SelectQuery $query, Criterion $criterion, $column)
{
switch ($criterion->operator) {
case Criterion\Operator::LIKE:
case Criterion\Operator::CONTAINS:
if ($criterion->operator === Criterion\Operator::LIKE) {
if (strpos($criterion->value, '%') !== false) {
// @deprecated In 6.7.x/6.13.x/7.3.x and higher, to be removed in 8.0
@trigger_error(
"Usage of '%' in Operator::LIKE criteria with Legacy Search Engine was never intended, " .
"and is deprecated for removal in 8.0. Please use '*' like in FullText, works across engines",
E_USER_DEPRECATED
);
$value = $this->lowerCase($criterion->value);
} else {
$value = str_replace('*', '%', $this->prepareLikeString($criterion->value));
}
$singleValueExpr = 'like';
} else {
$value = $this->prepareLikeString($criterion->value);
$singleValueExpr = 'eq';
}

$quotedColumn = $this->dbHandler->quoteColumn($column);
$value = $this->prepareLikeString($criterion->value);
$filter = $query->expr->lOr(
array(
$query->expr->eq(
$query->expr->$singleValueExpr(
$quotedColumn,
$query->bindValue($value, null, \PDO::PARAM_STR)
),
Expand Down

0 comments on commit a887a49

Please sign in to comment.