Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
babenkoivan committed May 27, 2024
1 parent 73d6251 commit e4ae5c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 40 deletions.
44 changes: 20 additions & 24 deletions src/Factories/SearchParametersFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,28 @@ protected function makeFilter(Builder $builder): ?array
'term' => [$field => $value],
])->values();

if (property_exists($builder, 'whereIns')) {
$whereIns = collect($builder->whereIns)->map(static fn (array $values, string $field) => [
'terms' => [$field => $values],
])->values();

if ($whereIns->isNotEmpty()) {
$filter->push([
'bool' => [
'must' => $whereIns->all(),
],
]);
}
$whereIns = collect($builder->whereIns)->map(static fn (array $values, string $field) => [
'terms' => [$field => $values],
])->values();

if ($whereIns->isNotEmpty()) {
$filter->push([
'bool' => [
'must' => $whereIns->all(),
],
]);
}

if (property_exists($builder, 'whereNotIns')) {
$whereNotIns = collect($builder->whereNotIns)->map(static fn (array $values, string $field) => [
'terms' => [$field => $values],
])->values();

if ($whereNotIns->isNotEmpty()) {
$filter->push([
'bool' => [
'must_not' => $whereNotIns->all(),
],
]);
}
$whereNotIns = collect($builder->whereNotIns)->map(static fn (array $values, string $field) => [
'terms' => [$field => $values],
])->values();

if ($whereNotIns->isNotEmpty()) {
$filter->push([
'bool' => [
'must_not' => $whereNotIns->all(),
],
]);
}

return $filter->isEmpty() ? null : $filter->all();
Expand Down
8 changes: 0 additions & 8 deletions tests/Integration/Engine/EngineSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public function test_search_result_can_be_filtered_with_where_clause(): void

public function test_search_result_can_be_filtered_with_where_in_clause(): void
{
if (!method_exists(Builder::class, 'whereIn')) {
$this->markTestSkipped('Method "whereIn" is not supported by current Scout version');
}

// add some mixins
factory(Client::class, rand(2, 10))->create();

Expand All @@ -82,10 +78,6 @@ public function test_search_result_can_be_filtered_with_where_in_clause(): void

public function test_search_result_can_be_filtered_with_where_not_in_clause(): void
{
if (!method_exists(Builder::class, 'whereNotIn')) {
$this->markTestSkipped('Method "whereNotIn" is not supported by current Scout version');
}

// add some mixins
factory(Client::class, rand(2, 10))->create(['email' => '[email protected]']);

Expand Down
8 changes: 0 additions & 8 deletions tests/Integration/Factories/SearchParametersFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ public function test_search_parameters_can_be_made_from_builder_with_where_filte

public function test_search_parameters_can_be_made_from_builder_with_where_in_filter(): void
{
if (!method_exists(Builder::class, 'whereIn')) {
$this->markTestSkipped('Method "whereIn" is not supported by current Scout version');
}

$model = new Client();
$builder = (new Builder($model, 'book'))->whereIn('author_id', [1, 2]);
$searchParameters = $this->searchParametersFactory->makeFromBuilder($builder);
Expand Down Expand Up @@ -119,10 +115,6 @@ public function test_search_parameters_can_be_made_from_builder_with_where_in_fi

public function test_search_parameters_can_be_made_from_builder_with_where_not_in_filter(): void
{
if (!method_exists(Builder::class, 'whereNotIn')) {
$this->markTestSkipped('Method "whereNotIn" is not supported by current Scout version');
}

$model = new Client();
$builder = (new Builder($model, 'book'))->whereNotIn('author_id', [1, 2]);
$searchParameters = $this->searchParametersFactory->makeFromBuilder($builder);
Expand Down

0 comments on commit e4ae5c6

Please sign in to comment.