示例#1
0
 /**
  * {@inheritdoc}
  */
 public function query(RequestInterface $request)
 {
     $query = $this->mapper->buildQuery($request);
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $table = $temporaryStorage->storeDocumentsFromSelect($query);
     $documents = $this->getDocuments($table);
     $aggregations = $this->aggregationBuilder->build($request, $table, $documents);
     $response = ['documents' => $documents, 'aggregations' => $aggregations];
     return $this->responseFactory->create($response);
 }
示例#2
0
 /**
  * @inheritdoc
  */
 protected function _renderFiltersBefore()
 {
     if ($this->filters) {
         foreach ($this->filters as $attributes) {
             foreach ($attributes as $attributeCode => $attributeValue) {
                 $attributeCode = $this->getAttributeCode($attributeCode);
                 $this->addAttributeToSearch($attributeCode, $attributeValue);
             }
         }
         $searchCriteria = $this->getSearchCriteriaBuilder()->create();
         $searchCriteria->setRequestName('advanced_search_container');
         try {
             $searchResult = $this->getSearch()->search($searchCriteria);
         } catch (EmptyRequestDataException $e) {
             /** @var \Magento\Framework\Api\Search\SearchResultInterface $searchResult */
             $searchResult = $this->searchResultFactory->create()->setItems([]);
         } catch (NonExistingRequestNameException $e) {
             $this->_logger->error($e->getMessage());
             throw new LocalizedException(__('Sorry, something went wrong. You can find out more in the error log.'));
         }
         $temporaryStorage = $this->temporaryStorageFactory->create();
         $table = $temporaryStorage->storeApiDocuments($searchResult->getItems());
         $this->getSelect()->joinInner(['search_result' => $table->getName()], 'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, []);
     }
     parent::_renderFiltersBefore();
 }
 /**
  * @inheritdoc
  */
 protected function _renderFiltersBefore()
 {
     $this->getSearchCriteriaBuilder();
     $this->getFilterBuilder();
     $this->getSearch();
     if ($this->queryText) {
         $this->filterBuilder->setField('search_term');
         $this->filterBuilder->setValue($this->queryText);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     $priceRangeCalculation = $this->_scopeConfig->getValue(\Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory::XML_PATH_RANGE_CALCULATION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($priceRangeCalculation) {
         $this->filterBuilder->setField('price_dynamic_algorithm');
         $this->filterBuilder->setValue($priceRangeCalculation);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     $searchCriteria = $this->searchCriteriaBuilder->create();
     $searchCriteria->setRequestName($this->searchRequestName);
     $this->searchResult = $this->search->search($searchCriteria);
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $table = $temporaryStorage->storeApiDocuments($this->searchResult->getItems());
     $this->getSelect()->joinInner(['search_result' => $table->getName()], 'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, []);
     $this->_totalRecords = $this->searchResult->getTotalCount();
     if ($this->order && 'relevance' === $this->order['field']) {
         $this->getSelect()->order('search_result.' . TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
     }
     return parent::_renderFiltersBefore();
 }
 /**
  * {@inheritdoc}
  */
 public function query(RequestInterface $request)
 {
     $query = $this->catalogSearchHelper->getEscapedQueryText();
     $storeId = $this->storeManager->getStore()->getId();
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $documents = [];
     $table = null;
     if (!$this->config->getApplicationID($storeId) || !$this->config->getAPIKey($storeId) || $this->config->isEnabledFrontEnd($storeId) === false || $this->config->makeSeoRequest($storeId) === '0' || $this->request->getControllerName() === 'category' && $this->config->replaceCategories($storeId) == false) {
         $query = $this->mapper->buildQuery($request);
         $table = $temporaryStorage->storeDocumentsFromSelect($query);
         $documents = $this->getDocuments($table);
     } else {
         $algolia_query = $query !== '__empty__' ? $query : '';
         //If instant search is on, do not make a search query unless SEO request is set to 'Yes'
         if (!$this->config->isInstantEnabled($storeId) || $this->config->makeSeoRequest($storeId)) {
             $documents = $this->algoliaHelper->getSearchResult($algolia_query, $storeId);
         }
         $getDocumentMethod = 'getDocument21';
         $storeDocumentsMethod = 'storeApiDocuments';
         if (version_compare($this->config->getMagentoVersion(), '2.1.0', '<') === true) {
             $getDocumentMethod = 'getDocument20';
             $storeDocumentsMethod = 'storeDocuments';
         }
         $apiDocuments = array_map(function ($document) use($getDocumentMethod) {
             return $this->{$getDocumentMethod}($document);
         }, $documents);
         $table = $temporaryStorage->{$storeDocumentsMethod}($apiDocuments);
     }
     $aggregations = $this->aggregationBuilder->build($request, $table);
     $response = ['documents' => $documents, 'aggregations' => $aggregations];
     return $this->responseFactory->create($response);
 }
示例#5
0
 /**
  * @param QueryContainerFactory   $queryContainerFactory
  * @param Match                   $matchBuilder
  * @param TemporaryStorageFactory $temporaryStorageFactory
  * @param IndexFactory            $indexFactory
  * @param IndexScopeResolver      $scopeResolver
  * @param Engine                  $engine
  * @param MysqlDocumentFactory    $documentFactory
  */
 public function __construct(QueryContainerFactory $queryContainerFactory, Match $matchBuilder, TemporaryStorageFactory $temporaryStorageFactory, IndexFactory $indexFactory, IndexScopeResolver $scopeResolver, Engine $engine, MysqlDocumentFactory $documentFactory)
 {
     $this->queryContainerFactory = $queryContainerFactory;
     $this->matchBuilder = $matchBuilder;
     $this->temporaryStorage = $temporaryStorageFactory->create();
     $this->indexFactory = $indexFactory;
     $this->scopeResolver = $scopeResolver;
     $this->engine = $engine;
     $this->documentFactory = $documentFactory;
 }
示例#6
0
 /**
  * @param ScoreBuilderFactory $scoreBuilderFactory
  * @param Builder $filterBuilder
  * @param ConditionManager $conditionManager
  * @param ResourceConnection $resource
  * @param EntityMetadata $entityMetadata
  * @param QueryContainerFactory $queryContainerFactory
  * @param Query\Builder\Match $matchBuilder
  * @param TemporaryStorageFactory $temporaryStorageFactory
  * @param IndexBuilderInterface[] $indexProviders
  */
 public function __construct(ScoreBuilderFactory $scoreBuilderFactory, Builder $filterBuilder, ConditionManager $conditionManager, ResourceConnection $resource, EntityMetadata $entityMetadata, QueryContainerFactory $queryContainerFactory, Match $matchBuilder, TemporaryStorageFactory $temporaryStorageFactory, array $indexProviders)
 {
     $this->scoreBuilderFactory = $scoreBuilderFactory;
     $this->filterBuilder = $filterBuilder;
     $this->conditionManager = $conditionManager;
     $this->resource = $resource;
     $this->entityMetadata = $entityMetadata;
     $this->indexProviders = $indexProviders;
     $this->queryContainerFactory = $queryContainerFactory;
     $this->matchBuilder = $matchBuilder;
     $this->temporaryStorage = $temporaryStorageFactory->create();
 }
示例#7
0
 /**
  * {@inheritdoc}
  */
 public function query(RequestInterface $request)
 {
     $query = $this->mapper->buildQuery($request);
     if ($request->getName() == 'quick_search_container') {
         $query->limit($this->searchConfig->getResultsLimit());
     }
     if (isset($_GET) && isset($_GET['debug'])) {
         echo '<hr>' . $query . '<hr>';
     }
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $table = $temporaryStorage->storeDocumentsFromSelect($query);
     $this->searchHelper->prepareTemporaryTable($table);
     $documents = $this->getDocuments($table);
     $aggregations = $this->aggregationBuilder->build($request, $table);
     $response = ['documents' => $documents, 'aggregations' => $aggregations];
     return $this->responseFactory->create($response);
 }
示例#8
0
 /**
  * @param RequestInterface $request
  * @return \Magento\Framework\Search\Response\QueryResponse
  */
 public function query(RequestInterface $request)
 {
     try {
         $query = $this->mapper->buildQuery($request);
         $query->limit($this->searchConfig->getResultsLimit());
     } catch (\Exception $e) {
         // fallback engine
         $objectManager = ObjectManager::getInstance();
         return $objectManager->create('Mirasvit\\SearchMysql\\Model\\Adapter')->query($request);
     }
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $table = $temporaryStorage->storeDocumentsFromSelect($query);
     $this->searchHelper->prepareTemporaryTable($table);
     $documents = $this->getDocuments($table);
     $aggregations = $this->aggregationBuilder->build($request, $table);
     $response = ['documents' => $documents, 'aggregations' => $aggregations];
     return $this->responseFactory->create($response);
 }
 /**
  * @inheritdoc
  */
 protected function _renderFiltersBefore()
 {
     if ($this->filters) {
         foreach ($this->filters as $attributes) {
             foreach ($attributes as $attributeCode => $attributeValue) {
                 $attributeCode = $this->getAttributeCode($attributeCode);
                 $this->addAttributeToSearch($attributeCode, $attributeValue);
             }
         }
         $searchCriteria = $this->searchCriteriaBuilder->create();
         $searchCriteria->setRequestName('advanced_search_container');
         $searchResult = $this->search->search($searchCriteria);
         $temporaryStorage = $this->temporaryStorageFactory->create();
         $table = $temporaryStorage->storeApiDocuments($searchResult->getItems());
         $this->getSelect()->joinInner(['search_result' => $table->getName()], 'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, []);
     }
     parent::_renderFiltersBefore();
 }
示例#10
0
 /**
  * @inheritdoc
  */
 protected function _renderFiltersBefore()
 {
     if ($this->filters) {
         $this->requestBuilder->bindDimension('scope', $this->getStoreId());
         $this->requestBuilder->setRequestName('advanced_search_container');
         foreach ($this->filters as $attributes) {
             foreach ($attributes as $attributeCode => $attributeValue) {
                 $attributeCode = $this->getAttributeCode($attributeCode);
                 $this->requestBuilder->bindRequestValue($attributeCode, $attributeValue);
             }
         }
         $queryRequest = $this->requestBuilder->create();
         $queryResponse = $this->searchEngine->search($queryRequest);
         $temporaryStorage = $this->temporaryStorageFactory->create();
         $table = $temporaryStorage->storeDocuments($queryResponse->getIterator());
         $this->getSelect()->joinInner(['search_result' => $table->getName()], 'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, []);
     }
     return parent::_renderFiltersBefore();
 }
示例#11
0
 /**
  * Join matches to collection
  *
  * @param AbstractDb $collection
  * @param string     $field
  *
  * @return $this
  */
 public function joinMatches($collection, $field = 'e.entity_id')
 {
     $requestBuilder = $this->requestBuilderFactory->create();
     $queryText = $this->queryFactory->get()->getQueryText();
     $requestBuilder->bind('search_term', $queryText);
     $requestBuilder->bindDimension('scope', $this->scopeResolver->getScope());
     $requestBuilder->setRequestName($this->index->getCode());
     $queryRequest = $requestBuilder->create();
     $queryResponse = $this->searchEngine->search($queryRequest);
     $temporaryStorage = $this->temporaryStorageFactory->create();
     if ($field == 'ID') {
         //external connection (need improve detection)
         $ids = [0];
         foreach ($queryResponse->getIterator() as $item) {
             $ids[] = $item->getId();
         }
         $collection->getSelect()->where(new \Zend_Db_Expr("{$field} IN (" . implode(',', $ids) . ")"));
     } else {
         $table = $temporaryStorage->storeDocuments($queryResponse->getIterator());
         $collection->getSelect()->joinInner(['search_result' => $table->getName()], $field . ' = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, []);
     }
     return $this;
 }
示例#12
0
 /**
  * @inheritdoc
  */
 protected function _renderFiltersBefore()
 {
     $this->getSearchCriteriaBuilder();
     $this->getFilterBuilder();
     $this->getSearch();
     if ($this->queryText) {
         $this->filterBuilder->setField('search_term');
         $this->filterBuilder->setValue($this->queryText);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     $priceRangeCalculation = $this->_scopeConfig->getValue(\Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory::XML_PATH_RANGE_CALCULATION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($priceRangeCalculation) {
         $this->filterBuilder->setField('price_dynamic_algorithm');
         $this->filterBuilder->setValue($priceRangeCalculation);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     $searchCriteria = $this->searchCriteriaBuilder->create();
     $searchCriteria->setRequestName($this->searchRequestName);
     try {
         $this->searchResult = $this->getSearch()->search($searchCriteria);
     } catch (EmptyRequestDataException $e) {
         /** @var \Magento\Framework\Api\Search\SearchResultInterface $searchResult */
         $this->searchResult = $this->searchResultFactory->create()->setItems([]);
     } catch (NonExistingRequestNameException $e) {
         $this->_logger->error($e->getMessage());
         throw new LocalizedException(__('Sorry, something went wrong. You can find out more in the error log.'));
     }
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $table = $temporaryStorage->storeApiDocuments($this->searchResult->getItems());
     $this->getSelect()->joinInner(['search_result' => $table->getName()], 'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, []);
     $this->_totalRecords = $this->searchResult->getTotalCount();
     if ($this->order && 'relevance' === $this->order['field']) {
         $this->getSelect()->order('search_result.' . TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
     }
     return parent::_renderFiltersBefore();
 }