16 use Magento\Search\Model\ResourceModel\Query\CollectionFactory;
61 CollectionFactory $queryCollectionFactory,
65 $this->_queryCollectionFactory = $queryCollectionFactory;
66 $this->_urlFactory = $urlFactory;
67 parent::__construct($context,
$data);
78 if (empty($this->_terms)) {
80 $terms = $this->_queryCollectionFactory->create()->setPopularQueryFilter(
81 $this->_storeManager->getStore()->getId()
84 )->load()->getItems();
86 if (count($terms) == 0) {
90 $this->_maxPopularity = reset($terms)->getPopularity();
91 $this->_minPopularity = end($terms)->getPopularity();
93 $range = $range == 0 ? 1 : $range;
94 foreach ($terms as $term) {
95 if (!$term->getPopularity()) {
99 $temp[$term->getQueryText()] = $term;
100 $termKeys[] = $term->getQueryText();
102 natcasesort($termKeys);
104 foreach ($termKeys as $termKey) {
105 $this->_terms[$termKey] = $temp[$termKey];
125 public function getSearchUrl($obj)
128 $url = $this->_urlFactory->create();
133 $url->setQueryParam(
'q', $obj->getQueryText());
134 return $url->getUrl(
'catalogsearch/result');
__construct(Context $context, CollectionFactory $queryCollectionFactory, UrlFactory $urlFactory, array $data=[])