Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

Support for "WHERE IN" searches #55

Merged
merged 1 commit into from
Aug 8, 2017
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/ElasticsearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ protected function performSearch(Builder $builder, array $options = [])
protected function filters(Builder $builder)
{
return collect($builder->wheres)->map(function ($value, $key) {
if (is_array($value)) {
return ['terms' => [$key => $value]];
}

return ['match_phrase' => [$key => $value]];
})->values()->all();
}
Expand Down
4 changes: 3 additions & 1 deletion tests/ElasticsearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function test_search_sends_correct_parameters_to_elasticsearch()
'bool' => [
'must' => [
['query_string' => ['query' => '*zonda*']],
['match_phrase' => ['foo' => 1]]
['match_phrase' => ['foo' => 1]],
['terms' => ['bar' => [1, 3]]],
]
]
],
Expand All @@ -76,6 +77,7 @@ public function test_search_sends_correct_parameters_to_elasticsearch()
$engine = new ElasticsearchEngine($client, 'scout');
$builder = new Laravel\Scout\Builder(new ElasticsearchEngineTestModel, 'zonda');
$builder->where('foo', 1);
$builder->where('bar', [1, 3]);
$builder->orderBy('id', 'desc');
$engine->search($builder);
}
Expand Down