/** * Append the user fulltext query to the tracked variables list * * @return array */ public function getVariables() { $variables = ['search.query' => $this->catalogSearchData->getEscapedQueryText()]; if ($layer = $this->catalogLayer) { $productCollection = $layer->getProductCollection(); $variables['search.is_spellchecked'] = (int) $productCollection->isSpellchecked(); } return $variables; }
/** * Append the fuzziness alert message + save the search result count. * * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @param \Magento\CatalogSearch\Block\Result $resultBlock Result block. * @param \Closure $proceed Original method. * * @return string[] */ public function aroundGetNoteMessages(Result $resultBlock, \Closure $proceed) { $messages = $proceed(); $query = $this->queryFactory->get(); $query->setNumResults($this->resultCount); $query->setIsSpellchecked(false); if ($this->isSpellcheck() && $this->resultCount > 0) { $messages[] = __("No search results for: <b>'%1'</b>. We propose you approaching results.", $this->catalogSearchData->getEscapedQueryText()); $query->setIsSpellchecked(true); } $this->queryResource->saveSearchResults($query); return $messages; }
/** * {@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); }
/** * Get search query text * * @return \Magento\Framework\Phrase */ public function getSearchQueryText() { return __("Search results for: '%1'", $this->catalogSearchData->getEscapedQueryText()); }
/** * Append message to the customer session to inform he has been redirected * * @param \Magento\Catalog\Api\Data\ProductInterface $product The product being redirected to. */ private function addRedirectMessage(ProductInterface $product) { $message = __("%1 is the only product matching your '%2' research.", $product->getName(), $this->helper->getEscapedQueryText()); $this->messageManager->addSuccessMessage($message); }