private function searchBlog(Criteria $criteria, Struct\ProductContextInterface $context) { /**@var $condition SearchTermCondition*/ $condition = $criteria->getCondition('search'); $query = $this->createMultiMatchQuery($condition); $search = new Search(); $search->addQuery($query); $search->setFrom(0)->setSize(5); $index = $this->indexFactory->createShopIndex($context->getShop()); $params = ['index' => $index->getName(), 'type' => 'blog', 'body' => $search->toArray()]; $raw = $this->client->search($params); return $this->createBlogStructs($raw); }
/** * {@inheritdoc} */ public function hydrate(array $elasticResult, ProductNumberSearchResult $result, Criteria $criteria, ShopContextInterface $context) { if (!isset($elasticResult['aggregations'])) { return; } if (!isset($elasticResult['aggregations']['agg_properties'])) { return; } $data = $elasticResult['aggregations']['agg_properties']['buckets']; $ids = array_column($data, 'key'); if (empty($ids)) { return; } $groupIds = $this->getGroupIds($ids); $search = new Search(); $search->addFilter(new IdsFilter($groupIds)); $search->addFilter(new TermFilter('filterable', 1)); $search->addSort(new FieldSort('name')); $index = $this->indexFactory->createShopIndex($context->getShop()); $data = $this->client->search(['index' => $index->getName(), 'type' => PropertyMapping::TYPE, 'body' => $search->toArray()]); $data = $data['hits']['hits']; $properties = $this->hydrateProperties($data, $ids); $actives = $this->getFilteredValues($criteria); $criteriaPart = $this->createCollectionResult($properties, $actives); $result->addFacet($criteriaPart); }
/** * {@inheritdoc} */ public function search(Criteria $criteria, ShopContextInterface $context) { $search = $this->buildSearch($criteria, $context); $index = $this->indexFactory->createShopIndex($context->getShop()); $data = $this->client->search(['index' => $index->getName(), 'type' => ProductMapping::TYPE, 'body' => $search->toArray()]); $products = $this->createProducts($data); $result = new ProductNumberSearchResult($products, $data['hits']['total'], []); if (isset($data['hits']['max_score'])) { $result->addAttribute('elastic_search', new Attribute(['max_score' => $data['hits']['max_score']])); } foreach ($this->handlers as $handler) { if (!$handler instanceof ResultHydratorInterface) { continue; } $handler->hydrate($data, $result, $criteria, $context); } return $result; }
/** * Removes unused indices */ public function cleanupIndices() { $prefix = $this->indexFactory->getPrefix(); $aliases = $this->client->indices()->getAliases(); foreach ($aliases as $index => $indexAliases) { if (strpos($index, $prefix) !== 0) { continue; } if (empty($indexAliases['aliases'])) { $this->client->indices()->delete(['index' => $index]); } } }
/** * {@inheritdoc} */ public function getList($products, Struct\ProductContextInterface $context) { $result = $this->getDefined($products, $context); $fallback = $this->findFallbackProducts($products, $result); if (empty($fallback)) { return $result; } $limit = (int) $this->config->get('similarLimit'); if ($limit <= 0) { return $result; } foreach ($fallback as $product) { $search = $this->getSearch($product, $context, $limit); $body = $search->toArray(); $index = $this->indexFactory->createShopIndex($context->getShop()); $similar = $this->client->search(['index' => $index->getName(), 'type' => ProductMapping::TYPE, 'body' => $body]); if (empty($similar['hits']['hits'])) { continue; } $numbers = array_column($similar['hits']['hits'], '_id'); $result[$product->getNumber()] = $this->listProductService->getList($numbers, $context); } return $result; }