getBuckets example

new TermsAggregation('category-ids', 'parentId', null, null, new CountAggregation('visible-children-count', 'id'))
        );

        $termsResult = $this->categoryRepository
            ->aggregate($criteria$context)
            ->get('category-ids');

        if (!($termsResult instanceof TermsResult)) {
            return;
        }

        foreach ($termsResult->getBuckets() as $bucket) {
            $key = $bucket->getKey();

            if ($key === null) {
                continue;
            }

            $parent = $levels->get($key);

            if ($parent instanceof CategoryEntity) {
                $parent->setVisibleChildCount($bucket->getCount());
            }
        }
$criteria->addAggregation(new TermsAggregation('manufacturer-ids', 'product.manufacturerId'));

            $aggregations = $aggregator->aggregate($this->productDefinition, $criteria$this->context);

            static::assertCount(1, $aggregations);

            static::assertTrue($aggregations->has('manufacturer-ids'));

            $result = $aggregations->get('manufacturer-ids');
            static::assertInstanceOf(TermsResult::class$result);

            static::assertCount(3, $result->getBuckets());

            static::assertContains($data->get('m1')$result->getKeys());
            static::assertContains($data->get('m2')$result->getKeys());
            static::assertContains($data->get('m3')$result->getKeys());

            $bucket = $result->get($data->get('m1'));
            static::assertNotNull($bucket);
            static::assertEquals(1, $bucket->getCount());

            $bucket = $result->get($data->get('m2'));
            static::assertNotNull($bucket);
            
$criteria->addAggregation(
            new TermsAggregation('category-ids', 'product.categories.id')
        );

        $result = $this->aggregator->aggregate($this->definition, $criteria$context);

        static::assertTrue($result->has('category-ids'));

        $categoryAgg = $result->get('category-ids');
        static::assertInstanceOf(TermsResult::class$categoryAgg);

        static::assertCount(4, $categoryAgg->getBuckets());
        static::assertTrue($categoryAgg->has(''));
        static::assertTrue($categoryAgg->has($this->ids->get('c-1')));
        static::assertTrue($categoryAgg->has($this->ids->get('c-2')));
        static::assertTrue($categoryAgg->has($this->ids->get('c-3')));

        $bucket = $categoryAgg->get('');
        static::assertInstanceOf(Bucket::class$bucket);
        static::assertEquals(1, $bucket->getCount());
        static::assertNull($bucket->getResult());

        $bucket = $categoryAgg->get($this->ids->get('c-1'));
        
$this->eventDispatcher->dispatch(new ProductReviewsLoadedEvent($reviews$context$request));

        $reviewResult = ReviewLoaderResult::createFrom($reviews);
        $reviewResult->setProductId($request->get('productId'));
        $reviewResult->setParentId($request->get('parentId'));

        $aggregation = $reviews->getAggregations()->get('ratingMatrix');
        $matrix = new RatingMatrix([]);

        if ($aggregation instanceof TermsResult) {
            $matrix = new RatingMatrix($aggregation->getBuckets());
        }
        $reviewResult->setMatrix($matrix);
        $reviewResult->setCustomerReview($this->getCustomerReview($productId$context));
        $reviewResult->setTotalReviews($matrix->getTotalReviewCount());

        return $reviewResult;
    }

    private function createCriteria(Request $request, SalesChannelContext $context): Criteria
    {
        $limit = (int) $request->get('limit', self::LIMIT);
        
->getResult()->getEntities()->first();
    }

    /** * @param EntitySearchResult<ProductReviewCollection> $reviews */
    private function getReviewRatingMatrix(EntitySearchResult $reviews): RatingMatrix
    {
        $aggregation = $reviews->getAggregations()->get('ratingMatrix');

        if ($aggregation instanceof TermsResult) {
            return new RatingMatrix($aggregation->getBuckets());
        }

        return new RatingMatrix([]);
    }
}
public function getAuthors(Context $context): array
    {
        $files = $this->snippetFileCollection->toArray();

        $criteria = new Criteria();
        $criteria->addAggregation(new TermsAggregation('distinct_author', 'author'));

        /** @var TermsResult|null $aggregation */
        $aggregation = $this->snippetRepository->aggregate($criteria$context)
                ->get('distinct_author');

        if (!$aggregation || empty($aggregation->getBuckets())) {
            $result = [];
        } else {
            $result = $aggregation->getKeys();
        }

        $authors = array_flip($result);
        foreach ($files as $file) {
            $authors[$file['author']] = true;
        }
        $result = array_keys($authors);
        sort($result);

        
Home | Imprint | This part of the site doesn't use cookies.