public function testGetQuery()
 {
     $builder = new ElasticaQueryBuilder($this->options());
     $query = $builder->getQuery();
     $this->assertInstanceOf('Elastica\\Query', $query);
     $queryAsArray = $query->toArray();
     $this->assertInternalType('array', $queryAsArray);
     $this->assertCount(3, $queryAsArray);
     $this->assertArrayHasKey('size', $queryAsArray);
     $this->assertArrayHasKey('query', $queryAsArray);
     $this->assertArrayHasKey('aggs', $queryAsArray);
 }
Esempio n. 2
0
 public function init()
 {
     parent::init();
     $builder = new ElasticaQueryBuilder($this->options);
     /** @var \Elastica\Query $query */
     $query = $builder->getQuery();
     if (!$query) {
         $this->errors = $builder->getErrors();
         return;
     }
     /** @var \anmoroz\analytics\components\ElasticaBase $elasticaBase */
     $elasticaBase = $this->locator->get('elastica');
     $resultSet = $elasticaBase->getIndex()->search($query);
     $aggregations = $resultSet->getAggregation(ElasticaQueryBuilder::GROUP_AGGREGATION_NAME);
     $this->totalHits = $resultSet->getTotalHits();
     $this->totalTime = $resultSet->getTotalTime();
     $this->arrayIterator = new \ArrayIterator($aggregations['buckets']);
     $this->viewHelperToLocator($builder->getAggregationList());
 }