Skip to content

Commit c29b0a1

Browse files
author
aprilsacil
authored
Merge pull request #39 from rujealfon/patch-1
filter json field
2 parents 82ba2bc + 48476ee commit c29b0a1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Model/Service/SqlService.php

+14
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,20 @@ public function search(array $data = [])
567567
$search->addFilter($column . ' IN ("' . implode('", "', $values) . '")');
568568
}
569569
}
570+
571+
// add json filters
572+
foreach ($json as $column => $values) {
573+
$or = [];
574+
$where = [];
575+
576+
foreach ($values as $value) {
577+
$where[] = "JSON_SEARCH(LOWER($column), 'one', %s) IS NOT NULL";
578+
$or[] = '%' . strtolower($value) . '%';
579+
}
580+
581+
array_unshift($or, '(' . implode(' OR ', $where) . ')');
582+
call_user_func([$search, 'addFilter'], ...$or);
583+
}
570584

571585
//add spans
572586
foreach ($span as $column => $value) {

0 commit comments

Comments
 (0)