/** * Tests the HasChild Query. */ public function testHasChildQuery() { $this->specify('hasChild query was created', function () { $query = $this->queryBuilder->createHasChildQuery(); verify($query)->isInstanceOf('\\Nord\\Lumen\\Elasticsearch\\Search\\Query\\Joining\\HasChildQuery'); }); $this->specify('hasChild query format', function () { $query = $this->queryBuilder->createHasChildQuery(); $query->setType('doc')->setQuery($this->queryBuilder->createBoolQuery()->addMust($this->queryBuilder->createTermsQuery()->setField('id')->setValues(['ID1', 'ID2']))); $array = $query->toArray(); verify($array)->equals(['has_child' => ['type' => 'doc', 'query' => ['bool' => ['must' => [['terms' => ['id' => ['ID1', 'ID2']]]]]]]]); }); $this->specify('hasChild query format with score_mode', function () { $query = $this->queryBuilder->createHasChildQuery(); $query->setType('doc')->setQuery($this->queryBuilder->createBoolQuery()->addMust($this->queryBuilder->createTermsQuery()->setField('id')->setValues(['ID1', 'ID2'])))->setScoreMode(\Nord\Lumen\Elasticsearch\Search\Query\Joining\HasChildQuery::SCORE_MODE_SUM); $array = $query->toArray(); verify($array)->equals(['has_child' => ['type' => 'doc', 'query' => ['bool' => ['must' => [['terms' => ['id' => ['ID1', 'ID2']]]]]], 'score_mode' => 'sum']]); }); $this->specify('hasChild query format with min_children', function () { $query = $this->queryBuilder->createHasChildQuery(); $query->setType('doc')->setQuery($this->queryBuilder->createBoolQuery()->addMust($this->queryBuilder->createTermsQuery()->setField('id')->setValues(['ID1', 'ID2'])))->setMinChildren(2); $array = $query->toArray(); verify($array)->equals(['has_child' => ['type' => 'doc', 'query' => ['bool' => ['must' => [['terms' => ['id' => ['ID1', 'ID2']]]]]], 'min_children' => 2]]); }); $this->specify('hasChild query format with max_children', function () { $query = $this->queryBuilder->createHasChildQuery(); $query->setType('doc')->setQuery($this->queryBuilder->createBoolQuery()->addMust($this->queryBuilder->createTermsQuery()->setField('id')->setValues(['ID1', 'ID2'])))->setMaxChildren(10); $array = $query->toArray(); verify($array)->equals(['has_child' => ['type' => 'doc', 'query' => ['bool' => ['must' => [['terms' => ['id' => ['ID1', 'ID2']]]]]], 'max_children' => 10]]); }); }
/** * Tests the Terms Query. */ public function testTermsQuery() { $this->specify('terms query was created', function () { $query = $this->queryBuilder->createTermsQuery(); verify($query)->isInstanceOf('\\Nord\\Lumen\\Elasticsearch\\Search\\Query\\TermLevel\\TermsQuery'); }); $this->specify('terms query format', function () { $query = $this->queryBuilder->createTermsQuery(); $query->setField('field')->setValues(['val1', 'val2']); $array = $query->toArray(); verify($array)->equals(['terms' => ['field' => ['val1', 'val2']]]); }); }