I've been battling with this issue for quite some time but have yet to find a good solution. I am trying to programmatically search products within a certain category. I do not want to build my own search functionality and want to use the standard Magento 'catalogsearch' module. My current code looks like

$catalogSearchModel = Mage::getModel('catalogsearch/query')->setQueryText(search query);
$catalogSearchModelCollection = $catalogSearchModel->getResultCollection();
$catalogSearchModelCollection->getSelect()->limit(limit1, limit2);
$data = $catalogSearchModelCollection->getData();

$filters = array();
foreach ($data as $key => $value) {
    $filters[] = array("attribute" => "entity_id", "eq" => $value["entity_id"]);


I use the product collection because I need more attributes for the products then there are available in the search model.

Is there a way to add a filter field to the catalog search collection, or something like that?

1 Answer 1


The result of

$catalogSearchModelCollection = $catalogSearchModel->getResultCollection();

is an instance of Mage_CatalogSearch_Model_Resource_Search_Collection that extends Mage_Catalog_Model_Resource_Product_Collection.
So I conclude is save to use addCategoryFilter.
Something like:

$category = Mage::getModel('catalog/category')->load(22);
$catalogSearchModelCollection = $catalogSearchModel->getResultCollection();
  • Oh my! It's so simple! Thank you so much! I was on the right track, but I was putting the cat_id in the addCategoryFilter function. Thank you! Feb 3, 2014 at 9:27
  • I have checked the Mage_CatalogSearch_Model_Resource_Search_Collection and Mage_Catalog_Model_Resource_Product_Collection, but unfortunately i did not able to find the "$catalogSearchModel->getResultCollection();" line can you able to me guide in where i need to do the mentioned changes
    – senthil
    Dec 7, 2017 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.