Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filtering null values in where() with Meilisearch #901

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Engines/MeilisearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ protected function filters(Builder $builder)
return sprintf('%s=%s', $key, $value ? 'true' : 'false');
}

if (is_null($value)) {
return sprintf('%s %s', $key, 'IS NULL');
}

return is_numeric($value)
? sprintf('%s=%s', $key, $value)
: sprintf('%s="%s"', $key, $value);
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Engines/MeilisearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,13 @@ public function test_where_in_conditions_are_applied()
$builder = new Builder(new SearchableUser, '');
$builder->where('foo', 'bar');
$builder->where('bar', 'baz');
$builder->where('baz', null);
$builder->whereIn('qux', [1, 2]);
$builder->whereIn('quux', [1, 2]);

$this->client->shouldReceive('index')->once()->with('users')->andReturn($index = m::mock(Indexes::class));
$index->shouldReceive('rawSearch')->once()->with($builder->query, array_filter([
'filter' => 'foo="bar" AND bar="baz" AND qux IN [1, 2] AND quux IN [1, 2]',
'filter' => 'foo="bar" AND bar="baz" AND baz IS NULL AND qux IN [1, 2] AND quux IN [1, 2]',
'hitsPerPage' => $builder->limit,
]))->andReturn([]);

Expand Down
Loading