Exemplo n.º 1
1
 private function makeElasticQuery()
 {
     $exceptedQuery = new \Elastica\Query();
     $aggregationFilters = new \Elastica\Aggregation\Filters("emotion");
     $negative = new \Elastica\Filter\Range('valeur', array('lt' => 0));
     $aggregationFilters->addFilter($negative, 'negative');
     $neutral = new \Elastica\Filter\Range('valeur', array('lt' => 1, 'gt' => -1));
     $aggregationFilters->addFilter($neutral, 'neutral');
     $positive = new \Elastica\Filter\Range('valeur', array('gt' => 0));
     $aggregationFilters->addFilter($positive, 'positive');
     $dateHisto = new \Elastica\Aggregation\DateHistogram('nb', 'date', 'month');
     $aggregationFilters->addAggregation($dateHisto);
     $exceptedQuery->addAggregation($aggregationFilters);
     return $exceptedQuery;
 }
Exemplo n.º 2
0
 public function getColorAttributes($allArticles, $elasticIndexVariants, $colors)
 {
     foreach ($allArticles as $article) {
         $article_ids[] = $article->getId();
     }
     $boolQuery = new \Elastica\Query\BoolQuery();
     $articleRefQuery = new \Elastica\Query\Terms();
     $articleRefQuery->setTerms('articleRef', $article_ids);
     $boolQuery->addMust($articleRefQuery);
     $query = new \Elastica\Query();
     $query->setQuery($boolQuery);
     $agg2 = new \Elastica\Aggregation\Terms("variantsattr");
     $agg2->setField('variantvalues.otherTerms');
     $agg2->setSize(50);
     $filter = new \Elastica\Filter\Term();
     $filter->setTerm('attributeRef', 1);
     $agg4 = new \Elastica\Aggregation\Filters('filterColor');
     $agg4->addFilter($filter);
     $agg4->addAggregation($agg2);
     $cAgg = new \Elastica\Aggregation\Nested('colors', 'variantvalues');
     $cAgg->addAggregation($agg4);
     $query->addAggregation($cAgg);
     $aggResult = $elasticIndexVariants->search($query);
     $colors = $aggResult->getAggregations();
     $result = [];
     foreach ($colors['colors']['filterColor']['buckets'][0]['variantsattr']['buckets'] as $color) {
         $result[] = $color;
     }
     return $result;
 }