Flowpack.SimpleSearch.ContentRepositoryAdaptor
Flowpack.SimpleSearch.ContentRepositoryAdaptor copied to clipboard
ExactMatch operator does not seem to work with properties containing multiple references
Use Case: There's a nodetype "project" which has a property "categories" of type references. On the category page, i want to list all projects which have the current category in their reference property. Eel:
${Search.query(site).nodeType('My.Vendor:Project').exactMatch('category', node).execute()}
This works when there's only one category attached, if a 'project' has more than one category it will be not listed. Is there any possibility to check if the node is in the references list? Something like:
${Search.query(site).nodeType('My.Vendor:Project').isInProperty('category', node).execute()}
I solved my problem by extending \Flowpack\SimpleSearch\ContentRepositoryAdaptor\Search\SqLiteQueryBuilder and adding the following function:
/**
* adds an like query for references.
*
* @param $propertyName
* @param $propertyValue
* @return QueryBuilder
*/
public function isInReferences($propertyName, $propertyValue) {
$this->where[] = "(" . $propertyName . " LIKE '%" . $propertyValue->getIdentifier() . "%')";
return $this;
}
Thanks, will check how we want to deal with this in the API and implement.