Pull Magento's Most Common Search Queries

Submitted by deeperdata - 2 years ago

I used the following script to provide a "feed" for a customer who would later make use of this data to populate a "popular search" block. You could go one step further and combine it with some frontend library to populate an "auto-suggest" search. NOTE: The redirect field might not show for everyone. The popularity field will show the number of times the term has been searched for.

// Run this from your Magento root (in a file e.g. topsearches.php)

        // Path to Mage.php;

        $searchCollection = Mage::getModel('catalogsearch/query')->getCollection()
         ->setOrder('popularity', 'DESC');
        // Choose how many results to show
        foreach ($searchCollection as $item)
            echo "Redirect: " . $item->getData('redirect') . "<br />";
            echo "Query: " . $item->getData('query_text') . "<br />";
            echo "Popularity: " . $item->getData('popularity') . "<br /><br />";
Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean