TermsAggregation example

 catch (Exception $e) {
        }

        $this->criteriaParts[] = $criteriaPart;

        switch ($criteriaPart->getMode()) {
            case ProductAttributeFacet::MODE_VALUE_LIST_RESULT:
            case ProductAttributeFacet::MODE_RADIO_LIST_RESULT:
                if ($type === 'string') {
                    $field .= '.raw';
                }
                $aggregation = new TermsAggregation($criteriaPart->getName());
                $aggregation->setField($field);
                $aggregation->addParameter('size', self::AGGREGATION_SIZE);
                break;

            case ProductAttributeFacet::MODE_BOOLEAN_RESULT:
                $count = new ValueCountAggregation($criteriaPart->getName() . '_count');
                $count->setField($field);

                $aggregation = new FilterAggregation($criteriaPart->getName());
                $aggregation->setFilter(new ExistsQuery($field));
                $aggregation->addAggregation($count);
                


    /** * {@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 hydrate(
        array $elasticResult,
        ProductNumberSearchResult $result,
        


    /** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $aggregation = new TermsAggregation('properties');
        $aggregation->setField('properties.id');
        $aggregation->addParameter('size', self::AGGREGATION_SIZE);
        $search->addAggregation($aggregation);
    }

    /** * {@inheritdoc} */
    public function hydrate(
        array $elasticResult,
        ProductNumberSearchResult $result,
        
public function supports(CriteriaPartInterface $criteriaPart)
    {
        return $criteriaPart instanceof VariantFacet;
    }

    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $aggregation = new TermsAggregation('variant');
        $aggregation->setField('configuration.options.id');
        $aggregation->setParameters(['size' => 5000]);
        $search->addAggregation($aggregation);
    }

    public function hydrate(
        array $elasticResult,
        ProductNumberSearchResult $result,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        
/** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addAggregation(
            new TermsAggregation('vote_average', 'voteAverage.average')
        );
    }

    /** * {@inheritdoc} */
    public function hydrate(
        array $elasticResult,
        ProductNumberSearchResult $result,
        Criteria $criteria,
        ShopContextInterface $context
    )


    /** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $aggregation = new TermsAggregation('category');
        $aggregation->setField('categoryIds');
        $aggregation->addParameter('size', self::AGGREGATION_SIZE);
        $search->addAggregation($aggregation);
    }

    /** * {@inheritdoc} */
    public function hydrate(
        array $elasticResult,
        ProductNumberSearchResult $result,
        
Home | Imprint | This part of the site doesn't use cookies.