2013-04-25 36 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