buildSearch example

 {
        $this->client = $client;
        $this->indexFactory = $indexFactory;
        $this->handlerRegistry = $handlerRegistry;
    }

    /** * {@inheritdoc} */
    public function search(Criteria $criteria, ShopContextInterface $context)
    {
        $search = $this->buildSearch($criteria$context);
        $index = $this->indexFactory->createShopIndex($context->getShop(), ProductMapping::TYPE);

        $arguments = [
            'index' => $index->getName(),
            'body' => $search->toArray(),
            'rest_total_hits_as_int' => true,
            'track_total_hits' => true,
        ];

        $data = $this->client->search($arguments);

        
$term = (string) mb_eregi_replace('\s(and)\s', ' + ', $term);
        $term = (string) mb_eregi_replace('\s(not)\s', ' -', $term);

        foreach ($entities as $entityName) {
            if (!$context->isAllowed($entityName . ':' . AclRoleDefinition::PRIVILEGE_READ)) {
                continue;
            }

            $indexer = $this->registry->getIndexer($entityName);
            $alias = $this->adminEsHelper->getIndex($indexer->getName());
            $index[] = ['index' => $alias];
            $query = $indexer->globalCriteria($term$this->buildSearch($term$limit))->toArray();
            $query['timeout'] = $this->timeout;

            $index[] = $query;
        }

        $responses = $this->client->msearch(['body' => $index]);

        $result = [];
        foreach ($responses['responses'] as $response) {
            if (empty($response['hits']['hits'])) {
                continue;
            }
Home | Imprint | This part of the site doesn't use cookies.