/** * @inheritdoc */ protected function _renderFiltersBefore() { $this->requestBuilder->bindDimension('scope', $this->getStoreId()); if ($this->queryText) { $this->requestBuilder->bind('search_term', $this->queryText); } $priceRangeCalculation = $this->_scopeConfig->getValue(\Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory::XML_PATH_RANGE_CALCULATION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if ($priceRangeCalculation) { $this->requestBuilder->bind('price_dynamic_algorithm', $priceRangeCalculation); } $this->requestBuilder->setRequestName($this->searchRequestName); $queryRequest = $this->requestBuilder->create(); $this->queryResponse = $this->searchEngine->search($queryRequest); $temporaryStorage = $this->temporaryStorageFactory->create(); $table = $temporaryStorage->storeDocuments($this->queryResponse->getIterator()); $this->getSelect()->joinInner(['search_result' => $table->getName()], 'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, []); $this->_totalRecords = $this->queryResponse->count(); if ($this->order && 'relevance' === $this->order['field']) { $this->getSelect()->order('search_result.' . TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']); } return parent::_renderFiltersBefore(); }
/** * @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(); }
/** * @SuppressWarnings(PHPMD.CamelCaseMethodName) * * {@inheritdoc} */ protected function _renderFiltersBefore() { $searchRequest = $this->prepareRequest(); $this->queryResponse = $this->searchEngine->search($searchRequest); // Update the product count. $this->_totalRecords = $this->queryResponse->count(); // Filter search results. The pagination has to be resetted since it is managed by the engine itself. $docIds = array_map(function (\Magento\Framework\Api\Search\Document $doc) { return (int) $doc->getId(); }, $this->queryResponse->getIterator()->getArrayCopy()); if (empty($docIds)) { $docIds[] = 0; } $this->getSelect()->where('e.entity_id IN (?)', ['in' => $docIds]); $this->_pageSize = false; $this->isSpellchecked = $searchRequest->isSpellchecked(); return parent::_renderFiltersBefore(); }
/** * @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(); }
/** * @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(); }
/** * @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(); }