Skip to content

Commit

Permalink
Merge conflict changes.txt resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin committed Mar 15, 2014
2 parents 6441851 + 3e6d2f2 commit ce167ac
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 20 deletions.
4 changes: 4 additions & 0 deletions changes.txt
@@ -1,5 +1,9 @@
CHANGES

2014-03-13
- Added missing query options for MultiMatch (operator, minimum_should_match, zero_terms_query, cutoff_frequency, type, fuzziness, prefix_length, max_expansions, analyzer) #569
- Added missing query options for Match (zero_terms_query, cutoff_frequency) #569

2014-03-11
- Fixed request body reuse in http transport #567

Expand Down
30 changes: 30 additions & 0 deletions lib/Elastica/Query/Match.php
Expand Up @@ -8,10 +8,14 @@
* @category Xodoa
* @package Elastica
* @author F21
* @author WONG Wing Lun <luiges90@gmail.com>
* @link http://www.elasticsearch.org/guide/reference/query-dsl/match-query.html
*/
class Match extends AbstractQuery
{
const ZERO_TERM_NONE = 'none';
const ZERO_TERM_ALL = 'all';

/**
* Sets a param for the message array
*
Expand Down Expand Up @@ -165,4 +169,30 @@ public function setFieldMaxExpansions($field, $maxExpansions)
{
return $this->setFieldParam($field, 'max_expansions', (int) $maxExpansions);
}

/**
* Set zero terms query
*
* If not set, default to 'none'
*
* @param string $field
* @param string $zeroTermQuery
* @return \Elastica\Query\Match
*/
public function setFieldZeroTermsQuery($field, $zeroTermQuery = 'none')
{
return $this->setFieldParam($field, 'zero_terms_query', $zeroTermQuery);
}

/**
* Set cutoff frequency
*
* @param string $field
* @param float $cutoffFrequency
* @return \Elastica\Query\Match
*/
public function setFieldCutoffFrequency($field, $cutoffFrequency)
{
return $this->setFieldParam($field, 'cutoff_frequency', $cutoffFrequency);
}
}
117 changes: 117 additions & 0 deletions lib/Elastica/Query/MultiMatch.php
Expand Up @@ -8,10 +8,23 @@
* @category Xodoa
* @package Elastica
* @author Rodolfo Adhenawer Campagnoli Moraes <adhenawer@gmail.com>
* @author Wong Wing Lun <luiges90@gmail.com>
* @author Tristan Maindron <tmaindron@gmail.com>
* @link http://www.elasticsearch.org/guide/reference/query-dsl/multi-match-query.html
*/
class MultiMatch extends AbstractQuery
{
const TYPE_BEST_FIELDS = 'best_fields';
const TYPE_MOST_FIELDS = 'most_fields';
const TYPE_CROSS_FIELDS = 'cross_fields';
const TYPE_PHRASE = 'phrase';
const TYPE_PHRASE_PREFIX = 'phrase_prefix';

const OPERATOR_OR = 'or';
const OPERATOR_AND = 'and';

const ZERO_TERM_NONE = 'none';
const ZERO_TERM_ALL = 'all';

/**
* Sets the query
Expand Down Expand Up @@ -60,4 +73,108 @@ public function setTieBreaker($tieBreaker = 0.0)
{
return $this->setParam('tie_breaker', $tieBreaker);
}

/**
* Sets operator for Match Query
*
* If not set, defaults to 'or'
*
* @param string $operator
* @return \Elastica\Query\MultiMatch Current object
*/
public function setOperator($operator = 'or')
{
return $this->setParam('operator', $operator);
}

/**
* Set field minimum should match for Match Query
*
* @param int $minimumShouldMatch
* @return \Elastica\Query\Match
*/
public function setMinimumShouldMatch($minimumShouldMatch)
{
return $this->setParam('minimum_should_match', (int) $minimumShouldMatch);
}

/**
* Set zero terms query for Match Query
*
* If not set, default to 'none'
*
* @param string $zeroTermQuery
* @return \Elastica\Query\Match
*/
public function setZeroTermsQuery($zeroTermQuery = 'none')
{
return $this->setParam('zero_terms_query', $zeroTermQuery);
}

/**
* Set cutoff frequency for Match Query
*
* @param float $cutoffFrequency
* @return \Elastica\Query\Match
*/
public function setCutoffFrequency($cutoffFrequency)
{
return $this->setParam('cutoff_frequency', $cutoffFrequency);
}

/**
* Set type
*
* @param string $field
* @param string $type
* @return \Elastica\Query\Match
*/
public function setType($type)
{
return $this->setParam('type', $type);
}

/**
* Set fuzziness
*
* @param float $fuzziness
* @return \Elastica\Query\Match
*/
public function setFuzziness($fuzziness)
{
return $this->setParam('fuzziness', (float) $fuzziness);
}

/**
* Set prefix length
*
* @param int $prefixLength
* @return \Elastica\Query\Match
*/
public function setPrefixLength($prefixLength)
{
return $this->setParam('prefix_length', (int) $prefixLength);
}

/**
* Set max expansions
*
* @param int $maxExpansions
* @return \Elastica\Query\Match
*/
public function setMaxExpansions($maxExpansions)
{
return $this->setParam('max_expansions', (int) $maxExpansions);
}

/**
* Set analyzer
*
* @param string $analyzer
* @return \Elastica\Query\Match
*/
public function setAnalyzer($analyzer)
{
return $this->setParam('analyzer', $analyzer);
}
}
21 changes: 21 additions & 0 deletions test/lib/Elastica/Test/Query/MatchTest.php
Expand Up @@ -84,6 +84,27 @@ public function testMatch()
$this->assertEquals(4, $resultSet->count());
}

public function testMatchZeroTerm()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('test');
$doc = new Document(1, array('name' => 'Basel-Stadt'));
$type->addDocument($doc);
$doc = new Document(2, array('name' => 'New York'));
$type->addDocument($doc);
$index->refresh();

$query = new Match();
$query->setFieldQuery('name', '');
$query->setFieldZeroTermsQuery('name', Match::ZERO_TERM_ALL);

$resultSet = $index->search($query);

$this->assertEquals(2, $resultSet->count());
}

public function testMatchPhrase()
{
$client = $this->_getClient();
Expand Down

0 comments on commit ce167ac

Please sign in to comment.