-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for using pagination with custom query in Scout Builder. (#290)
* Add limit handling to SearchFactory Enhanced the SearchFactory to handle 'limit' from the builder and set the search size accordingly. Also included unit tests to verify limit handling and compatibility with pagination options. * Refactor search options handling in SearchFactory Simplify and centralize option preparation by introducing the `prepareOptions` and `supportedOptions` methods in `SearchFactory`. Adjust tests to align with the new logic, ensuring size and from parameters are correctly set and prioritized. * Fix CI report * Add changelog and update documentation * Update changelog
- Loading branch information
Showing
4 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Unit\ElasticSearch; | ||
|
||
use App\Product; | ||
use Laravel\Scout\Builder; | ||
use Matchish\ScoutElasticSearch\ElasticSearch\SearchFactory; | ||
use Tests\TestCase; | ||
|
||
class SearchFactoryTest extends TestCase | ||
{ | ||
public function test_limit_set_in_builder(): void | ||
{ | ||
$builder = new Builder(new Product(), '*'); | ||
$builder->take($expectedSize = 50); | ||
|
||
$search = SearchFactory::create($builder); | ||
|
||
$this->assertEquals($expectedSize, $search->getSize()); | ||
} | ||
|
||
public function test_limit_compatible_with_pagination(): void | ||
{ | ||
$builder = new Builder(new Product(), '*'); | ||
$builder->take(30); | ||
|
||
$search = SearchFactory::create($builder, [ | ||
'from' => 0, | ||
'size' => $expectedSize = 50, | ||
]); | ||
|
||
$this->assertEquals($expectedSize, $search->getSize()); | ||
} | ||
|
||
public function test_size_set_in_options_dont_take_effect(): void | ||
{ | ||
$builder = new Builder(new Product(), '*'); | ||
$builder->take($expectedSize = 30) | ||
->options([ | ||
'size' => 100, | ||
]); | ||
|
||
$search = SearchFactory::create($builder); | ||
|
||
$this->assertEquals($expectedSize, $search->getSize()); | ||
} | ||
|
||
public function test_from_set_in_options_take_effect(): void | ||
{ | ||
$builder = new Builder(new Product(), '*'); | ||
$builder->options([ | ||
'from' => $expectedFrom = 100, | ||
]); | ||
|
||
$search = SearchFactory::create($builder); | ||
|
||
$this->assertEquals($expectedFrom, $search->getFrom()); | ||
} | ||
|
||
public function test_both_parameters_dont_take_effect_on_pagination(): void | ||
{ | ||
$builder = new Builder(new Product(), '*'); | ||
$builder->options([ | ||
'from' => 250, | ||
]) | ||
->take(30); | ||
|
||
$search = SearchFactory::create($builder, [ | ||
'from' => $expectedFrom = 100, | ||
'size' => $expectedSize = 50, | ||
]); | ||
|
||
$this->assertEquals($expectedSize, $search->getSize()); | ||
$this->assertEquals($expectedFrom, $search->getFrom()); | ||
} | ||
} |