Skip to content

Commit 74be50b

Browse files
authored
Fix filtering null values in where() with Meilisearch (#901)
1 parent d0c0ae3 commit 74be50b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Engines/MeilisearchEngine.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ protected function filters(Builder $builder)
182182
return sprintf('%s=%s', $key, $value ? 'true' : 'false');
183183
}
184184

185+
if (is_null($value)) {
186+
return sprintf('%s %s', $key, 'IS NULL');
187+
}
188+
185189
return is_numeric($value)
186190
? sprintf('%s=%s', $key, $value)
187191
: sprintf('%s="%s"', $key, $value);

tests/Feature/Engines/MeilisearchEngineTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ public function test_where_in_conditions_are_applied()
206206
$builder = new Builder(new SearchableUser, '');
207207
$builder->where('foo', 'bar');
208208
$builder->where('bar', 'baz');
209+
$builder->where('baz', null);
209210
$builder->whereIn('qux', [1, 2]);
210211
$builder->whereIn('quux', [1, 2]);
211212

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

0 commit comments

Comments
 (0)