DateHistogramAggregation example


    public function testDateHistogram(DateHistogramCase $case): void
    {
        $context = Context::createDefaultContext();

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

        $criteria->addAggregation(
            new DateHistogramAggregation(
                'release-histogram',
                'product.releaseDate',
                $case->getInterval(),
                null,
                null,
                $case->getFormat(),
                $case->getTimeZone()
            )
        );

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

        

        try {
            $context = $this->context;

            $aggregator = $this->createEntityAggregator();

            // check simple search without any restrictions             $criteria = new Criteria($data->prefixed('p'));
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);

            $criteria->addAggregation(
                new DateHistogramAggregation(
                    'release-histogram',
                    'product.releaseDate',
                    $case->getInterval(),
                    null,
                    null,
                    $case->getFormat(),
                    $case->getTimeZone()
                )
            );

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

            
$naturalSorting = $sort['naturalSorting'] ?? false;

                    if (strcasecmp((string) $order, 'desc') === 0) {
                        $order = FieldSorting::DESCENDING;
                    } else {
                        $order = FieldSorting::ASCENDING;
                    }

                    $sorting = new FieldSorting($sort['field']$order(bool) $naturalSorting);
                }

                return new DateHistogramAggregation($name$field$interval$sorting$nested$format$timeZone);

            case 'terms':
                $nested = null;
                $limit = null;
                $sorting = null;

                if (isset($aggregation['aggregation'])) {
                    $nested = $this->parseAggregation($index$definition$aggregation['aggregation']$exceptions);
                }

                if (isset($aggregation['limit'])) {
                    
use Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Bucket\DateHistogramAggregation;

/** * @internal * * @covers \Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Bucket\DateHistogramAggregation */
class DateHistogramAggregationTest extends TestCase
{
    public function testEncode(): void
    {
        $aggregation = new DateHistogramAggregation(
            'test',
            'test',
            DateHistogramAggregation::PER_DAY,
            null,
            null,
            null,
            null
        );

        static::assertEquals([
            'extensions' => [],
            
Home | Imprint | This part of the site doesn't use cookies.