Skip to content

Commit d8b54f9

Browse files
authored
Revert "Removed numericFilters from AlgoliaEngine. (#837)" (#838)
This reverts commit dadf49e.
1 parent dadf49e commit d8b54f9

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/Engines/AlgoliaEngine.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function delete($models)
105105
public function search(Builder $builder)
106106
{
107107
return $this->performSearch($builder, array_filter([
108-
'filters' => $this->filters($builder),
108+
'numericFilters' => $this->filters($builder),
109109
'hitsPerPage' => $builder->limit,
110110
]));
111111
}
@@ -121,7 +121,7 @@ public function search(Builder $builder)
121121
public function paginate(Builder $builder, $perPage, $page)
122122
{
123123
return $this->performSearch($builder, [
124-
'filters' => $this->filters($builder),
124+
'numericFilters' => $this->filters($builder),
125125
'hitsPerPage' => $perPage,
126126
'page' => $page - 1,
127127
]);
@@ -163,18 +163,18 @@ protected function performSearch(Builder $builder, array $options = [])
163163
protected function filters(Builder $builder)
164164
{
165165
$wheres = collect($builder->wheres)->map(function ($value, $key) {
166-
return $key.":'{$value}'";
166+
return $key.'='.$value;
167167
})->values();
168168

169169
return $wheres->merge(collect($builder->whereIns)->map(function ($values, $key) {
170170
if (empty($values)) {
171-
return '0:1';
171+
return '0=1';
172172
}
173173

174-
return '('.collect($values)->map(function ($value) use ($key) {
175-
return $key.":'{$value}'";
176-
})->implode(' OR ').')';
177-
})->values()->implode(' AND '))->values()->filter()->implode(' AND ');
174+
return collect($values)->map(function ($value) use ($key) {
175+
return $key.'='.$value;
176+
})->all();
177+
})->values())->values()->all();
178178
}
179179

180180
/**

tests/Unit/AlgoliaEngineTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function test_search_sends_correct_parameters_to_algolia()
113113
$client = m::mock(SearchClient::class);
114114
$client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock(stdClass::class));
115115
$index->shouldReceive('search')->with('zonda', [
116-
'filters' => "foo:'1'",
116+
'numericFilters' => ['foo=1'],
117117
]);
118118

119119
$engine = new AlgoliaEngine($client);
@@ -127,13 +127,12 @@ public function test_search_sends_correct_parameters_to_algolia_for_where_in_sea
127127
$client = m::mock(SearchClient::class);
128128
$client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock(stdClass::class));
129129
$index->shouldReceive('search')->with('zonda', [
130-
'filters' => "foo:'1' AND (bar:'1' OR bar:'2') AND (qux:'2' OR qux:'3')",
130+
'numericFilters' => ['foo=1', ['bar=1', 'bar=2']],
131131
]);
132132

133133
$engine = new AlgoliaEngine($client);
134134
$builder = new Builder(new SearchableModel, 'zonda');
135-
$builder->where('foo', 1)->whereIn('bar', [1, 2])
136-
->whereIn('qux', [2, 3]);
135+
$builder->where('foo', 1)->whereIn('bar', [1, 2]);
137136
$engine->search($builder);
138137
}
139138

@@ -142,7 +141,7 @@ public function test_search_sends_correct_parameters_to_algolia_for_empty_where_
142141
$client = m::mock(SearchClient::class);
143142
$client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock(stdClass::class));
144143
$index->shouldReceive('search')->with('zonda', [
145-
'filters' => "foo:'1' AND 0:1",
144+
'numericFilters' => ['foo=1', '0=1'],
146145
]);
147146

148147
$engine = new AlgoliaEngine($client);

0 commit comments

Comments
 (0)