createSearch example

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(
                $search,
                $definition,
                $criteria,
                $context
            )
        );

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

        
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;

        try {
            $result = $this->client->search([
                'index' => $this->helper->getIndexName($definition$this->helper->enabledMultilingualIndex() ? null : $context->getLanguageId()),
                
Home | Imprint | This part of the site doesn't use cookies.