Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     $aggregation = new StatsAggregation('price');
     $field = $this->fieldMapping->getPriceField($context);
     $aggregation->setField($field);
     $search->addAggregation($aggregation);
 }
 /**
  * {@inheritdoc}
  */
 public function preProcessSearch(Search $search, Search $relatedSearch, FilterState $state = null)
 {
     $name = $state ? $state->getName() : $this->getField();
     $agg = new TermsAggregation($name);
     $agg->setField($this->getField());
     $search->addAggregation($agg);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     $aggregation = new TermsAggregation('manufacturer');
     $aggregation->setField('manufacturer.id');
     $aggregation->addParameter('size', self::AGGREGATION_SIZE);
     $search->addAggregation($aggregation);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     /** @var ProductAttributeFacet $criteriaPart */
     $field = 'attributes.core.' . $criteriaPart->getField();
     $this->criteriaParts[] = $criteriaPart;
     switch ($criteriaPart->getMode()) {
         case ProductAttributeFacet::MODE_VALUE_LIST_RESULT:
         case ProductAttributeFacet::MODE_RADIO_LIST_RESULT:
             $aggregation = new TermsAggregation($criteriaPart->getName());
             $aggregation->setField($field);
             break;
         case ProductAttributeFacet::MODE_BOOLEAN_RESULT:
             $count = new ValueCountAggregation($criteriaPart->getName() . '_count');
             $count->setField($field);
             $aggregation = new FilterAggregation($criteriaPart->getName());
             $aggregation->setFilter(new ExistsFilter($field));
             $aggregation->addAggregation($count);
             break;
         case ProductAttributeFacet::MODE_RANGE_RESULT:
             $aggregation = new TermsAggregation($criteriaPart->getName());
             $aggregation->setField($field);
             break;
         default:
             return;
     }
     $search->addAggregation($aggregation);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     $aggregation = new ValueCountAggregation('has_available_variant_count');
     $aggregation->setField('hasAvailableVariant');
     $filter = new FilterAggregation('has_available_variant_filter');
     $filter->setFilter(new TermFilter('hasAvailableVariant', 1));
     $filter->addAggregation($aggregation);
     $search->addAggregation($filter);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     $aggregation = new ValueCountAggregation('shipping_free_count');
     $aggregation->setField('shippingFree');
     $filterAgg = new FilterAggregation('shipping_free_filter');
     $filterAgg->setFilter(new TermFilter('shippingFree', 1));
     $filterAgg->addAggregation($aggregation);
     $search->addAggregation($filterAgg);
 }
Esempio n. 7
0
 /**
  * Tests integration of the FiltersAggregation anonymous example from the documentation.
  *
  * @link https://github.com/ongr-io/ElasticsearchDSL/blob/master/docs/Aggregation/Filters.md#anonymous-example
  */
 public function testFiltersAggregationAnonymousExample()
 {
     $errorTermFilter = new TermQuery('body', 'error');
     $warningTermFilter = new TermQuery('body', 'warning');
     $histogramAggregation = new HistogramAggregation('monthly', 'timestamp');
     $histogramAggregation->setInterval('1M');
     $filterAggregation = new FiltersAggregation('grades_stats', ['error' => $errorTermFilter, 'warning' => $warningTermFilter], true);
     $filterAggregation->addAggregation($histogramAggregation);
     $search = new Search();
     $search->addAggregation($filterAggregation);
     $this->assertSame(['aggregations' => ['grades_stats' => ['filters' => ['filters' => [['term' => ['body' => 'error']], ['term' => ['body' => 'warning']]]], 'aggregations' => ['monthly' => ['histogram' => ['field' => 'timestamp', 'interval' => '1M']]]]]], $search->toArray());
 }
Esempio n. 8
0
 /**
  * Append an aggregation to the aggregation query builder.
  *
  * @param AbstractAggregation $aggregation
  */
 public function append(AbstractAggregation $aggregation)
 {
     $this->query->addAggregation($aggregation);
 }
Esempio n. 9
0
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     $statsAgg = new StatsAggregation('sales');
     $statsAgg->setField('sales');
     $search->addAggregation($statsAgg);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     $aggregation = new StatsAggregation('vote_average');
     $aggregation->setField('voteAverage.average');
     $search->addAggregation($aggregation);
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     $aggregation = new TermsAggregation('properties');
     $aggregation->setField('properties.id');
     $search->addAggregation($aggregation);
 }