2013-04-25 58 views
1

如何获得热门搜索主页上的术语?未获得热门搜索Magento使用代码

我有参考以下问题: Getting Popular Searches In Magento

所以,我已经使用相同的代码,给出如下:

$searchCollectino=Mage::getModel('catalogsearch/query')->getCollection() 
->setPopularQueryFilter() 
->setPageSize($limit); 

他们告诉使用 - > getItems(),我们可以得到搜索词。

但我没有得到什么确切的代码可以.. ??

如何使用此代码?

回答

3

我得到前5个热门搜索词通过下面的代码:

$searchCollection = Mage::getModel('catalogsearch/query')->getCollection() 
->setOrder('popularity', 'DESC'); 
$searchCollection->getSelect()->limit(8); 
foreach ($searchCollection as $item) 
{ 
    echo $item->getData('redirect'); 
    echo $item->getData('query_text'); 
} 
+1

这对我不起作用,但这是''searchCollectino = Mage :: getModel('catalogsearch/query') - > getCollection() - > setPopularQueryFilter() - > setPageSize($ limit);'从此获得[链接](http://stackoverflow.com/a/5435234/1577396)。 – 2013-10-29 07:03:12

1
`$searchCollection = Mage::getModel('catalogsearch/query')->getCollection() 
->setOrder('popularity', 'DESC'); 
$searchCollection->getSelect()->limit(5); 
$searchCollection->getItems();` 

这将取得与限制

希望的热门搜索你喜欢它:)

+0

与方法我可以打印搜索条件? 表示foreach($ searchCollection-> getItems()作为$ terms){echo $ terms - > ***在这里写什么***(); } – LuFFy 2013-04-29 13:17:42

+0

您的答案也可以在其他网站上找到,我已经提到过。 – LuFFy 2013-04-29 15:04:00