addPostFilter example



    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(PropertyCondition $criteriaPart): TermsQuery
    {
        return new TermsQuery('properties.id', $criteriaPart->getValueIds());
    }
}
Search $search,
        ShopContextInterface $context
    ) {
        $this->handle($criteriaPart$criteria$search);
    }

    private function handle(VariantCondition $criteriaPart, Criteria $criteria, Search $search): void
    {
        $groupBy = $this->buildGroupBy($criteria);

        if ($groupBy) {
            $search->addPostFilter(new TermQuery($groupBy, true));

            $search->addPostFilter(
                new TermsQuery(
                    'filterConfiguration.options.id',
                    $criteriaPart->getOptionIds()
                )
            );

            return;
        }

        


    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(SalesCondition $criteriaPart): RangeQuery
    {
        return new RangeQuery('sales', ['gt' => $criteriaPart->getMinSales()]);
    }
}


    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(ReleaseDateCondition $criteriaPart): RangeQuery
    {
        $date = new DateTime();
        $intervalSpec = 'P' . $criteriaPart->getDays() . 'D';
        $interval = new DateInterval($intervalSpec);
        $dateNow = new DateTime();

        switch ($criteriaPart->getDirection()) {
            case ReleaseDateCondition::DIRECTION_FUTURE:
                


    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(ProductIdCondition $criteriaPart): TermsQuery
    {
        return new TermsQuery('id', $criteriaPart->getProductIds());
    }
}


    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter(
            new TermQuery('shippingFree', true)
        );
    }
}
ShopContextInterface $context
    ) {
        $search->addQuery($this->getQuery($criteriaPart), BoolQuery::FILTER);
    }

    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(HeightCondition $criteriaPart): RangeQuery
    {
        $range = [];
        if ($criteriaPart->getMinHeight()) {
            $range['gte'] = $criteriaPart->getMinHeight();
        }
        if ($criteriaPart->getMaxHeight()) {
            $range['lte'] = $criteriaPart->getMaxHeight();
        }

        
ShopContextInterface $context
    ) {
        $search->addQuery($this->getQuery($criteriaPart), BoolQuery::FILTER);
    }

    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(LengthCondition $criteriaPart): RangeQuery
    {
        $range = [];
        if ($criteriaPart->getMinLength()) {
            $range['gte'] = $criteriaPart->getMinLength();
        }
        if ($criteriaPart->getMaxLength()) {
            $range['lte'] = $criteriaPart->getMaxLength();
        }

        
/** * @depends testIndexing */
    public function testTotalWithGroupFieldAndPostFilter(IdsCollection $data): void
    {
        try {
            $searcher = $this->createEntitySearcher();
            // check simple equals filter             $criteria = new Criteria($data->prefixed('product-'));
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);
            $criteria->addGroupField(new FieldGrouping('stock'));
            $criteria->addPostFilter(new EqualsFilter('manufacturerId', $data->get('m2')));

            $products = $searcher->search($this->productDefinition, $criteria$this->context);

            static::assertEquals(3, $products->getTotal());
            static::assertCount(3, $products->getIds());
            static::assertContains($data->get('product-2')$products->getIds());
            static::assertContains($data->get('product-3')$products->getIds());
            static::assertContains($data->get('product-4')$products->getIds());
        } catch (\Exception $e) {
            static::tearDown();

            


    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($context));
    }

    private function getQuery(ShopContextInterface $context): RangeQuery
    {
        return new RangeQuery(
            $this->getPseudoPriceField($context),
            ['gt' => 0]
        );
    }

    private function getPseudoPriceField(ShopContextInterface $context): string
    {
$criteria->setLimit(200);

        // check that provided criteria has other key         $route->load($ids->get('product')new Request()$context$criteria);
    }

    public static function criteriaProvider(): \Generator
    {
        yield 'Paginated criteria' => [(new Criteria())->setOffset(1)->setLimit(20)];
        yield 'Filtered criteria' => [(new Criteria())->addFilter(new EqualsFilter('active', true))];
        yield 'Post filtered criteria' => [(new Criteria())->addPostFilter(new EqualsFilter('active', true))];
        yield 'Aggregation criteria' => [(new Criteria())->addAggregation(new StatsAggregation('name', 'name'))];
        yield 'Query criteria' => [(new Criteria())->addQuery(new ScoreQuery(new EqualsFilter('active', true), 200))];
        yield 'Term criteria' => [(new Criteria())->setTerm('test')];
        yield 'Sorted criteria' => [(new Criteria())->addSorting(new FieldSorting('active'))];
    }

    /** * @dataProvider invalidationProvider */
    public function testInvalidation(IdsCollection $ids, \Closure $before, \Closure $after, int $calls): void
    {
        


    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart$criteria$context));
    }

    private function getQuery(
        CombinedCondition $criteriaPart,
        Criteria $criteria,
        ShopContextInterface $context
    ): BoolQuery {
        return $this->combinedConditionQueryBuilder->build(
            $criteriaPart->getConditions(),
            $criteria,
            $context
        );
$criteria->setLimit(200);

        // check that provided criteria has other key         $route->load(new Request()$criteria$context);
    }

    public static function criteriaProvider(): \Generator
    {
        yield 'Paginated criteria' => [(new Criteria())->setOffset(1)->setLimit(20)];
        yield 'Filtered criteria' => [(new Criteria())->addFilter(new EqualsFilter('active', true))];
        yield 'Post filtered criteria' => [(new Criteria())->addPostFilter(new EqualsFilter('active', true))];
        yield 'Aggregation criteria' => [(new Criteria())->addAggregation(new StatsAggregation('name', 'name'))];
        yield 'Query criteria' => [(new Criteria())->addQuery(new ScoreQuery(new EqualsFilter('active', true), 200))];
        yield 'Term criteria' => [(new Criteria())->setTerm('test')];
        yield 'Sorted criteria' => [(new Criteria())->addSorting(new FieldSorting('active'))];
    }

    /** * @dataProvider invalidationProvider */
    public function testInvalidation(\Closure $before, \Closure $after, int $calls): void
    {
        


    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(LastProductIdCondition $criteriaPart): RangeQuery
    {
        return new RangeQuery('id', [
            'gt' => $criteriaPart->getLastId(),
        ]);
    }
}
public function supports(CriteriaPartInterface $criteriaPart)
    {
        return $criteriaPart instanceof MainVariantCondition;
    }

    public function handleFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery());
    }

    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery());
    }

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