Skip to content

Commit

Permalink
Add constructor to Match query
Browse files Browse the repository at this point in the history
  • Loading branch information
im-denisenko committed Jun 18, 2015
1 parent 9c9fad6 commit b6394dd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file based on the
- Methods of classes in `QueryBuilder\DSL` namespace now have exact same signatures as corresponding constructors. [#878](https://github.com/ruflin/Elastica/pull/878)
- Constructor of `Aggregation\Filter` now accepts filter as second parameter [#878](https://github.com/ruflin/Elastica/pull/878)
- Constructor of `Filter\AbstractMulti` (`BoolAnd`, `BooldOr`) now accepts array of filters as parameter [#878](https://github.com/ruflin/Elastica/pull/878)
- Constructor of `Query\Match` now accepts arguments [#878](https://github.com/ruflin/Elastica/pull/878)

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

Expand Down
11 changes: 11 additions & 0 deletions lib/Elastica/Query/Match.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ class Match extends AbstractQuery
const ZERO_TERM_NONE = 'none';
const ZERO_TERM_ALL = 'all';

/**
* @param string $field
* @param mixed $values
*/
public function __construct($field = null, $values = null)
{
if ($field !== null && $values !== null) {
$this->setParam($field, $values);
}
}

/**
* Sets a param for the message array.
*
Expand Down
15 changes: 4 additions & 11 deletions lib/Elastica/QueryBuilder/DSL/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,14 @@ public function getType()
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
*
* @param null|string $field
* @param null|string $value
* @param string $field
* @param mixed $values
*
* @return Match
*/
public function match($field = null, $value = null)
public function match($field = null, $values = null)
{
if ($field !== null && $value !== null) {
$match = new Match();
$match->setParam($field, $value);

return $match;
}

return new Match();
return new Match($field, $values);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions test/lib/Elastica/Test/Query/MatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,21 @@ public function testMatchFuzzinessType()
$parameters = $query->getParam($field);
$this->assertEquals($fuzziness, $parameters['fuzziness']);
}

/**
* @group unit
*/
public function testConstruct()
{
$match = new Match(null, 'values');
$this->assertEquals(array('match' => array()), $match->toArray());

$match = new Match('field', null);
$this->assertEquals(array('match' => array()), $match->toArray());

$match1 = new Match('field', 'values');
$match2 = new Match();
$match2->setField('field', 'values');
$this->assertEquals($match1->toArray(), $match2->toArray());
}
}
1 change: 1 addition & 0 deletions test/lib/Elastica/Test/QueryBuilder/DSL/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function testInterface()
$this->_assertImplemented($queryDSL, 'has_child', 'Elastica\Query\HasChild', array(new Match()));
$this->_assertImplemented($queryDSL, 'has_parent', 'Elastica\Query\HasParent', array(new Match(), 'type'));
$this->_assertImplemented($queryDSL, 'ids', 'Elastica\Query\Ids', array('type', array()));
$this->_assertImplemented($queryDSL, 'match', 'Elastica\Query\Match', array('field', 'values'));
$this->_assertImplemented($queryDSL, 'match_all', 'Elastica\Query\MatchAll', array());
$this->_assertImplemented($queryDSL, 'more_like_this', 'Elastica\Query\MoreLikeThis', array());
$this->_assertImplemented($queryDSL, 'multi_match', 'Elastica\Query\MultiMatch', array());
Expand Down

0 comments on commit b6394dd

Please sign in to comment.