diff --git a/src/Query/ElasticMatch.php b/src/Query/ElasticMatch.php index 71ec3bd..185d47c 100644 --- a/src/Query/ElasticMatch.php +++ b/src/Query/ElasticMatch.php @@ -16,7 +16,7 @@ public function __construct( private bool|int|string|null $query, private float $boost = 1.0, private \Spameri\ElasticQuery\Query\Match\Fuzziness|null $fuzziness = null, - private int|null $minimumShouldMatch = null, + private int|string|null $minimumShouldMatch = null, private string $operator = \Spameri\ElasticQuery\Query\Match\Operator::OR, private string|null $analyzer = null, ) diff --git a/src/Query/MultiMatch.php b/src/Query/MultiMatch.php index 77df568..882a7e0 100644 --- a/src/Query/MultiMatch.php +++ b/src/Query/MultiMatch.php @@ -17,7 +17,7 @@ public function __construct( private float $boost = 1.0, private \Spameri\ElasticQuery\Query\Match\Fuzziness|null $fuzziness = null, private string $type = \Spameri\ElasticQuery\Query\Match\MultiMatchType::BEST_FIELDS, - private int|null $minimumShouldMatch = null, + private int|string|null $minimumShouldMatch = null, private string $operator = \Spameri\ElasticQuery\Query\Match\Operator::OR, private string|null $analyzer = null, ) diff --git a/src/Query/Nested.php b/src/Query/Nested.php index 4be9ed6..532f81a 100644 --- a/src/Query/Nested.php +++ b/src/Query/Nested.php @@ -34,7 +34,7 @@ public function toArray(): array { $queryArray = $this->query->toArray(); - if (count($queryArray) === 0) { + if (\count($queryArray) === 0) { $queryArray = [ 'bool' => [], ]; diff --git a/tests/SpameriTests/ElasticQuery/Aggregation/AggregationCollection.phpt b/tests/SpameriTests/ElasticQuery/Aggregation/AggregationCollection.phpt index f998dda..bf7d0da 100644 --- a/tests/SpameriTests/ElasticQuery/Aggregation/AggregationCollection.phpt +++ b/tests/SpameriTests/ElasticQuery/Aggregation/AggregationCollection.phpt @@ -149,6 +149,7 @@ class AggregationCollection extends \Tester\TestCase null, null, null, + null, $collection, ); diff --git a/tests/SpameriTests/ElasticQuery/ElasticQuery.phpt b/tests/SpameriTests/ElasticQuery/ElasticQuery.phpt index ea2b364..aac3eb8 100644 --- a/tests/SpameriTests/ElasticQuery/ElasticQuery.phpt +++ b/tests/SpameriTests/ElasticQuery/ElasticQuery.phpt @@ -79,6 +79,7 @@ class ElasticQuery extends \Tester\TestCase $term ) ), + NULL, new \Spameri\ElasticQuery\Options\SortCollection( new \Spameri\ElasticQuery\Options\Sort( 'year', diff --git a/tests/SpameriTests/ElasticQuery/Query/ElasticMatch.phpt b/tests/SpameriTests/ElasticQuery/Query/ElasticMatch.phpt index 39230cf..69198fe 100644 --- a/tests/SpameriTests/ElasticQuery/Query/ElasticMatch.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/ElasticMatch.phpt @@ -83,6 +83,54 @@ class ElasticMatch extends \Tester\TestCase } + public function testMinimumShouldMatchString() : void + { + $match = new \Spameri\ElasticQuery\Query\ElasticMatch( + 'name', + 'Avengers Endgame', + 1.0, + null, + '75%', + ); + + $array = $match->toArray(); + + \Tester\Assert::same('75%', $array['match']['name']['minimum_should_match']); + } + + + public function testMinimumShouldMatchCombinationString() : void + { + $match = new \Spameri\ElasticQuery\Query\ElasticMatch( + 'name', + 'Avengers Endgame Infinity War', + 1.0, + null, + '2<90%', + ); + + $array = $match->toArray(); + + \Tester\Assert::same('2<90%', $array['match']['name']['minimum_should_match']); + } + + + public function testMinimumShouldMatchInt() : void + { + $match = new \Spameri\ElasticQuery\Query\ElasticMatch( + 'name', + 'Avengers Endgame', + 1.0, + null, + 2, + ); + + $array = $match->toArray(); + + \Tester\Assert::same(2, $array['match']['name']['minimum_should_match']); + } + + public function tearDown() : void { $ch = \curl_init(); diff --git a/tests/SpameriTests/ElasticQuery/Query/MultiMatch.phpt b/tests/SpameriTests/ElasticQuery/Query/MultiMatch.phpt index 72e09e5..91f2ef0 100644 --- a/tests/SpameriTests/ElasticQuery/Query/MultiMatch.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/MultiMatch.phpt @@ -154,6 +154,57 @@ class MultiMatch extends \Tester\TestCase } + public function testMinimumShouldMatchString(): void + { + $multiMatch = new \Spameri\ElasticQuery\Query\MultiMatch( + ['title', 'description'], + 'search term', + 1.0, + null, + \Spameri\ElasticQuery\Query\Match\MultiMatchType::BEST_FIELDS, + '75%', + ); + + $array = $multiMatch->toArray(); + + \Tester\Assert::same('75%', $array['multi_match']['minimum_should_match']); + } + + + public function testMinimumShouldMatchCombinationString(): void + { + $multiMatch = new \Spameri\ElasticQuery\Query\MultiMatch( + ['title', 'description'], + 'search term query', + 1.0, + null, + \Spameri\ElasticQuery\Query\Match\MultiMatchType::BEST_FIELDS, + '2<90%', + ); + + $array = $multiMatch->toArray(); + + \Tester\Assert::same('2<90%', $array['multi_match']['minimum_should_match']); + } + + + public function testMinimumShouldMatchInt(): void + { + $multiMatch = new \Spameri\ElasticQuery\Query\MultiMatch( + ['title', 'description'], + 'search term', + 1.0, + null, + \Spameri\ElasticQuery\Query\Match\MultiMatchType::BEST_FIELDS, + 2, + ); + + $array = $multiMatch->toArray(); + + \Tester\Assert::same(2, $array['multi_match']['minimum_should_match']); + } + + public function testCreate(): void { $multiMatch = new \Spameri\ElasticQuery\Query\MultiMatch( diff --git a/tests/SpameriTests/ElasticQuery/Query/Nested.phpt b/tests/SpameriTests/ElasticQuery/Query/Nested.phpt index ff0debf..ed9d044 100644 --- a/tests/SpameriTests/ElasticQuery/Query/Nested.phpt +++ b/tests/SpameriTests/ElasticQuery/Query/Nested.phpt @@ -31,7 +31,7 @@ class Nested extends \Tester\TestCase \Tester\Assert::true(isset($array['nested'])); \Tester\Assert::same('comments', $array['nested']['path']); - \Tester\Assert::true(isset($array['nested']['query']['bool'])); + \Tester\Assert::true(isset($array['nested']['query'][0]['bool'])); } @@ -47,8 +47,8 @@ class Nested extends \Tester\TestCase $array = $nested->toArray(); \Tester\Assert::same('comments', $array['nested']['path']); - \Tester\Assert::true(isset($array['nested']['query']['bool']['bool']['must'])); - \Tester\Assert::count(1, $array['nested']['query']['bool']['bool']['must']); + \Tester\Assert::true(isset($array['nested']['query'][0]['bool']['must'])); + \Tester\Assert::count(1, $array['nested']['query'][0]['bool']['must']); } @@ -74,8 +74,8 @@ class Nested extends \Tester\TestCase $array = $nested->toArray(); - \Tester\Assert::true(isset($array['nested']['query']['bool']['bool']['must'])); - \Tester\Assert::true(isset($array['nested']['query']['bool']['bool']['should'])); + \Tester\Assert::true(isset($array['nested']['query'][0]['bool']['must'])); + \Tester\Assert::true(isset($array['nested']['query'][0]['bool']['should'])); }