Skip to content

Commit 7195c3c

Browse files
committed
Add constructor to Match query
1 parent f249cfe commit 7195c3c

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file based on the
1818
- Methods of classes in `QueryBuilder\DSL` namespace now have exact same signatures as corresponding constructors. [#878](https://github.com/ruflin/Elastica/pull/878)
1919
- Constructor of `Aggregation\Filter` now accepts filter as second parameter [#878](https://github.com/ruflin/Elastica/pull/878)
2020
- Constructor of `Filter\AbstractMulti` (`BoolAnd`, `BooldOr`) now accepts array of filters as parameter [#878](https://github.com/ruflin/Elastica/pull/878)
21+
- Constructor of `Query\Match` now accepts arguments [#878](https://github.com/ruflin/Elastica/pull/878)
2122

2223
## [2.1.0](https://github.com/ruflin/Elastica/releases/tag/2.1.0) - 2015-06-01
2324

lib/Elastica/Query/Match.php

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ class Match extends AbstractQuery
1414
const ZERO_TERM_NONE = 'none';
1515
const ZERO_TERM_ALL = 'all';
1616

17+
/**
18+
* @param string $field
19+
* @param mixed $values
20+
*/
21+
public function __construct($field = null, $values = null)
22+
{
23+
if ($field !== null && $values !== null) {
24+
$this->setParam($field, $values);
25+
}
26+
}
27+
1728
/**
1829
* Sets a param for the message array.
1930
*

lib/Elastica/QueryBuilder/DSL/Query.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,14 @@ public function getType()
5656
*
5757
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
5858
*
59-
* @param null|string $field
60-
* @param null|string $value
59+
* @param string $field
60+
* @param mixed $values
6161
*
6262
* @return Match
6363
*/
64-
public function match($field = null, $value = null)
64+
public function match($field = null, $values = null)
6565
{
66-
if ($field !== null && $value !== null) {
67-
$match = new Match();
68-
$match->setParam($field, $value);
69-
70-
return $match;
71-
}
72-
73-
return new Match();
66+
return new Match($field, $values);
7467
}
7568

7669
/**

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

+17
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,21 @@ public function testMatchFuzzinessType()
319319
$parameters = $query->getParam($field);
320320
$this->assertEquals($fuzziness, $parameters['fuzziness']);
321321
}
322+
323+
/**
324+
* @group unit
325+
*/
326+
public function testConstruct()
327+
{
328+
$match = new Match(null, 'values');
329+
$this->assertEquals(array('match' => array()), $match->toArray());
330+
331+
$match = new Match('field', null);
332+
$this->assertEquals(array('match' => array()), $match->toArray());
333+
334+
$match1 = new Match('field', 'values');
335+
$match2 = new Match();
336+
$match2->setField('field', 'values');
337+
$this->assertEquals($match1->toArray(), $match2->toArray());
338+
}
322339
}

test/lib/Elastica/Test/QueryBuilder/DSL/QueryTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function testInterface()
4949
$this->_assertImplemented($queryDSL, 'has_child', 'Elastica\Query\HasChild', array(new Match()));
5050
$this->_assertImplemented($queryDSL, 'has_parent', 'Elastica\Query\HasParent', array(new Match(), 'type'));
5151
$this->_assertImplemented($queryDSL, 'ids', 'Elastica\Query\Ids', array('type', array()));
52+
$this->_assertImplemented($queryDSL, 'match', 'Elastica\Query\Match', array('field', 'values'));
5253
$this->_assertImplemented($queryDSL, 'match_all', 'Elastica\Query\MatchAll', array());
5354
$this->_assertImplemented($queryDSL, 'more_like_this', 'Elastica\Query\MoreLikeThis', array());
5455
$this->_assertImplemented($queryDSL, 'multi_match', 'Elastica\Query\MultiMatch', array());

0 commit comments

Comments
 (0)