EsSearch example

$result = $this->fetch($search);

        return $this->iterate($result);
    }

    /** * @return EsSearch */
    protected function buildSearchObject(SearchCriteria $criteria)
    {
        $search = new EsSearch();

        if ($criteria->offset) {
            $search->setFrom($criteria->offset);
        }
        if ($criteria->limit) {
            $search->setSize($criteria->limit);
        }

        if ($criteria->term) {
            $search->addQuery($this->buildSearchQuery($criteria));
        }

        


        $data = $elasticResult['aggregations']['properties']['buckets'];
        $ids = array_column($data, 'key');

        if (empty($ids)) {
            return;
        }

        $groupIds = $this->getGroupIds($ids);

        $search = new EsSearch();
        $search->addQuery(new IdsQuery($groupIds), BoolQuery::FILTER);
        $search->addQuery(new TermQuery('filterable', true), BoolQuery::FILTER);
        $search->addSort(new FieldSort('name', 'asc'));
        $search->setFrom(0);
        $search->setSize(self::AGGREGATION_SIZE);

        $index = $this->indexFactory->createShopIndex($context->getShop(), PropertyMapping::TYPE);

        $arguments = [
            'index' => $index->getName(),
            'body' => $search->toArray(),
            
public function __construct(Container $container)
    {
        $this->container = $container;
    }

    /** * @return BoolQuery */
    public function build(array $conditions, Criteria $criteria, ShopContextInterface $context)
    {
        $search = new EsSearch();
        $handlerRegistry = $this->container->get(HandlerRegistry::class);

        if (!$handlerRegistry instanceof HandlerRegistry) {
            throw new RuntimeException(sprintf('%s is missing', HandlerRegistry::class));
        }

        foreach ($conditions as $condition) {
            $handler = $handlerRegistry->getHandler($condition);

            if ($handler instanceof PartialConditionHandlerInterface) {
                $handler->handleFilter($condition$criteria$search$context);
            }
return new ProductNumberSearchResult(
            $products,
            $data['hits']['total'],
            $facets,
            $result->getAttributes()
        );
    }

    private function buildSearch(Criteria $criteria, ShopContextInterface $context): EsSearch
    {
        $search = new EsSearch();

        $this->addConditions($criteria$context$search);
        $this->addCriteriaParts($criteria$context$search$criteria->getSortings());
        $this->addCriteriaParts($criteria$context$search$criteria->getFacets());

        if ($criteria->getOffset() !== null) {
            $search->setFrom($criteria->getOffset());
        }
        if ($criteria->getLimit() !== null) {
            $search->setSize($criteria->getLimit());
        }

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