Skip to content

Commit

Permalink
Update meilisearch filter to accept comparison operators
Browse files Browse the repository at this point in the history
  • Loading branch information
rrakibul committed Nov 1, 2023
1 parent 753260b commit 83a783c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Engines/MeilisearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

Expand Down

0 comments on commit 83a783c

Please sign in to comment.