getGroupFields example

if ($criteria->getTerm()) {
            return true;
        }

        // paginated lists are handled by entity searcher         if ($criteria->getOffset() !== null || $criteria->getLimit() !== null) {
            return true;
        }

        // group by is only supported by entity searcher         if (\count($criteria->getGroupFields())) {
            return true;
        }

        // sortings are only supported by entity searcher         if (\count($criteria->getSorting())) {
            return true;
        }

        // queries can only be handled in entity searcher         if (\count($criteria->getQueries())) {
            return true;
        }
$nested = $this->extractHits($hit['inner_hits']['inner']);
            foreach ($nested as $inner) {
                $records[] = $inner;
            }
        }

        return $records;
    }

    private function getTotalValue(Criteria $criteria, array $result): int
    {
        if (!$criteria->getGroupFields()) {
            return (int) $result['hits']['total']['value'];
        }

        if (!$criteria->getPostFilters()) {
            return (int) $result['aggregations']['total-count']['value'];
        }

        return (int) $result['aggregations']['total-filtered-count']['total-count']['value'];
    }

    private function sortByIdArray(array $ids, array $data): array
    {
foreach ($queries->getParameters() as $key => $value) {
            $query->setParameter($key$value$queries->getType($key));
        }
    }

    private function hasGroupBy(Criteria $criteria, QueryBuilder $query): bool
    {
        if ($query->hasState(EntityReader::MANY_TO_MANY_LIMIT_QUERY)) {
            return false;
        }

        return $query->hasState(EntityDefinitionQueryHelper::HAS_TO_MANY_JOIN) || !empty($criteria->getGroupFields());
    }

    /** * @param list<string> $additionalFields * * @return list<Filter> */
    private function groupFilters(EntityDefinition $definition, Criteria $criteria, array $additionalFields = []): array
    {
        $filters = [];
        foreach ($criteria->getFilters() as $filter) {
            
foreach ($criteria->getQueries() as $query) {
                $arrayQuery = [
                    'score' => $query->getScore(),
                    'scoreField' => $query->getScoreField(),
                    'extensions' => $query->getExtensions(),
                ];
                $arrayQuery['query'] = QueryStringParser::toArray($query->getQuery());
                $array['query'][] = $arrayQuery;
            }
        }

        if (\count($criteria->getGroupFields())) {
            $array['grouping'] = [];

            foreach ($criteria->getGroupFields() as $groupField) {
                $array['grouping'][] = $groupField->getField();
            }
        }

        if (\count($criteria->getAggregations())) {
            $array['aggregations'] = $this->aggregationParser->toArray($criteria->getAggregations());
        }

        

        return md5((string) json_encode([
            $criteria->getIds(),
            $criteria->getFilters(),
            $criteria->getTerm(),
            $criteria->getPostFilters(),
            $criteria->getQueries(),
            $criteria->getSorting(),
            $criteria->getLimit(),
            $criteria->getOffset() ?? 0,
            $criteria->getTotalCountMode(),
            $criteria->getGroupFields(),
            $criteria->getAggregations(),
            $criteria->getAssociations(),
        ], \JSON_THROW_ON_ERROR));
    }
}

        $search->setFrom((int) $criteria->getOffset());

        return $search;
    }

    /** * @return array<string, mixed> */
    private function convertSearch(Criteria $criteria, EntityDefinition $definition, Context $context, Search $search): array
    {
        if (!$criteria->getGroupFields()) {
            $array = $search->toArray();
            $array['timeout'] = $this->timeout;

            return $array;
        }

        $aggregation = $this->buildTotalCountAggregation($criteria$definition$context);

        $search->addAggregation($aggregation);
        $array = $search->toArray();
        $array['collapse'] = $this->parseGrouping($criteria->getGroupFields()$definition$context);
        
$total = new QueryBuilder($this->connection);
        $total->select(['COUNT(*)'])
            ->from(sprintf('(%s) total', $query->getSQL()))
            ->setParameters($query->getParameters()$query->getParameterTypes());

        return (int) $total->executeQuery()->fetchOne();
    }

    private function addGroupBy(EntityDefinition $definition, Criteria $criteria, Context $context, QueryBuilder $query, string $table): void
    {
        if ($criteria->getGroupFields()) {
            foreach ($criteria->getGroupFields() as $grouping) {
                $accessor = $this->queryHelper->getFieldAccessor($grouping->getField()$definition$definition->getEntityName()$context);

                $query->addGroupBy($accessor);
            }

            return;
        }

        if ($query->hasState(EntityDefinitionQueryHelper::HAS_TO_MANY_JOIN)) {
            $query->addGroupBy(
                
Home | Imprint | This part of the site doesn't use cookies.