|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use Ensi\LaravelElasticQuery\Contracts\MatchOptions; |
| 4 | +use Ensi\LaravelElasticQuery\Contracts\MultiMatchOptions; |
3 | 5 | use Ensi\LaravelElasticQuerySpecification\Exceptions\InvalidQueryException; |
4 | 6 | use Ensi\LaravelElasticQuerySpecification\Filtering\AllowedFilter; |
5 | 7 | use Ensi\LaravelElasticQuerySpecification\Specification\CompositeSpecification; |
|
79 | 81 | 'between' => [['rating__lte' => 7, 'rating__gte' => 5], [1, 328]], |
80 | 82 | ]); |
81 | 83 |
|
82 | | -test('match filter', function (string $query, array $expectedIds) { |
| 84 | +test('match filter', function (string $query, ?MatchOptions $options, array $expectedIds) { |
83 | 85 | $spec = CompositeSpecification::new() |
84 | 86 | ->allowedFilters([ |
85 | | - AllowedFilter::match('name', 'search_name'), |
| 87 | + AllowedFilter::match('name', 'search_name', $options), |
86 | 88 | ]); |
87 | 89 |
|
88 | 90 | searchQuery($spec, ['filter' => ['name' => $query]])->assertDocumentIds($expectedIds); |
89 | 91 | })->with([ |
90 | | - 'single' => ['water', [150]], |
91 | | - 'multiple' => ['gloves', [319, 471]], |
| 92 | + 'single result' => ['water', null, [150]], |
| 93 | + 'multiple results' => ['gloves', null, [319, 471]], |
| 94 | + 'with options' => ['woter', MatchOptions::make(fuzziness: 'AUTO'), [150]], |
92 | 95 | ]); |
| 96 | + |
| 97 | +test('multi match filter', function (string $query, ?MultiMatchOptions $options, array $expectedIds) { |
| 98 | + $spec = CompositeSpecification::new() |
| 99 | + ->allowedFilters([ |
| 100 | + AllowedFilter::multiMatch('name', ['search_name', 'description'], $options), |
| 101 | + ]); |
| 102 | + |
| 103 | + searchQuery($spec, ['filter' => ['name' => $query]])->assertDocumentIds($expectedIds); |
| 104 | +})->with([ |
| 105 | + 'single result' => ['water', null, [150]], |
| 106 | + 'multiple results' => ['gloves', null, [319, 471]], |
| 107 | + 'with options' => ['woter', MultiMatchOptions::make(fuzziness: 'AUTO'), [150]], |
| 108 | +]); |
| 109 | + |
| 110 | +test('multi match filter priority', function () { |
| 111 | + $spec = CompositeSpecification::new() |
| 112 | + ->allowedFilters([ |
| 113 | + AllowedFilter::multiMatch('name', ['search_name^3', 'description']), |
| 114 | + ]); |
| 115 | + |
| 116 | + searchQuery($spec, ['filter' => ['name' => 'leather']])->assertDocumentOrder([319, 471]); |
| 117 | +}); |
| 118 | + |
| 119 | +test('multi match filter without fields', function () { |
| 120 | + $spec = CompositeSpecification::new() |
| 121 | + ->allowedFilters([ |
| 122 | + AllowedFilter::multiMatch('name'), |
| 123 | + ]); |
| 124 | + |
| 125 | + searchQuery($spec, ['filter' => ['name' => 'leather']])->assertDocumentOrder([319, 471]); |
| 126 | +}); |
0 commit comments