getSum example


                    'aggregations' => [
                        ['name' => 'sum', 'type' => 'sum', 'field' => 'price.gross'],
                    ],
                ],
                'search',
                $ids,
                function DEntitySearchResult $result): void {
                    static::assertCount(4, $result);
                    $agg = $result->getAggregations()->get('sum');
                    static::assertInstanceOf(SumResult::class$agg);
                    static::assertEquals(600, $agg->getSum());
                },
            ],
            'testSearchSort' => [
                [
                    'sort' => [['field' => 'id']],
                ],
                'search',
                $ids,
                function DEntitySearchResult $result): void {
                    $actual = $result->getIds();

                    

        ]$versionContext);

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('product.ean', 'EAN'));
        $criteria->addAggregation(new SumAggregation('sum_price', 'product.price.gross'));

        $aggregations = $this->productRepository->aggregate($criteria$context);
        static::assertTrue($aggregations->has('sum_price'));
        /** @var SumResult $sum */
        $sum = $aggregations->get('sum_price');
        static::assertEquals(100, $sum->getSum());

        $aggregations = $this->productRepository->aggregate($criteria$versionContext);
        static::assertTrue($aggregations->has('sum_price'));
        /** @var SumResult $sum */
        $sum = $aggregations->get('sum_price');
        static::assertEquals(1000, $sum->getSum());

        $this->productRepository->merge($versionId$context);

        $aggregations = $this->productRepository->aggregate($criteria$context);
        static::assertTrue($aggregations->has('sum_price'));
        
$criteria->addAggregation(new SumAggregation('sum-stock', 'product.stock'));

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

            static::assertCount(1, $aggregations);

            static::assertTrue($aggregations->has('sum-stock'));

            $result = $aggregations->get('sum-stock');
            static::assertInstanceOf(SumResult::class$result);

            static::assertEquals(1362, $result->getSum());
        } catch (\Exception $e) {
            static::tearDown();

            throw $e;
        }
    }

    /** * @depends testIndexing */
    public function testSumAggregationWithTermsAggregation(IdsCollection $data): void
    {
$criteria->addAggregation(
            new SumAggregation('sum-price', 'product.price')
        );

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

        static::assertTrue($result->has('sum-price'));

        $sum = $result->get('sum-price');
        static::assertInstanceOf(SumResult::class$sum);

        static::assertSame(750.0, $sum->getSum());
    }

    public function testSumAggregationWithTermsAggregation(): void
    {
        $context = Context::createDefaultContext();

        $criteria = new Criteria(
            $this->ids->getList(['p-1', 'p-2', 'p-3', 'p-4', 'p-5'])
        );

        $criteria->addAggregation(
            

                    'aggregations' => [
                        ['name' => 'sum', 'type' => 'sum', 'field' => 'childCount'],
                    ],
                ],
                'search',
                $ids,
                function DEntitySearchResult $result): void {
                    static::assertCount(3, $result);
                    $agg = $result->getAggregations()->get('sum');
                    static::assertInstanceOf(SumResult::class$agg);
                    static::assertEquals(1, $agg->getSum());
                },
            ],
            'testSearchSort' => [
                [
                    'sort' => [['field' => 'id']],
                ],
                'search',
                $ids,
                function DEntitySearchResult $result): void {
                    $actual = $result->getIds();

                    
$criteria = new Criteria();
        $criteria->addAggregation(new SumAggregation('stock_sum', 'root.sub.stock'));
        $result = $this->repository->search($criteria$context);

        static::assertTrue($result->getAggregations()->has('stock_sum'));
        $sum = $result->getAggregations()->get('stock_sum');

        /** @var SumResult $sum */
        static::assertInstanceOf(SumResult::class$sum);

        static::assertEquals(11, $sum->getSum());
    }

    public function testCreateVersioning(): void
    {
        $id = 'a80c8dc21a424061a4048e457b2732df';

        $data = [
            'id' => $id,
            'name' => 'root 1',
            'subCascade' => [
                'id' => $id,
                
Home | Imprint | This part of the site doesn't use cookies.