From 83a783ca730d79a28fa6793cfaa299087024e4bd Mon Sep 17 00:00:00 2001 From: rakibul Date: Wed, 1 Nov 2023 20:55:32 +0600 Subject: [PATCH] Update meilisearch filter to accept comparison operators --- src/Engines/MeilisearchEngine.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Engines/MeilisearchEngine.php b/src/Engines/MeilisearchEngine.php index 1fdb795a..86bf22e4 100644 --- a/src/Engines/MeilisearchEngine.php +++ b/src/Engines/MeilisearchEngine.php @@ -171,29 +171,32 @@ protected function performSearch(Builder $builder, array $searchParams = []) /** * Get the filter array for the query. * - * @param \Laravel\Scout\Builder $builder * @return string */ protected function filters(Builder $builder) { - $filters = collect($builder->wheres)->map(function ($value, $key) { - if (is_bool($value)) { - return sprintf('%s=%s', $key, $value ? 'true' : 'false'); + $wheres = array_map(function ($value) { + return ['operator' => '=', 'value' => $value]; + }, $builder->wheres); + + $filters = collect(array_merge($wheres, $builder->whereComparisons))->map(function ($value, $key) { + if (is_bool($value['value'])) { + return sprintf('%s'.$value['operator'].'%s', $key, $value['value'] ? 'true' : 'false'); } - return is_numeric($value) - ? sprintf('%s=%s', $key, $value) - : sprintf('%s="%s"', $key, $value); + return is_numeric($value['value']) + ? sprintf('%s'.$value['operator'].'%s', $key, $value['value']) + : sprintf('%s'.$value['operator'].'"%s"', $key, $value['value']); }); if (property_exists($builder, 'whereBetween')) { foreach ($builder->whereBetween as $key => $values) { - $filters->push(sprintf('%s %s TO %s', $key, $values[0], $values[1])); + $filters->push(sprintf('%s "%s" TO "%s"', $key, $values[0], end($values))); } } $whereInOperators = [ - 'whereIns' => 'IN', + 'whereIns' => 'IN', 'whereNotIns' => 'NOT IN', ];