Skip to content

Commit 548b1d4

Browse files
topikitoruflin
authored andcommitted
Allow strings for setMinimumMatch in Terms query (#1151)
* Updated changelog
1 parent 62fafe0 commit 548b1d4

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file based on the
77

88
### Bugfixes
99
- Set HTTP headers on each request preventing server error if persistent connection is enabled and compression enabled and later disabled for the same connection.
10+
- Removed `int` type hinting in `setMinimumMatch` (`Terms` Query): it should also allow `string`. [#1151](https://github.com/ruflin/Elastica/pull/1151)
1011

1112
### Added
1213
- Elastica\QueryBuilder\DSL\Query::geo_distance

lib/Elastica/Query/Terms.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Terms query.
88
*
99
* @author Nicolas Ruflin <[email protected]>
10+
* @author Roberto Nygaard <[email protected]>
1011
*
1112
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
1213
*/
@@ -70,13 +71,12 @@ public function addTerm($term)
7071
/**
7172
* Sets the minimum matching values.
7273
*
73-
* @param int $minimum Minimum value
74-
*
75-
* @return $this
74+
* @param int|string $minimum Minimum value
75+
* @return $this
7676
*/
7777
public function setMinimumMatch($minimum)
7878
{
79-
return $this->setParam('minimum_match', (int) $minimum);
79+
return $this->setParam('minimum_match', $minimum);
8080
}
8181

8282
/**

test/lib/Elastica/Test/Query/TermsTest.php

+26-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,38 @@ public function testFilteredSearch()
3636
$this->assertEquals(3, $resultSet->count());
3737
}
3838

39+
public function provideMinimumArguments()
40+
{
41+
return [
42+
[
43+
3
44+
],
45+
[
46+
-2
47+
],
48+
[
49+
'75%'
50+
],
51+
[
52+
'-25%'
53+
],
54+
[
55+
'3<90%'
56+
],
57+
[
58+
'2<-25% 9<-3'
59+
]
60+
];
61+
}
62+
3963
/**
4064
* @group unit
65+
* @dataProvider provideMinimumArguments
4166
*/
42-
public function testSetMinimum()
67+
public function testSetMinimum($minimum)
4368
{
4469
$key = 'name';
4570
$terms = ['nicolas', 'ruflin'];
46-
$minimum = 2;
4771

4872
$query = new Terms($key, $terms);
4973
$query->setMinimumMatch($minimum);

0 commit comments

Comments
 (0)