public function testToArray() { $field = 'test'; $testQuery = 'Nicolas Ruflin'; $type = 'phrase'; $operator = 'and'; $analyzer = 'myanalyzer'; $boost = 2.0; $minimumShouldMatch = 2; $fuzziness = 0.3; $fuzzyRewrite = 'constant_score_boolean'; $prefixLength = 3; $maxExpansions = 12; $query = new Match(); $query->setFieldQuery($field, $testQuery); $query->setFieldType($field, $type); $query->setFieldOperator($field, $operator); $query->setFieldAnalyzer($field, $analyzer); $query->setFieldBoost($field, $boost); $query->setFieldMinimumShouldMatch($field, $minimumShouldMatch); $query->setFieldFuzziness($field, $fuzziness); $query->setFieldFuzzyRewrite($field, $fuzzyRewrite); $query->setFieldPrefixLength($field, $prefixLength); $query->setFieldMaxExpansions($field, $maxExpansions); $expectedArray = array('match' => array($field => array('query' => $testQuery, 'type' => $type, 'operator' => $operator, 'analyzer' => $analyzer, 'boost' => $boost, 'minimum_should_match' => $minimumShouldMatch, 'fuzziness' => $fuzziness, 'fuzzy_rewrite' => $fuzzyRewrite, 'prefix_length' => $prefixLength, 'max_expansions' => $maxExpansions))); $this->assertEquals($expectedArray, $query->toArray()); }
/** * Find all documents where the values are matched in the field. The type option * allows you to specify the type of match, can be either phrase or phrase_prefix. * * The phrase match analyzes the text and creates a phrase query out of the * analyzed text. * * The phrase prefix match is the same as phrase, except that it allows for * prefix matches on the last term in the text. * * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html * * @param string $field The field to search in the index * @param string $query The values to search for * @param string $type The match type * @param bool $fuzzy Set whether the match should be fuzzy * @return Query */ public function match($field, $query, $type = 'phrase', $fuzzy = false) { $match = new Match(); $match->setFieldQuery($field, $query); $match->setFieldType($field, $type); if ($fuzzy) { $match->setFieldFuzziness($field, 'AUTO'); } $query = $this->newQuery($match); $this->query[] = $query; return $query; }
public function testMatchFuzzinessType() { $field = 'test'; $query = new Match(); $fuzziness = "AUTO"; $query->setFieldFuzziness($field, $fuzziness); $parameters = $query->getParam($field); $this->assertEquals($fuzziness, $parameters['fuzziness']); $fuzziness = 0.3; $query->setFieldFuzziness($field, $fuzziness); $parameters = $query->getParam($field); $this->assertEquals($fuzziness, $parameters['fuzziness']); }