CardinalityAggregation example



    private function buildTotalCountAggregation(Criteria $criteria, EntityDefinition $definition, Context $context): AbstractAggregation
    {
        $groupings = $criteria->getGroupFields();

        if (\count($groupings) === 1) {
            $first = array_shift($groupings);

            $accessor = $this->criteriaParser->buildAccessor($definition$first->getField()$context);

            $aggregation = new CardinalityAggregation('total-count');
            $aggregation->setField($accessor);

            return $this->addPostFilterAggregation($criteria$definition$context$aggregation);
        }

        $fields = [];
        foreach ($groupings as $grouping) {
            $accessor = $this->criteriaParser->buildAccessor($definition$grouping->getField()$context);

            $fields[] = sprintf(
                ' if (doc[\'%s\'].size()==0) { value = value + \'empty\'; } else { value = value + doc[\'%s\'].value; }',
Home | Imprint | This part of the site doesn't use cookies.