/** * Load terms and try to sort it by names * * @return $this */ protected function _loadTerms() { if (empty($this->_terms)) { $this->_terms = []; $terms = $this->_queryCollectionFactory->create()->setPopularQueryFilter($this->_storeManager->getStore()->getId())->setPageSize(100)->load()->getItems(); if (count($terms) == 0) { return $this; } $this->_maxPopularity = reset($terms)->getPopularity(); $this->_minPopularity = end($terms)->getPopularity(); $range = $this->_maxPopularity - $this->_minPopularity; $range = $range == 0 ? 1 : $range; foreach ($terms as $term) { if (!$term->getPopularity()) { continue; } $term->setRatio(($term->getPopularity() - $this->_minPopularity) / $range); $temp[$term->getName()] = $term; $termKeys[] = $term->getName(); } natcasesort($termKeys); foreach ($termKeys as $termKey) { $this->_terms[$termKey] = $temp[$termKey]; } } return $this; }
/** * Warm cache * @return void */ public function warm() { $collection = $this->queryCollectionFactory->create()->setOrder('popularity'); /** @var \Magento\Search\Model\Query $query */ foreach ($collection as $query) { $queryText = $query->getQueryText(); $this->processQuery($queryText); } $indexTable = $this->resource->getTableName('mst_misspell_index'); $select = $this->connection->select()->from($indexTable, ['keyword']); foreach ($this->connection->fetchCol($select) as $queryText) { $this->processQuery($queryText); } }
/** * {@inheritdoc} */ protected function _prepareCollection() { $this->_collection = $this->_queriesFactory->create(); if ($this->getRequest()->getParam('store')) { $storeIds = $this->getRequest()->getParam('store'); } elseif ($this->getRequest()->getParam('website')) { $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds(); } elseif ($this->getRequest()->getParam('group')) { $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); } else { $storeIds = ''; } $this->_collection->setPopularQueryFilter($storeIds); $this->setCollection($this->_collection); return parent::_prepareCollection(); }
/** * @return $this */ protected function _prepareCollection() { $this->_collection = $this->_queriesFactory->create(); $this->_collection->setRecentQueryFilter(); if ($this->getRequest()->getParam('store')) { $this->_collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store')); } elseif ($this->getRequest()->getParam('website')) { $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', ['in' => $storeIds]); } elseif ($this->getRequest()->getParam('group')) { $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); $this->_collection->addFieldToFilter('store_id', ['in' => $storeIds]); } $this->setCollection($this->_collection); return parent::_prepareCollection(); }
/** * Retrieve collection of suggest queries * * @return QueryCollection */ public function getSuggestCollection() { $collection = $this->getData('suggest_collection'); if ($collection === null) { $collection = $this->_queryCollectionFactory->create()->setStoreId($this->getStoreId())->setQueryFilter($this->getQueryText()); $this->setData('suggest_collection', $collection); } return $collection; }
/** * List of indexes * * @return array */ public function getIndexes() { $indexes = $this->dataHelper->getEnabledIndexes(); foreach ($indexes as $index) { $indexClass = '\\Mirasvit\\Search\\Model\\Index'; if ($index instanceof $indexClass) { $index->setData('search_collection', $index->getSearchCollection()); } else { /** @var \Magento\Framework\DataObject $index */ if ($index->getData('code') == 'catalogsearch_fulltext') { $index->setData('search_collection', $this->layerResolver->get()->getProductCollection()); } elseif ($index->getData('code') == 'magento_search_query') { $index->setData('search_collection', $this->queryCollectionFactory->create()->setQueryFilter($this->query->getQueryText())->addFieldToFilter('query_text', ['neq' => $this->query->getQueryText()])->addStoreFilter([$this->storeManager->getStore()->getId()])->setOrder('popularity')->distinct(true)); } } } return $indexes; }
/** * @return array */ public function getPopularSearches() { $result = $this->getDefaultPopularSearches(); if (!count($result)) { $ignored = $this->getIgnoredSearches(); $collection = $this->queryCollectionFactory->create()->setPopularQueryFilter()->setPageSize(20); /** @var \Magento\Search\Model\Query $query */ foreach ($collection as $query) { $text = $query->getName(); $isIgnored = false; foreach ($ignored as $word) { if (strpos(strtolower($text), $word) !== false) { $isIgnored = true; break; } } if (!$isIgnored) { $result[] = $text; } } } $result = array_map('ucfirst', $result); return $result; }