Example #1
0
 public function hydrate(array $elasticResult, ProductNumberSearchResult $result, Criteria $criteria, ShopContextInterface $context)
 {
     if (!isset($elasticResult['aggregations']['agg_sales'])) {
         return;
     }
     $data = $elasticResult['aggregations']['agg_sales'];
     $actives = $this->getActiveValues($criteria, $data);
     $facetResult = new RangeFacetResult('swag_product_es_sales', $criteria->hasCondition('swag_es_product_sales'), 'Sales', $data['min'], $data['max'], $actives['min'], $actives['max'], 'minSales', 'maxSales');
     $result->addFacet($facetResult);
 }
Example #2
0
 /**
  * Traces the search result into the s_statistic_search
  *
  * @param Criteria $criteria
  * @param ProductNumberSearchResult $result
  * @param Shop $shop
  */
 public function logResult(Criteria $criteria, ProductNumberSearchResult $result, Shop $shop)
 {
     if (!$criteria->hasCondition('search')) {
         return;
     }
     /* @var $condition SearchTermCondition */
     $condition = $criteria->getCondition('search');
     $now = new \DateTime();
     $this->connection->insert('s_statistics_search', ['datum' => $now->format('Y-m-d H:i:s'), 'searchterm' => $condition->getTerm(), 'results' => $result->getTotalCount(), 'shop_id' => $shop->getId()]);
 }
 /**
  * {@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;
 }
 /**
  * {@inheritdoc}
  */
 public function hydrate(array $elasticResult, ProductNumberSearchResult $result, Criteria $criteria, ShopContextInterface $context)
 {
     if (!isset($elasticResult['aggregations'])) {
         return;
     }
     if (!isset($elasticResult['aggregations']['agg_has_available_variant_filter'])) {
         return;
     }
     $data = $elasticResult['aggregations']['agg_has_available_variant_filter']['agg_has_available_variant_count'];
     if ($data['value'] <= 0) {
         return;
     }
     $criteriaPart = $this->createFacet($criteria);
     $result->addFacet($criteriaPart);
 }
 /**
  * {@inheritdoc}
  */
 public function hydrate(array $elasticResult, ProductNumberSearchResult $result, Criteria $criteria, ShopContextInterface $context)
 {
     if (!isset($elasticResult['aggregations'])) {
         return;
     }
     if (!isset($elasticResult['aggregations']['agg_price'])) {
         return;
     }
     $data = $elasticResult['aggregations']['agg_price'];
     if ($data['count'] <= 0) {
         return;
     }
     $criteriaPart = $this->createFacet($criteria, (double) $data['min'], (double) $data['max']);
     $result->addFacet($criteriaPart);
 }
 /**
  * {@inheritdoc}
  */
 public function hydrate(array $elasticResult, ProductNumberSearchResult $result, Criteria $criteria, ShopContextInterface $context)
 {
     if (!isset($elasticResult['aggregations']['agg_manufacturer'])) {
         return;
     }
     $buckets = $elasticResult['aggregations']['agg_manufacturer']['buckets'];
     if (empty($buckets)) {
         return;
     }
     $manufacturers = $this->getManufacturers($buckets, $context);
     $items = $this->createListItems($criteria, $manufacturers);
     $criteriaPart = $this->createFacet($criteria, $items);
     $result->addFacet($criteriaPart);
 }
