Skip to content

Commit c75fbce

Browse files
Spamerczclaude
andcommitted
fix(query): allow string type for minimumShouldMatch parameter
Elasticsearch accepts string values like "75%" or "2<90%" for minimum_should_match. Changed type from int|null to int|string|null in ElasticMatch and MultiMatch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4d6ca9d commit c75fbce

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

src/Query/ElasticMatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function __construct(
1616
private bool|int|string|null $query,
1717
private float $boost = 1.0,
1818
private \Spameri\ElasticQuery\Query\Match\Fuzziness|null $fuzziness = null,
19-
private int|null $minimumShouldMatch = null,
19+
private int|string|null $minimumShouldMatch = null,
2020
private string $operator = \Spameri\ElasticQuery\Query\Match\Operator::OR,
2121
private string|null $analyzer = null,
2222
)

src/Query/MultiMatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(
1717
private float $boost = 1.0,
1818
private \Spameri\ElasticQuery\Query\Match\Fuzziness|null $fuzziness = null,
1919
private string $type = \Spameri\ElasticQuery\Query\Match\MultiMatchType::BEST_FIELDS,
20-
private int|null $minimumShouldMatch = null,
20+
private int|string|null $minimumShouldMatch = null,
2121
private string $operator = \Spameri\ElasticQuery\Query\Match\Operator::OR,
2222
private string|null $analyzer = null,
2323
)

tests/SpameriTests/ElasticQuery/Query/ElasticMatch.phpt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,54 @@ class ElasticMatch extends \Tester\TestCase
8383
}
8484

8585

86+
public function testMinimumShouldMatchString() : void
87+
{
88+
$match = new \Spameri\ElasticQuery\Query\ElasticMatch(
89+
'name',
90+
'Avengers Endgame',
91+
1.0,
92+
null,
93+
'75%',
94+
);
95+
96+
$array = $match->toArray();
97+
98+
\Tester\Assert::same('75%', $array['match']['name']['minimum_should_match']);
99+
}
100+
101+
102+
public function testMinimumShouldMatchCombinationString() : void
103+
{
104+
$match = new \Spameri\ElasticQuery\Query\ElasticMatch(
105+
'name',
106+
'Avengers Endgame Infinity War',
107+
1.0,
108+
null,
109+
'2<90%',
110+
);
111+
112+
$array = $match->toArray();
113+
114+
\Tester\Assert::same('2<90%', $array['match']['name']['minimum_should_match']);
115+
}
116+
117+
118+
public function testMinimumShouldMatchInt() : void
119+
{
120+
$match = new \Spameri\ElasticQuery\Query\ElasticMatch(
121+
'name',
122+
'Avengers Endgame',
123+
1.0,
124+
null,
125+
2,
126+
);
127+
128+
$array = $match->toArray();
129+
130+
\Tester\Assert::same(2, $array['match']['name']['minimum_should_match']);
131+
}
132+
133+
86134
public function tearDown() : void
87135
{
88136
$ch = \curl_init();

tests/SpameriTests/ElasticQuery/Query/MultiMatch.phpt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,57 @@ class MultiMatch extends \Tester\TestCase
154154
}
155155

156156

157+
public function testMinimumShouldMatchString(): void
158+
{
159+
$multiMatch = new \Spameri\ElasticQuery\Query\MultiMatch(
160+
['title', 'description'],
161+
'search term',
162+
1.0,
163+
null,
164+
\Spameri\ElasticQuery\Query\Match\MultiMatchType::BEST_FIELDS,
165+
'75%',
166+
);
167+
168+
$array = $multiMatch->toArray();
169+
170+
\Tester\Assert::same('75%', $array['multi_match']['minimum_should_match']);
171+
}
172+
173+
174+
public function testMinimumShouldMatchCombinationString(): void
175+
{
176+
$multiMatch = new \Spameri\ElasticQuery\Query\MultiMatch(
177+
['title', 'description'],
178+
'search term query',
179+
1.0,
180+
null,
181+
\Spameri\ElasticQuery\Query\Match\MultiMatchType::BEST_FIELDS,
182+
'2<90%',
183+
);
184+
185+
$array = $multiMatch->toArray();
186+
187+
\Tester\Assert::same('2<90%', $array['multi_match']['minimum_should_match']);
188+
}
189+
190+
191+
public function testMinimumShouldMatchInt(): void
192+
{
193+
$multiMatch = new \Spameri\ElasticQuery\Query\MultiMatch(
194+
['title', 'description'],
195+
'search term',
196+
1.0,
197+
null,
198+
\Spameri\ElasticQuery\Query\Match\MultiMatchType::BEST_FIELDS,
199+
2,
200+
);
201+
202+
$array = $multiMatch->toArray();
203+
204+
\Tester\Assert::same(2, $array['multi_match']['minimum_should_match']);
205+
}
206+
207+
157208
public function testCreate(): void
158209
{
159210
$multiMatch = new \Spameri\ElasticQuery\Query\MultiMatch(

0 commit comments

Comments
 (0)