views:

762

answers:

2

I'm writing a custom plugin thing which needs to search the product catalog. Based on some sample code I saw somewhere (possibly this site), I came up with this working prototype:

$searcher = Mage::getSingleton('catalogsearch/advanced')
   -> addFilters(array('name' => $_REQUEST['name']))
   -> addFilters(array('sku' => $_REQUEST['sku']))
;
$products = $searcher->getProductCollection();

This works great for those two fields, but I also need to search by product id. It seems like the proper field to search on is 'entity_id', but its not working:

$searcher->addFilters(array('entity_id' => $_REQUEST['id']));

I've also tried using 'product_id' and simply 'id' with no luck. Keep getting this error:

Mage_Core_Exception: You have to specify at least one search term

Any thoughts on how to accomplish this? Maybe I should be using a different class to do my searching?

A: 

Thanks Jimmy for your help! Turns out I was overthinking things. I've implemented an if statement to simply load by id (if provided), otherwise do the search.

Colin O'Dell
A: 

Hello, I was hanging around and saw your post : I'm pretty interested in a new search module to override the default method. This because to me, the relevance calculation method (even when i regenerate the search cache) is not so relevant ... When typing pasta in the search bar, i can't get products which names contain 'pasta' first, but some products that have their description containning the word 'pasta' which is not relevant in some cases.

So I'd like to find something that sort results regarding the product's name :)

Could someone help me ? I don't really know about modules, so any help would be so appreciated.

Thank you !

Stev