/**
  * {@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);
 }
 /**
  * Test for toArray() with setting a filter.
  */
 public function testToArrayWithFilter()
 {
     $aggregation = new FilterAggregation('test_agg');
     $aggregation->setFilter(new MissingFilter('test'));
     $aggregation->toArray();
 }
 /**
  * Tests if filter can be passed to constructor.
  */
 public function testConstructorFilter()
 {
     $matchAllFilter = new MatchAllQuery();
     $aggregation = new FilterAggregation('test', $matchAllFilter);
     $this->assertEquals(['filter' => $matchAllFilter->toArray()], $aggregation->toArray());
 }
 /**
  * Tests if filter can be passed to constructor.
  */
 public function testConstructorFilter()
 {
     $matchAllFilter = new MatchAllFilter();
     $aggregation = new FilterAggregation('test', $matchAllFilter);
     $this->assertSame(['filter' => [$matchAllFilter->getType() => $matchAllFilter->toArray()]], $aggregation->toArray());
 }
 /**
  * Tests if filter can be passed to constructor.
  */
 public function testConstructorFilter()
 {
     /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface */
     $builderInterface = $this->getMockForAbstractClass('ONGR\\ElasticsearchDSL\\BuilderInterface');
     $aggregation = new FilterAggregation('test', $builderInterface);
     $this->assertSame(['agg_test' => ['filter' => [null => null]]], $aggregation->toArray());
 }