getQueries example

$criteriaCollection = $this->buyBoxResolver->collect($slot$resolverContext);

        static::assertNotNull($criteriaCollection);
        static::assertCount(1, $criteriaCollection->all());
        /** @var Criteria $criteria */
        $criteria = $criteriaCollection->all()[SalesChannelProductDefinition::class]['product_id'];

        static::assertInstanceOf(Criteria::class$criteria);
        static::assertCount(1, $criteria->getFilters());
        /** @var OrFilter $orFilter */
        static::assertInstanceOf(OrFilter::class$orFilter = $criteria->getFilters()[0]);
        static::assertCount(2, $queries = $orFilter->getQueries());

        static::assertInstanceOf(EqualsFilter::class$firstQuery = $queries[0]);
        static::assertEquals('product.parentId', $firstQuery->getField());
        static::assertEquals('product123', $firstQuery->getValue());
        static::assertInstanceOf(EqualsFilter::class$secondQuery = $queries[1]);
        static::assertEquals('id', $secondQuery->getField());
        static::assertEquals('product123', $secondQuery->getValue());
    }

    public function testEnrichWithEmptyConfig(): void
    {
        
try {
            $collector = $profile->getCollector($panelName);
        } catch (\InvalidArgumentException) {
            return new Response('This collector does not exist.');
        }

        if (!$collector instanceof ConnectionProfiler) {
            return new Response('This collector does not exist.');
        }

        $queries = $collector->getQueries();

        if (!isset($queries[$connectionName][$queryIndex])) {
            return new Response('This query does not exist.');
        }

        $queryIndex = $queries[$connectionName][$queryIndex];
        if (!$queryIndex['explainable']) {
            return new Response('This query cannot be explained.');
        }

        try {
            

        $queries = [
            ['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 1],
        ];
        $c = $this->createCollector($queries);
        $c->collect(new Request()new Response());

        $c->reset();
        $c->collect(new Request()new Response());
        $c = unserialize(serialize($c));

        $this->assertEquals([]$c->getQueries());
    }

    /** * @dataProvider paramProvider */
    public function testCollectQueries($param$types$expected)
    {
        $queries = [
            ['sql' => 'SELECT * FROM table1 WHERE field1 = ?1', 'params' => [$param], 'types' => $types, 'executionMS' => 1],
        ];
        $c = $this->createCollector($queries);
        
// must be MultiFilter             if (!(\count($filters) === 1 && $filters[0] instanceof MultiFilter)) {
                return false;
            }
            /** @var MultiFilter $filter */
            $filter = $filters[0];
            // must be OR             if ($filter->getOperator() !== MultiFilter::CONNECTION_OR) {
                return false;
            }
            $fields = ['name', 'label'];
            foreach ($filter->getQueries() as $query) {
                /** @var ContainsFilter $query */
                if (!(
                    $query instanceof ContainsFilter
                    && $query->getValue() === $filterValue
                    // first test against name, then label                     && $query->getField() === array_shift($fields)
                )
                ) {
                    return false;
                }
            }

            

    private function recursion(array $filters, EntityDefinition $definition, string $operator, bool $negated): array
    {
        $mapped = [];

        // for each nesting level we need an own group to keep the mathematical logic         $prefix = Uuid::randomHex();

        foreach ($filters as $filter) {
            if ($filter instanceof MultiFilter) {
                $nested = $this->recursion($filter->getQueries()$definition$filter->getOperator()$filter instanceof NotFilter || $negated);
                $mapped = array_merge_recursive($mapped$nested);

                continue;
            }

            if (!$filter instanceof SingleFieldFilter) {
                // this case should never happen, because all core filters are an instead of SingleFieldFilter or MultiFilter                 $mapped[self::NOT_RELEVANT][] = $filter;

                continue;
            }

            
if (!$esDefinition) {
            throw new UnsupportedElasticsearchDefinitionException($definition->getEntityName());
        }

        $query = $esDefinition->buildTermQuery($context$criteria);

        $search->addQuery($query);
    }

    public function addQueries(EntityDefinition $definition, Criteria $criteria, Search $search, Context $context): void
    {
        $queries = $criteria->getQueries();
        if (empty($queries)) {
            return;
        }

        $bool = new BoolQuery();

        foreach ($queries as $query) {
            $parsed = $this->parser->parseFilter($query->getQuery()$definition$definition->getEntityName()$context);

            if ($parsed instanceof MatchQuery) {
                $score = (string) $query->getScore();

                
public function callbackLoadPaymentMethods(Request $request, SalesChannelContext $context, Criteria $criteria): PaymentMethodRouteResponse
    {
        $searchIds = $criteria->getIds();

        if ($searchIds === []) {
            static::assertCount(1, $criteria->getFilters());

            $nand = $criteria->getFilters()[0];

            static::assertInstanceOf(NandFilter::class$nand);
            static::assertCount(1, $nand->getQueries());

            $nameFilter = $nand->getQueries()[0];

            static::assertInstanceOf(EqualsAnyFilter::class$nameFilter);

            $names = $nameFilter->getValue();

            $collection = $this->paymentMethodCollection->filter(
                fn (PaymentMethodEntity $entity) => !\in_array($entity->getName() ?? '', $names, true)
            );
        } else {
            

        );

        foreach ($nested->getParameters() as $key => $value) {
            $type = $nested->getParameterType($key);
            $query->setParameter($key$value$type);
        }
    }

    private function parseFilter(JoinGroup $group, EntityDefinition $definition, QueryBuilder $query, Context $context, string $alias): void
    {
        $filter = new AndFilter($group->getQueries());
        if ($group->getOperator() === MultiFilter::CONNECTION_OR) {
            $filter = new OrFilter($group->getQueries());
        }

        $parsed = $this->parser->parse($filter$definition$context);
        if (empty($parsed->getWheres())) {
            return;
        }

        foreach ($parsed->getParameters() as $key => $value) {
            $query->setParameter($key$value$parsed->getType($key));
        }

    public function testCriteria(): void
    {
        $codes = ['code-123'];

        $template = new PermittedGlobalCodePromotions($codes$this->salesChannel->getId());

        static::assertEquals($this->getExpectedFilter($codes)->getQueries()$template->getQueries());
    }

    /** * @param list<string> $codes */
    private function getExpectedFilter(array $codes): MultiFilter
    {
        return new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [new EqualsFilter('active', true),
                new EqualsFilter('promotion.salesChannels.salesChannelId', $this->salesChannel->getId()),
                
static::assertEmpty($criteria->getSorting());
        static::assertCount(1, $criteria->getFilters());
        static::assertEmpty($criteria->getPostFilters());
        static::assertEmpty($criteria->getAggregations());
        static::assertEmpty($criteria->getAssociations());
        static::assertNull($criteria->getLimit());
        static::assertNull($criteria->getOffset());
        static::assertInstanceOf(MultiFilter::class$criteria->getFilters()[0]);
        /** @var MultiFilter $multiFilter */
        $multiFilter = $criteria->getFilters()[0];
        static::assertEquals(MultiFilter::CONNECTION_OR, $multiFilter->getOperator());
        static::assertCount(2, $multiFilter->getQueries());
    }

    public function testEmptyFiltersAreHandledByEntityReaderWithoutPriorSearch(): void
    {
        $searcherMock = $this->createMock(EntitySearcherInterface::class);
        $searcherMock->expects(static::never())
            ->method('search');

        $repository = new EntityRepository(
            $this->getContainer()->get(CurrencyDefinition::class),
            $this->getContainer()->get(EntityReaderInterface::class),
            
 else {
                $handler->handle($condition$criteria$search$context);
            }
        }

        $query = new BoolQuery();

        if ($search->getPostFilters()) {
            $query->add($search->getPostFilters());
        }

        if ($search->getQueries()->getQueries(BoolQuery::FILTER)) {
            foreach ($search->getQueries()->getQueries(BoolQuery::FILTER) as $filter) {
                $query->add($filter, BoolQuery::FILTER);
            }
        }
        if ($search->getQueries()) {
            $query->add($search->getQueries());
        }

        return $query;
    }
}
$ruleIds,
        ], \JSON_THROW_ON_ERROR));
    }

    public function getCriteriaHash(Criteria $criteria): string
    {
        return md5((string) json_encode([
            $criteria->getIds(),
            $criteria->getFilters(),
            $criteria->getTerm(),
            $criteria->getPostFilters(),
            $criteria->getQueries(),
            $criteria->getSorting(),
            $criteria->getLimit(),
            $criteria->getOffset() ?? 0,
            $criteria->getTotalCountMode(),
            $criteria->getGroupFields(),
            $criteria->getAggregations(),
            $criteria->getAssociations(),
        ], \JSON_THROW_ON_ERROR));
    }
}
// manual sorting provided         if (!empty($this->getSorting())) {
            return false;
        }

        // result will be sorted by interpreted search term and the calculated ranking         if (!empty($this->getTerm())) {
            return false;
        }

        // result will be sorted by calculated ranking         if (!empty($this->getQueries())) {
            return false;
        }

        return true;
    }

    public function removeAssociation(string $association): void
    {
        unset($this->associations[$association]);
    }

    


    public function testCollectQueryWithNoTypes()
    {
        $queries = [
            ['sql' => 'SET sql_mode=(SELECT REPLACE(@@sql_mode, \'ONLY_FULL_GROUP_BY\', \'\'))', 'params' => [], 'types' => null, 'executionMS' => 1],
        ];
        $c = $this->createCollector($queries);
        $c->collect(new Request()new Response());
        $c = unserialize(serialize($c));

        $collectedQueries = $c->getQueries();
        $this->assertSame([]$collectedQueries['default'][0]['types']);
    }
}
 [
                    'type' => 'equals',
                    'field' => 'category',
                    'value' => '5',
                ],
            ],
        ]);

        static::assertEquals('multi', $filter->getType());

        static::assertInstanceOf(MultiFilterStruct::class$filter);
        static::assertCount(2, $filter->getQueries());

        $ratings = $filter->getQueries()[0];
        static::assertInstanceOf(EqualsFilterStruct::class$ratings);
        static::assertEquals('ratings', $ratings->getField());
        static::assertEquals('2', $ratings->getValue());

        $category = $filter->getQueries()[1];
        static::assertInstanceOf(EqualsFilterStruct::class$category);
        static::assertEquals('category', $category->getField());
        static::assertEquals('5', $category->getValue());
    }

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