Example #7
0
 /**
  * @param SearchBundle\ProductNumberSearchResult $searchResult
  * @param $orderNumber
  * @param $categoryId
  * @param StoreFrontBundle\Struct\ProductContextInterface $context
  * @return array
  */
 private function buildNavigation(SearchBundle\ProductNumberSearchResult $searchResult, $orderNumber, $categoryId, StoreFrontBundle\Struct\ProductContextInterface $context)
 {
     $products = $searchResult->getProducts();
     $products = array_values($products);
     if (empty($products)) {
         return array();
     }
     /** @var $currentProduct BaseProduct */
     foreach ($products as $index => $currentProduct) {
         if ($currentProduct->getNumber() != $orderNumber) {
             continue;
         }
         $previousProduct = isset($products[$index - 1]) ? $products[$index - 1] : null;
         $nextProduct = isset($products[$index + 1]) ? $products[$index + 1] : null;
         $navigation = array();
         if ($previousProduct) {
             $previousProduct = $this->listProductService->get($previousProduct->getNumber(), $context);
             $navigation["previousProduct"]["orderNumber"] = $previousProduct->getNumber();
             $navigation["previousProduct"]["link"] = $this->config->get('sBASEFILE') . "?sViewport=detail&sDetails=" . $previousProduct->getId() . "&sCategory=" . $categoryId;
             $navigation["previousProduct"]["name"] = $previousProduct->getName();
             $previousCover = $previousProduct->getCover();
             if ($previousCover) {
                 $navigation["previousProduct"]["image"] = $this->legacyStructConverter->convertMediaStruct($previousCover);
             }
         }
         if ($nextProduct) {
             $nextProduct = $this->listProductService->get($nextProduct->getNumber(), $context);
             $navigation["nextProduct"]["orderNumber"] = $nextProduct->getNumber();
             $navigation["nextProduct"]["link"] = $this->config->get('sBASEFILE') . "?sViewport=detail&sDetails=" . $nextProduct->getId() . "&sCategory=" . $categoryId;
             $navigation["nextProduct"]["name"] = $nextProduct->getName();
             $nextCover = $nextProduct->getCover();
             if ($nextCover) {
                 $navigation["nextProduct"]["image"] = $this->legacyStructConverter->convertMediaStruct($nextCover);
             }
         }
         $navigation["currentListing"]["position"] = $index + 1;
         $navigation["currentListing"]["totalCount"] = $searchResult->getTotalCount();
         return $navigation;
     }
     return array();
 }
 /**
  * {@inheritdoc}
  */
 public function hydrate(array $elasticResult, ProductNumberSearchResult $result, Criteria $criteria, ShopContextInterface $context)
 {
     if (!isset($elasticResult['aggregations'])) {
         return;
     }
     $aggregations = $elasticResult['aggregations'];
     foreach ($this->criteriaParts as $criteriaPart) {
         $key = 'agg_' . $criteriaPart->getName();
         if (!isset($aggregations[$key])) {
             continue;
         }
         switch ($criteriaPart->getMode()) {
             case ProductAttributeFacet::MODE_VALUE_LIST_RESULT:
             case ProductAttributeFacet::MODE_RADIO_LIST_RESULT:
                 $criteriaPartResult = $this->createItemListResult($criteriaPart, $aggregations[$key], $criteria);
                 break;
             case ProductAttributeFacet::MODE_BOOLEAN_RESULT:
                 $criteriaPartResult = $this->createBooleanResult($criteriaPart, $aggregations[$key], $criteria);
                 break;
             case ProductAttributeFacet::MODE_RANGE_RESULT:
                 $criteriaPartResult = $this->createRangeResult($criteriaPart, $aggregations[$key], $criteria);
                 break;
             default:
                 $criteriaPartResult = null;
         }
         if ($criteriaPartResult) {
             $result->addFacet($criteriaPartResult);
         }
     }
 }
 /**
  * {@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);
 }
Example #10
0
 protected function assertSearchResultSorting(ProductNumberSearchResult $result, $expectedNumbers)
 {
     $productResult = array_values($result->getProducts());
     /**@var $product SearchProduct*/
     foreach ($productResult as $index => $product) {
         $expectedProduct = $expectedNumbers[$index];
         $this->assertEquals($expectedProduct, $product->getNumber(), sprintf('Expected %s at search result position %s, but got product %s', $expectedProduct, $index, $product->getNumber()));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function hydrate(array $elasticResult, ProductNumberSearchResult $result, Criteria $criteria, ShopContextInterface $context)
 {
     if (!isset($elasticResult['aggregations'])) {
         return;
     }
     if (!isset($elasticResult['aggregations']['agg_category'])) {
         return;
     }
     $data = $elasticResult['aggregations']['agg_category']['buckets'];
     $ids = $this->getCategoryIds($criteria, $data);
     $categories = $this->categoryService->getList($ids, $context);
     $active = [];
     if ($criteria->hasCondition('category')) {
         /**@var $condition CategoryCondition*/
         $condition = $criteria->getCondition('category');
         $active = $condition->getCategoryIds();
     }
     $criteriaPart = $this->createTreeFacet($categories, $active);
     $result->addFacet($criteriaPart);
 }