I want to override magento default search result, what I want to do is if products are not assign to any category then those products are not display on frontend in search result, by default magento include those products also which are not assign to any category.

I know magento prepare search result collection here prepareProductCollection($collection) in layer.php file but how we can exclude product without category?

2 Answers 2


I think the best solution here is to change the visibility of the products you don't want to show on search to 'Catalog' instead of 'Catalog,Search' (or 'Not visible individually'), instead of changing the way that the search results are fetched.
You can run a script to check the products that are not assigned to any category (attribute category_ids is null) and change the value of 'visibility'.

  • Yes i thought for this create one observer to check if category_id is null or not and set visibility according to that
    – Mufaddal
    May 15, 2013 at 11:38

If you change top level category option Is Anchor to No, magento will return products only assigned to subcategories.

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.