/** * Tests the Nested Query. */ public function testNestedQuery() { $this->specify('nested query was created', function () { $query = $this->queryBuilder->createNestedQuery(); verify($query)->isInstanceOf('\\Nord\\Lumen\\Elasticsearch\\Search\\Query\\Joining\\NestedQuery'); }); $this->specify('nested query format', function () { $query = $this->queryBuilder->createNestedQuery(); $query->setPath('doc')->setQuery($this->queryBuilder->createBoolQuery()->addMust($this->queryBuilder->createMatchQuery()->setField('field')->setValue('value'))); $array = $query->toArray(); verify($array)->equals(['nested' => ['path' => 'doc', 'query' => ['bool' => ['must' => [['match' => ['field' => 'value']]]]]]]); }); $this->specify('nested query format with score_mode', function () { $query = $this->queryBuilder->createNestedQuery(); $query->setPath('doc')->setQuery($this->queryBuilder->createBoolQuery()->addMust($this->queryBuilder->createMatchQuery()->setField('field')->setValue('value')))->setScoreMode(\Nord\Lumen\Elasticsearch\Search\Query\Joining\NestedQuery::SCORE_MODE_AVG); $array = $query->toArray(); verify($array)->equals(['nested' => ['path' => 'doc', 'query' => ['bool' => ['must' => [['match' => ['field' => 'value']]]]], 'score_mode' => 'avg']]); }); }
/** * Tests the Match Query. */ public function testMatchQuery() { $this->specify('match query was created', function () { $query = $this->queryBuilder->createMatchQuery(); verify($query)->isInstanceOf('\\Nord\\Lumen\\Elasticsearch\\Search\\Query\\FullText\\MatchQuery'); }); $this->specify('match query format', function () { $query = $this->queryBuilder->createMatchQuery(); $query->setField('field')->setValue('value'); $array = $query->toArray(); verify($array)->equals(['match' => ['field' => 'value']]); }); $this->specify('match query format with operator', function () { $query = $this->queryBuilder->createMatchQuery(); $query->setField('field')->setValue('value')->setOperator('and'); $array = $query->toArray(); verify($array)->equals(['match' => ['field' => ['query' => 'value', 'operator' => 'and']]]); }); $this->specify('match query format with zero_terms_query', function () { $query = $this->queryBuilder->createMatchQuery(); $query->setField('field')->setValue('value')->setZeroTermsQuery('none'); $array = $query->toArray(); verify($array)->equals(['match' => ['field' => ['query' => 'value', 'zero_terms_query' => 'none']]]); }); $this->specify('match query format with cutoff_frequency', function () { $query = $this->queryBuilder->createMatchQuery(); $query->setField('field')->setValue('value')->setCutOffFrequency(0.001); $array = $query->toArray(); verify($array)->equals(['match' => ['field' => ['query' => 'value', 'cutoff_frequency' => 0.001]]]); }); $this->specify('match query format with type', function () { $query = $this->queryBuilder->createMatchQuery(); $query->setField('field')->setValue('value')->setType('phrase'); $array = $query->toArray(); verify($array)->equals(['match' => ['field' => ['query' => 'value', 'type' => 'phrase']]]); }); $this->specify('match query format with type and slop', function () { $query = $this->queryBuilder->createMatchQuery(); $query->setField('field')->setValue('value')->setType('phrase')->setSlop(0); $array = $query->toArray(); verify($array)->equals(['match' => ['field' => ['query' => 'value', 'type' => 'phrase', 'slop' => 0]]]); }); $this->specify('match query format with type and slop and max_expansions', function () { $query = $this->queryBuilder->createMatchQuery(); $query->setField('field')->setValue('value')->setType('phrase_prefix')->setMaxExpansions(10); $array = $query->toArray(); verify($array)->equals(['match' => ['field' => ['query' => 'value', 'type' => 'phrase_prefix', 'max_expansions' => 10]]]); }); $this->specify('match query format with analyzer', function () { $query = $this->queryBuilder->createMatchQuery(); $query->setField('field')->setValue('value')->setAnalyzer('custom_analyzer'); $array = $query->toArray(); verify($array)->equals(['match' => ['field' => ['query' => 'value', 'analyzer' => 'custom_analyzer']]]); }); }