allowSearch example

$this->createMock(Client::class),
            $registry,
            $this->createMock(CriteriaParser::class),
            $this->createMock(LoggerInterface::class),
            $this->createMock(AbstractKeyValueStorage::class)
        );

        $criteria = new Criteria();
        $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);

        static::assertTrue(
            $helper->allowSearch(new ProductDefinition(), Context::createDefaultContext()$criteria)
        );

        static::assertFalse(
            $helper->allowSearch(new CategoryDefinition(), Context::createDefaultContext()$criteria)
        );

        $helper->setEnabled(false);

        static::assertFalse(
            $helper->allowSearch(new ProductDefinition(), Context::createDefaultContext()$criteria)
        );
    }
private readonly ElasticsearchHelper $helper,
        private readonly Client $client,
        private readonly EntityAggregatorInterface $decorated,
        private readonly AbstractElasticsearchAggregationHydrator $hydrator,
        private readonly EventDispatcherInterface $eventDispatcher,
        private readonly string $timeout = '5s'
    ) {
    }

    public function aggregate(EntityDefinition $definition, Criteria $criteria, Context $context): AggregationResultCollection
    {
        if (!$this->helper->allowSearch($definition$context$criteria)) {
            return $this->decorated->aggregate($definition$criteria$context);
        }

        $search = $this->createSearch($definition$criteria$context);

        $this->eventDispatcher->dispatch(
            new ElasticsearchEntityAggregatorSearchEvent($search$definition$criteria$context)
        );

        $searchArray = $search->toArray();
        $searchArray['timeout'] = $this->timeout;

        

    public function __construct(
        private readonly ProductSearchBuilderInterface $decorated,
        private readonly ElasticsearchHelper $helper,
        private readonly ProductDefinition $productDefinition,
        private readonly int $searchTermMaxLength = 300
    ) {
    }

    public function build(Request $request, Criteria $criteria, SalesChannelContext $context): void
    {
        if (!$this->helper->allowSearch($this->productDefinition, $context->getContext()$criteria)) {
            $this->decorated->build($request$criteria$context);

            return;
        }

        $search = $request->get('search');

        if (\is_array($search)) {
            $term = implode(' ', $search);
        } else {
            $term = (string) $search;
        }
private readonly EntitySearcherInterface $decorated,
        private readonly ElasticsearchHelper $helper,
        private readonly CriteriaParser $criteriaParser,
        private readonly AbstractElasticsearchSearchHydrator $hydrator,
        private readonly EventDispatcherInterface $eventDispatcher,
        private readonly string $timeout = '5s'
    ) {
    }

    public function search(EntityDefinition $definition, Criteria $criteria, Context $context): IdSearchResult
    {
        if (!$this->helper->allowSearch($definition$context$criteria)) {
            return $this->decorated->search($definition$criteria$context);
        }

        if ($criteria->getLimit() === 0) {
            return new IdSearchResult(0, []$criteria$context);
        }

        $search = $this->createSearch($criteria$definition$context);

        $this->eventDispatcher->dispatch(
            new ElasticsearchEntitySearcherSearchEvent(
                
Home | Imprint | This part of the site doesn't use cookies.