ValueCountAggregation example



    /** * {@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 TermQuery('shippingFree', true));
        $filterAgg->addAggregation($aggregation);

        $search->addAggregation($filterAgg);
    }

    /** * {@inheritdoc} */


    /** * {@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 TermQuery('hasAvailableVariant', true));
        $filter->addAggregation($aggregation);

        $search->addAggregation($filter);
    }

    /** * {@inheritdoc} */
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);
                break;

            case ProductAttributeFacet::MODE_RANGE_RESULT:
                $aggregation = new TermsAggregation($criteriaPart->getName());
                $aggregation->setField($field);
                $aggregation->addParameter('size', self::AGGREGATION_SIZE);
                
$fieldName = $this->getTranslatedFieldName($fieldName$context->getLanguageId());
            }
        }

        return match (true) {
            $aggregation instanceof StatsAggregation => $this->parseStatsAggregation($aggregation$fieldName$context),
            $aggregation instanceof AvgAggregation => new Metric\AvgAggregation($aggregation->getName()$fieldName),
            $aggregation instanceof EntityAggregation => $this->parseEntityAggregation($aggregation$fieldName),
            $aggregation instanceof MaxAggregation => new Metric\MaxAggregation($aggregation->getName()$fieldName),
            $aggregation instanceof MinAggregation => new Metric\MinAggregation($aggregation->getName()$fieldName),
            $aggregation instanceof SumAggregation => new Metric\SumAggregation($aggregation->getName()$fieldName),
            $aggregation instanceof CountAggregation => new ValueCountAggregation($aggregation->getName()$fieldName),
            $aggregation instanceof FilterAggregation => $this->parseFilterAggregation($aggregation$definition$context),
            $aggregation instanceof TermsAggregation => $this->parseTermsAggregation($aggregation$fieldName$definition$context),
            $aggregation instanceof DateHistogramAggregation => $this->parseDateHistogramAggregation($aggregation$fieldName$definition$context),
            $aggregation instanceof RangeAggregation => $this->parseRangeAggregation($aggregation$fieldName),
            default => throw new \RuntimeException(sprintf('Provided aggregation of class %s not supported', $aggregation::class)),
        };
    }

    private function parseEqualsFilter(EqualsFilter $filter, EntityDefinition $definition, Context $context): BuilderInterface
    {
        if ($this->keyValueStorage->get(ElasticsearchIndexer::ENABLE_MULTILINGUAL_INDEX_KEY, false)) {
            
Home | Imprint | This part of the site doesn't use cookies.