Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getResults(SearchStringQuery $query)
 {
     if (isset($this->facetGroup)) {
         $this->initializeFacetGroup($this->facetGroup);
     }
     $elasticaQuery = $this->compileElasticSearchStringQuery($query->getSearchTerm(), $query->getAppliedFilters(), $this->config, $query->getSearchParam(), $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;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getResults(SearchStringQuery $query)
 {
     if (isset($this->facetGroup)) {
         $this->initializeFacetGroup($this->facetGroup);
     }
     $finalResults = $facets = array();
     $modelIdsForChannel = $this->searchRepository->getProductIdsFromChannel($this->channelContext->getChannel());
     // get ids and tags from full text search
     foreach ($this->query($query->getSearchTerm(), $this->em) as $modelClass => $modelIdsToTags) {
         $modelIds = array_keys($modelIdsToTags);
         if (isset($modelIdsForChannel[$modelClass])) {
             $modelIds = array_intersect($modelIds, $modelIdsForChannel[$modelClass]);
         }
         //filter the ids if searchParam is not all
         // TODO: Will refactor pre-search filtering into a service based on the finder configuration
         if ($query->getSearchParam() != 'all' && $query->isDropdownFilterEnabled()) {
             $preFilteredModelIds = $this->searchRepository->getProductIdsFromTaxonName($query->getSearchParam());
             if (isset($preFilteredModelIds[$modelClass])) {
                 $modelIds = array_intersect($modelIds, $preFilteredModelIds[$modelClass]);
             } else {
                 $modelIds = array();
             }
         }
         $appliedFilters = $query->getAppliedFilters() ?: array();
         $finalResults[$modelClass] = array();
         if (!empty($modelIds)) {
             list($modelIdsForFacets, $finalResults[$modelClass]) = $this->getFilteredIds($appliedFilters, $modelIds, $modelClass);
             if (isset($this->facetGroup)) {
                 $facets = array_merge_recursive($facets, $this->calculateNewFacets($modelIdsToTags, $modelIdsForFacets));
             }
         }
     }
     $paginator = $this->searchRepository->getArrayPaginator($this->searchRepository->hydrateSearchResults($finalResults));
     $this->facets = $facets;
     $this->paginator = $paginator;
     $this->filters = $query->getAppliedFilters();
     return $this;
 }