getAvg example

$criteria->addAggregation(new AvgAggregation('avg-stock', 'product.stock'));

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

            static::assertCount(1, $aggregations);

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

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

            static::assertTrue(FloatComparator::equals(194.57142857143, $result->getAvg()));
        } catch (\Exception $e) {
            static::tearDown();

            throw $e;
        }
    }

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

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

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

        $avg = $result->get('avg-price');
        static::assertInstanceOf(AvgResult::class$avg);

        static::assertSame(150.0, $avg->getAvg());
    }

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

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

        $criteria->addAggregation(
            
Home | Imprint | This part of the site doesn't use cookies.