addQuery example



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

    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        
$context = Context::createDefaultContext();
        $pattern = new SearchPattern(new SearchTerm('test'));
        $builder = new EntityScoreQueryBuilder();
        $queries = $builder->buildScoreQueries(
            $pattern,
            $this->getContainer()->get(ProductDefinition::class),
            $this->getContainer()->get(ProductDefinition::class)->getEntityName(),
            $context
        );

        $criteria = new Criteria();
        $criteria->addQuery(...$queries);

        $this->repository->create([
            ['id' => Uuid::randomHex(), 'productNumber' => Uuid::randomHex(), 'stock' => 10, 'name' => 'product 1 test', 'tax' => ['name' => 'test', 'taxRate' => 5], 'manufacturer' => ['name' => 'test'], 'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 10, 'net' => 9, 'linked' => false]]],
            ['id' => Uuid::randomHex(), 'productNumber' => Uuid::randomHex(), 'stock' => 10, 'name' => 'product 2 test', 'tax' => ['name' => 'test', 'taxRate' => 5], 'manufacturer' => ['name' => 'test'], 'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 10, 'net' => 9, 'linked' => false]]],
        ]$context);

        foreach ($this->repository->search($criteria$context)->getEntities() as $entity) {
            static::assertArrayHasKey('search', $entity->getExtensions());
            $extension = $entity->getExtension('search');

            static::assertInstanceOf(ArrayEntity::class$extension);
            


    /** * {@inheritdoc} */
    public function handleFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addQuery(
            $this->getQuery($criteriaPart),
            BoolQuery::FILTER
        );
    }

    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        
// check that provided criteria has other key         $route->load($ids->get('c.1')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('price', 'price'))];
        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 stateProvider */
    public function testStates(array $current, array $config): void
    {
        $ids = new IdsCollection();

        
$query = new Query('select * from table where key = ?');
        $query->setValue(
            1,
            new class() {
                public function __toString(): string
                {
                    return 'value';
                }
            },
            ParameterType::STRING
        );
        $debugDataHolder->addQuery('default', $query);

        $collector = new ConnectionProfiler($connection);
        $collector->lateCollect();

        $profile->addCollector($collector);

        $response = $controller->explainAction(
            'some-token',
            'app.connection_collector',
            'default',
            0
        );


    /** * {@inheritdoc} */
    public function handleFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addQuery($this->getQuery($criteriaPart), BoolQuery::FILTER);
    }

    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        
if ($definition->isInheritanceAware() && $context->considerInheritance()) {
            $parent = $definition->getFields()->get('parent');

            if ($parent) {
                $this->helper->resolveField($parent$definition$definition->getEntityName()$query$context);
            }
        }

        if ($criteria->getTerm()) {
            $pattern = $this->interpreter->interpret((string) $criteria->getTerm());
            $queries = $this->scoreBuilder->buildScoreQueries($pattern$definition$definition->getEntityName()$context);
            $criteria->addQuery(...$queries);
        }

        $filters = $this->groupFilters($definition$criteria$paths);

        $this->criteriaPartResolver->resolve($filters$definition$query$context);

        $this->criteriaPartResolver->resolve($criteria->getQueries()$definition$query$context);

        $this->criteriaPartResolver->resolve($criteria->getSorting()$definition$query$context);

        // do not use grouped filters, because the grouped filters are mapped flat and the logical OR/AND are removed

    /** * @var OrderedSerializer */
    protected static $serializer;

    /** * {@inheritdoc} */
    public function addFilter(BuilderInterface $query)
    {
        $this->addQuery($query, BoolQuery::FILTER);
    }

    /** * {@inheritdoc} */
    public function getFilters(BuilderInterface $query): BuilderInterface
    {
        $boolQuery = new BoolQuery();

        foreach ($this->getQueries()->getQueries(BoolQuery::FILTER) as $filterQuerys) {
            $boolQuery->add($filterQuerys, BoolQuery::FILTER);
        }
'Missing permissions for nested sorting' => [
                ['product:read'],
                (new Criteria())
                    ->addSorting(new FieldSorting('categories.media.private')),
                false,
            ],

            // query validation             'Has permissions for query' => [
                ['product:read', 'category:read'],
                (new Criteria())
                    ->addQuery(new ScoreQuery(new EqualsFilter('categories.active', true), 100)),
                true,
            ],
            'Missing permissions for query' => [
                ['product:read'],
                (new Criteria())
                    ->addQuery(new ScoreQuery(new EqualsFilter('categories.active', true), 100)),
                false,
            ],
            'Has permissions for nested query' => [
                ['product:read', 'category:read', 'media:read'],
                (new Criteria())
                    


    /** * {@inheritdoc} */
    public function handleFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addQuery($this->getQuery($criteriaPart), BoolQuery::FILTER);
    }

    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        


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

    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        
return new Statement(
            parent::prepare($sql),
            $this->debugDataHolder,
            $this->connectionName,
            $sql,
            $this->stopwatch,
        );
    }

    public function query(string $sql): Result
    {
        $this->debugDataHolder->addQuery($this->connectionName, $query = new Query($sql));

        $this->stopwatch?->start('doctrine', 'doctrine');
        $query->start();

        try {
            $result = parent::query($sql);
        } finally {
            $query->stop();
            $this->stopwatch?->stop('doctrine');
        }

        
public function supports(CriteriaPartInterface $criteriaPart)
    {
        return $criteriaPart instanceof WidthCondition;
    }

    public function handleFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        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));
    }

    


    /** * {@inheritdoc} */
    public function handleFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addQuery($this->getQuery($criteriaPart), BoolQuery::FILTER);
    }

    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        


    /** * {@inheritdoc} */
    public function handleFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addQuery($this->getQuery($criteriaPart$criteria$context), BoolQuery::FILTER);
    }

    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        
Home | Imprint | This part of the site doesn't use cookies.