Skip to content

Commit 97aef55

Browse files
[9.x] Check for meilisearch-php 0.19.0 instead (#513)
* Check for meilisearch-php 0.19.0 instead * Update tests * Update MeiliSearchEngine.php Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 59024ec commit 97aef55

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/Engines/MeiliSearchEngine.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ protected function performSearch(Builder $builder, array $searchParams = [])
127127
{
128128
$meilisearch = $this->meilisearch->index($builder->index ?: $builder->model->searchableAs());
129129

130-
if (version_compare(MeiliSearch::VERSION, '0.21.0') >= 0) {
130+
// meilisearch-php 0.19.0 is compatible with meilisearch server 0.21.0...
131+
if (version_compare(MeiliSearch::VERSION, '0.19.0') >= 0 && isset($searchParams['filters'])) {
131132
$searchParams['filter'] = $searchParams['filters'];
132133

133134
unset($searchParams['filters']);

tests/Unit/MeiliSearchEngineTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ public function test_search_sends_correct_parameters_to_meilisearch()
4848
$client = m::mock(Client::class);
4949
$client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class));
5050
$index->shouldReceive('search')->with('mustang', [
51-
'filters' => 'foo=1 AND bar=2',
51+
'filter' => 'foo=1 AND bar=2',
5252
]);
5353

5454
$engine = new MeiliSearchEngine($client);
5555
$builder = new Builder(new SearchableModel(), 'mustang', function ($meilisearch, $query, $options) {
56-
$options['filters'] = 'foo=1 AND bar=2';
56+
$options['filter'] = 'foo=1 AND bar=2';
5757

5858
return $meilisearch->search($query, $options);
5959
});
@@ -66,14 +66,14 @@ public function test_submitting_a_callable_search_with_search_method_returns_arr
6666
new SearchableModel(),
6767
$query = 'mustang',
6868
$callable = function ($meilisearch, $query, $options) {
69-
$options['filters'] = 'foo=1';
69+
$options['filter'] = 'foo=1';
7070

7171
return $meilisearch->search($query, $options);
7272
}
7373
);
7474
$client = m::mock(Client::class);
7575
$client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class));
76-
$index->shouldReceive('search')->with($query, ['filters' => 'foo=1'])->andReturn(new SearchResult($expectedResult = [
76+
$index->shouldReceive('search')->with($query, ['filter' => 'foo=1'])->andReturn(new SearchResult($expectedResult = [
7777
'hits' => [],
7878
'offset' => 0,
7979
'limit' => 20,
@@ -95,14 +95,14 @@ public function test_submitting_a_callable_search_with_raw_search_method_works()
9595
new SearchableModel(),
9696
$query = 'mustang',
9797
$callable = function ($meilisearch, $query, $options) {
98-
$options['filters'] = 'foo=1';
98+
$options['filter'] = 'foo=1';
9999

100100
return $meilisearch->rawSearch($query, $options);
101101
}
102102
);
103103
$client = m::mock(Client::class);
104104
$client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class));
105-
$index->shouldReceive('rawSearch')->with($query, ['filters' => 'foo=1'])->andReturn($expectedResult = [
105+
$index->shouldReceive('rawSearch')->with($query, ['filter' => 'foo=1'])->andReturn($expectedResult = [
106106
'hits' => [],
107107
'offset' => 0,
108108
'limit' => 20,
@@ -274,14 +274,14 @@ public function test_pagination_correct_parameters()
274274
$client = m::mock(Client::class);
275275
$client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class));
276276
$index->shouldReceive('search')->with('mustang', [
277-
'filters' => 'foo=1',
277+
'filter' => 'foo=1',
278278
'limit' => $perPage,
279279
'offset' => ($page - 1) * $perPage,
280280
]);
281281

282282
$engine = new MeiliSearchEngine($client);
283283
$builder = new Builder(new SearchableModel(), 'mustang', function ($meilisearch, $query, $options) {
284-
$options['filters'] = 'foo=1';
284+
$options['filter'] = 'foo=1';
285285

286286
return $meilisearch->search($query, $options);
287287
});
@@ -335,7 +335,7 @@ public function test_where_conditions_are_applied()
335335
$client = m::mock(Client::class);
336336
$client->shouldReceive('index')->once()->andReturn($index = m::mock(Indexes::class));
337337
$index->shouldReceive('rawSearch')->once()->with($builder->query, array_filter([
338-
'filters' => 'foo="bar" AND key="value"',
338+
'filter' => 'foo="bar" AND key="value"',
339339
'limit' => $builder->limit,
340340
]))->andReturn([]);
341341

@@ -353,7 +353,7 @@ public function test_where_in_conditions_are_applied()
353353
$client = m::mock(Client::class);
354354
$client->shouldReceive('index')->once()->andReturn($index = m::mock(Indexes::class));
355355
$index->shouldReceive('rawSearch')->once()->with($builder->query, array_filter([
356-
'filters' => 'foo="bar" AND bar="baz" AND (qux=1 OR qux=2) AND (quux=1 OR quux=2)',
356+
'filter' => 'foo="bar" AND bar="baz" AND (qux=1 OR qux=2) AND (quux=1 OR quux=2)',
357357
'limit' => $builder->limit,
358358
]))->andReturn([]);
359359

@@ -369,7 +369,7 @@ public function test_where_in_conditions_are_applied_without_other_conditions()
369369
$client = m::mock(Client::class);
370370
$client->shouldReceive('index')->once()->andReturn($index = m::mock(Indexes::class));
371371
$index->shouldReceive('rawSearch')->once()->with($builder->query, array_filter([
372-
'filters' => '(qux=1 OR qux=2) AND (quux=1 OR quux=2)',
372+
'filter' => '(qux=1 OR qux=2) AND (quux=1 OR quux=2)',
373373
'limit' => $builder->limit,
374374
]))->andReturn([]);
375375

0 commit comments

Comments
 (0)