/**
  * {@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);
 }
Пример #2
0
 /**
  * {@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)
 {
     /** @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);
 }
 /**
  * Get aggregation collection with several aggregations registered.
  *
  * @return AbstractAggregation
  */
 private function buildAggregation()
 {
     $aggregation = new TermsAggregation('terms');
     $aggregation->setField('description');
     $aggregation2 = new RangeAggregation('range');
     $aggregation2->setField('price');
     $aggregation2->addRange(null, 20);
     $aggregation2->addRange(20, null);
     $aggregation->addAggregation($aggregation2);
     return $aggregation;
 }
 /**
  * Creates locales list.
  *
  * @param ViewData\ChoicesAwareViewData $filter
  *
  * @return array
  */
 private function buildLocalesList($filter)
 {
     $search = $this->repository->createSearch();
     $localeAgg = new TermsAggregation('locale_agg');
     $localeAgg->setField('messages.locale');
     $search->addAggregation($localeAgg);
     $result = $this->repository->execute($search, Result::RESULTS_RAW);
     $list = [];
     foreach ($result['aggregations']['agg_locale_agg']['buckets'] as $value) {
         $list[$value['key']] = true;
     }
     ksort($list);
     $activeLocales = [];
     if ($filter->getState()->isActive()) {
         foreach ($filter->getChoices() as $choice) {
             $activeLocales[$choice->getLabel()] = $choice->isActive();
         }
         $list = array_merge($list, $activeLocales);
     }
     return $list;
 }
 /**
  * Tests getType method.
  */
 public function testTermsAggregationGetType()
 {
     $aggregation = new TermsAggregation('foo');
     $result = $aggregation->getType();
     $this->assertEquals('terms', $result);
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     $aggregation = new TermsAggregation('properties');
     $aggregation->setField('properties.id');
     $search->addAggregation($aggregation);
 }