parseAggregation example

public function testAggregationWithSorting(): void
    {
        $aggs = new TermsAggregation('foo', 'test', null, new FieldSorting('abc', FieldSorting::ASCENDING)new TermsAggregation('foo', 'foo2'));

        $definition = $this->getDefinition();

        /** @var CompositeAggregation $esAgg */
        $esAgg = (new CriteriaParser(
            new EntityDefinitionQueryHelper(),
            $this->createMock(CustomFieldService::class),
            $this->createMock(AbstractKeyValueStorage::class)
        ))->parseAggregation($aggs$definition, Context::createDefaultContext());

        static::assertInstanceOf(CompositeAggregation::class$esAgg);
        static::assertSame([
            'composite' => [
                'sources' => [
                    [
                        'foo.sorting' => [
                            'terms' => [
                                'field' => 'abc',
                                'order' => 'ASC',
                            ],
                        ],
$filter instanceof RangeFilter => $this->parseRangeFilter($filter$definition$context),
            default => throw new \RuntimeException(sprintf('Unsupported filter %s', $filter::class)),
        };
    }

    protected function parseFilterAggregation(FilterAggregation $aggregation, EntityDefinition $definition, Context $context): AbstractAggregation
    {
        if ($aggregation->getAggregation() === null) {
            throw new \RuntimeException(sprintf('Filter aggregation %s contains no nested aggregation.', $aggregation->getName()));
        }

        $nested = $this->parseAggregation($aggregation->getAggregation()$definition$context);
        if ($nested === null) {
            throw new \RuntimeException(sprintf('Nested filter aggregation %s can not be parsed.', $aggregation->getName()));
        }

        // when aggregation inside the filter aggregation points to a nested object (e.g. product.properties.id) we have to add all filters         // which points to the same association to the same "nesting" level like the nested aggregation for this association         $path = $nested instanceof NestedAggregation ? $nested->getPath() : null;
        $bool = new BoolQuery();

        $filters = [];
        foreach ($aggregation->getFilter() as $filter) {
            

#[Package('core')] class AggregationParser
{
    public function buildAggregations(EntityDefinition $definition, array $payload, Criteria $criteria, SearchRequestException $searchRequestException): void
    {
        if (!\is_array($payload['aggregations'])) {
            throw new InvalidAggregationQueryException('The aggregations parameter has to be a list of aggregations.');
        }

        foreach ($payload['aggregations'] as $index => $aggregation) {
            $parsed = $this->parseAggregation($index$definition$aggregation$searchRequestException);

            if ($parsed) {
                $criteria->addAggregation($parsed);
            }
        }
    }

    public function toArray(array $aggregations): array
    {
        $data = [];

        

    }

    public function addAggregations(EntityDefinition $definition, Criteria $criteria, Search $search, Context $context): void
    {
        $aggregations = $criteria->getAggregations();
        if (empty($aggregations)) {
            return;
        }

        foreach ($aggregations as $aggregation) {
            $agg = $this->parser->parseAggregation($aggregation$definition$context);

            if (!$agg) {
                continue;
            }

            $search->addAggregation($agg);
        }
    }

    /** * Only used for unit tests because the container parameter bag is frozen and can not be changed at runtime. * Therefore this function can be used to test different behaviours * * @internal */
Home | Imprint | This part of the site doesn't use cookies.