magento search order by relevance

Mario Delgado picture Mario Delgado · Feb 9, 2012 · Viewed 9.6k times · Source

I have the following code:

$collection = Mage::getSingleton('catalogsearch/layer')->getProductCollection();

I've tried

$collection = Mage::getSingleton('catalogsearch/layer')->getProductCollection()->addAttributeToSort('relevance', 'desc')

But it does not work.

Any ideas?

Answer

Vinai picture Vinai · Feb 9, 2012

Check out this related answer: Magento Search 'relevance' Value is Always 0

It gives some insight into the relevance value of search results.