Skip to content

Commit

Permalink
Merge pull request #2995 from bolt/bugfix/select-json-search-multiple
Browse files Browse the repository at this point in the history
Allow Select fields with `JSON_SEARCH` to filter multiple values
  • Loading branch information
bobdenotter authored Dec 3, 2021
2 parents 57936b8 + 735b167 commit 6244854
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Storage/SelectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,14 @@ private function getRegularFieldExpression(Filter $filter): string
private function getRegularFieldWhereExpression(Filter $filter, string $valueAlias): string
{
if ($this->utils->isFieldType($this, $filter->getKey(), SelectField::TYPE) && $this->utils->hasJsonSearch()) {
// todo: Instead of using only the 1st param, make sure that the whole expression works.
// this is the case for things like multiselect: abc || def
return sprintf("JSON_SEARCH(%s, 'one', :%s) != ''", $valueAlias, key($filter->getParameters()));
$expressions = preg_split('/\s?(AND|OR)\s?/', $filter->getExpression());

$newExpressions = array_map(function($expression) use ($valueAlias) {
preg_match('/:\w+/', $expression, $parameter);
return sprintf("JSON_SEARCH(%s, 'one', %s) != ''", $valueAlias, $parameter[0]);
}, $expressions);

return str_replace($expressions, $newExpressions, $filter->getExpression());
}

$originalLeftExpression = 'content.' . $filter->getKey();
Expand Down

0 comments on commit 6244854

Please sign in to comment.