Reputation: 2185
I want to display the top 10 searches on my Magento store. Magento already stores searches made on the store under Admin > Catalog > Search Terms, so it's just a matter of getting it into my view. Does anyone know which helper or function I can access to get this list?
Upvotes: 4
Views: 5394
Reputation: 248
If anyone needs the Magento 2 solution:
inject the class \Magento\Search\Model\Query
in your constructor and then retrieve the collection like so:
$collection = $this->query->getSuggestCollection()
This will return a collection of most popular search terms sorted by the popularity.
Upvotes: 0
Reputation: 4528
You have a setPopularQueryFilter method in the class Mage_CatalogSearch_Model_Mysql4_Query_Collection, after that you only have to set a limit I guess :)
Without trying, it should be something like that :
$searchCollectino=Mage::getModel('catalogsearch/query')->getCollection()
->setPopularQueryFilter()
->setPageSize($limit);
Upvotes: 8