Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getResultsForTaxon(TaxonQuery $query)
 {
     if (isset($this->facetGroup)) {
         $this->initializeFacetGroup($this->facetGroup);
     }
     $channel = $this->channelContext->getChannel();
     // First get ALL products from the taxon to get their ids
     $paginator = $this->productRepository->createByTaxonPaginator($query->getTaxon(), array('channels' => $channel));
     $ids = array();
     $pages = $paginator->getNbPages();
     for ($i = 1; $i <= $pages; $i++) {
         $paginator->setCurrentPage($i);
         foreach ($paginator->getIterator() as $product) {
             $ids[] = $product->getId();
         }
     }
     // Now apply any filtered facets to reduce the available products
     $queryBuilder = $this->em->createQueryBuilder();
     $queryBuilder->select('u.itemId, u.tags, u.entity')->from(SearchIndex::class, 'u')->where('u.itemId IN (:ids)')->setParameter('ids', $ids);
     $indexedItems = $queryBuilder->getQuery()->getResult();
     // TODO: Need to configure / refactor this default!
     $entityName = "Product";
     $facetsArray = array();
     if ($indexedItems) {
         $entityName = $indexedItems[0]['entity'];
     }
     list($facetFilteredIds, $idsFromAllFacets) = $this->getFilteredIds($query->getAppliedFilters(), $ids, $entityName);
     if (isset($this->facetGroup) && $indexedItems) {
         foreach ($indexedItems as $item) {
             $facetsArray[$item['itemId']] = $item['tags'];
         }
         $this->facets = $this->calculateNewFacets($facetsArray, $facetFilteredIds);
     }
     if (count($idsFromAllFacets)) {
         $this->paginator = $this->productRepository->createByTaxonPaginator($query->getTaxon(), array('id' => $idsFromAllFacets, 'channels' => $channel));
     } else {
         $this->paginator = new Pagerfanta(new ArrayAdapter(array()));
     }
     $this->filters = $query->getAppliedFilters();
     return $this;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getResultsForTaxon(TaxonQuery $query)
 {
     if (isset($this->facetGroup)) {
         $this->initializeFacetGroup($this->facetGroup);
     }
     $elasticaQuery = $this->compileElasticaTaxonQuery($query->getAppliedFilters(), $this->config, $query->getTaxon()->getName(), $this->targetTypes);
     $elasticaQuery->setSize($this->resultSetSize);
     $objects = $this->targetIndex->search($elasticaQuery);
     $mapping = $this->targetIndex->getMapping();
     $facets = null;
     if (isset($this->facetGroup)) {
         $facets = $this->transformFacetsForPresentation($objects, $query->getAppliedFilters());
     }
     $results = array();
     foreach ($objects as $object) {
         $results[$mapping[$object->getType()]['_meta']['model']][] = $object->getId();
     }
     $paginator = $this->searchRepository->getArrayPaginator($this->searchRepository->hydrateSearchResults($results));
     $this->facets = $facets;
     $this->paginator = $paginator;
     $this->filters = $query->getAppliedFilters();
     return $this;
 }