Skip to content
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
2 changes: 1 addition & 1 deletion src/Query/ElasticMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion src/Query/MultiMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion src/Query/Nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function toArray(): array
{
$queryArray = $this->query->toArray();

if (count($queryArray) === 0) {
if (\count($queryArray) === 0) {
$queryArray = [
'bool' => [],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class AggregationCollection extends \Tester\TestCase
null,
null,
null,
null,
$collection,
);

Expand Down
1 change: 1 addition & 0 deletions tests/SpameriTests/ElasticQuery/ElasticQuery.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ElasticQuery extends \Tester\TestCase
$term
)
),
NULL,
new \Spameri\ElasticQuery\Options\SortCollection(
new \Spameri\ElasticQuery\Options\Sort(
'year',
Expand Down
48 changes: 48 additions & 0 deletions tests/SpameriTests/ElasticQuery/Query/ElasticMatch.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
51 changes: 51 additions & 0 deletions tests/SpameriTests/ElasticQuery/Query/MultiMatch.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions tests/SpameriTests/ElasticQuery/Query/Nested.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}


Expand All @@ -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']);
}


Expand All @@ -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']));
}


Expand Down
Loading