Fix: Magento Catalog Search Broken / Not Working

Written by Sid Vel

Topics: Magento

We recently updated a Magento install from 1.3.2.4 to 1.5.1.0. Everything worked fine, expect the search function. Whatever we searched for, the site returned just one result. This seems to be a problem with upgrades and even some fresh installs of Magneto 1.4.1.1, 1.4.2, 1.5.1.0, etc. The following is the fix. This will require fixing the core files. Hopefully the Magento team will address the issue in the next update.

Edit app/code/core/Mage/CatalogSearch/Block/Result.php

Uncomment lines 149 and 150

$this->getListBlock()
->setCollection($this->_getProductCollection());

Modify the line 172

// Change this line
$this->_productCollection = $this->getListBlock()->getLoadedProductCollection();

to the old code from Version 1.4.1.1

// Change the previous line to this one
$this->_productCollection = Mage::getSingleton('catalogsearch/layer')->getProductCollection();

Once the code is fixed, go to the Admin panel (System > Index Management) and select all the Indexes > Pick action is “Reindex data” > Press “Submit”.

The search should work now.

Source

34 Comments Comments For This Post I'd Love to Hear Yours!

  1. mark says:

    thank you very much, i had a new install 1.5.1.0 magento and this worked PERFECTLY!!!

    Easy fix and very much needed..

  2. Matthew says:

    Thank you, did the trick. In our case 1.5.1 was not even “searching/filtering” the catalog of products for the search term and just returned everything visible.

  3. Jo says:

    Thanks so much – it worked like a dream!

    It totally fixed the issue I was having whereby a search was not filtering any products, instead it was delivering everything. My search is now back to normal and working perfectly!

  4. Matt W says:

    Thanks a ton! This really saved me…

    • Matt W says:

      Had this working, but then 1 1/2 days to 2 days later, the search stopped working again. I am again getting no results returned, and I didn’t change a thing after making the edits you suggested. Has anyone else had this problem? Can you please help shed some light on this?

      Running Magento 1.5.1 on Apache server. All DB tables pertaining to catalogsearch are still in order, and tables are filled with data.

      • Sid Vel says:

        Did you try reindexing? System > Index Management. Magento should refresh indexes on a regular basis. It can fail some time. Reindexing will always make it work, but it can fail again. Can you give a link to your website?

  5. Sunil says:

    Thanks a ton… i just can tell you how much help this is for me. I was trying to solve this for 2 days..

    Thanks a lot again

  6. Rico says:

    Thank you very much for this fix. Saved my day :)

  7. DM says:

    Worked! On my 1.5.0.1 install, I was getting ALL products returned with any search term. This worked to narrow down the results.

  8. ARandomDeveloper says:

    THIS FIX WORKS (Tried and tested on Magento Version 1.6.1.0)!!

    I have searched for hours trying to find a simple fix without editing code, but many websites led me back to this single fix.

    THIS WORKS

    PLEASE DON’T BE AFRAID TO TRY IT! IT’S NOT HARD AT ALL!

    THANK YOU SO MUCH!

  9. magefast says:

    Thank you.

    Works.

  10. taulant says:

    thank you so much! I spent two hours trying to figure this out until I ran into your blog post. This fixed my problem. Version 1.5.1.0

  11. Dr. Gasket says:

    Hello,
    I am using 1.6 and search box does not find all products or none.
    i did all changes of uncomment and etc. re-index and compile…but still no results.
    for example i have 50 products under the brand Hobart. when you search Hobart you get only 1 results.
    all my products are set to be found in catalog and search

    what might be the problem ?

    Thank you

    public function setListCollection()
    {
    $this->getListBlock()
    ->setCollection($this->_getProductCollection());
    return $this;
    }

    /**
    * Retrieve Search result list HTML output
    *
    * @return string
    */
    public function getProductListHtml()
    {
    return $this->getChildHtml(‘search_result_list’);
    }

    /**
    * Retrieve loaded category collection
    *
    * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
    */
    protected function _getProductCollection()
    {
    if (is_null($this->_productCollection)) {
    $this->_productCollection = Mage::getSingleton(‘catalogsearch/layer’)->getProductCollection();
    }

  12. Paul Doherty says:

    Worked like a charm on 1.6!!! Thanks.

  13. Thank you very very much. I have a theme updated to 1.6.2 and it crashed this way. Yours tips works perfectly and save me a lot of time.

  14. But doesnt work after upgrade from 1.6.2 to 1.7.0 (stable). =/

  15. sorry, my mistake. also works for 1.7.0. :P

  16. Ivn says:

    Hi there,

    I am using Magento CE 1.6.1 . I had line 149 n 150 already commented in my file. But i changed line 172 with the line you had mentioned.

    I also refreshed the indices but it still shows me the same results for any search term.

    It shows me a certain set of products for any search term which is constant.

    Any Ideas why this is happening? Can you please help me out?

  17. Konstantin says:

    Got same problem with 1.4 -> 1.6.2
    My respect to author for this solution, it works. After some additional investigation I found how to fix this without Magento core files modification.
    at app/design/frontend/[path_to_your_theme]/layout/catalogsearch.xml
    put

    at -> section.
    this adds filter by attributes configured as “Use In Search Results Layered Navigation” and fixes this issue as side effect.

  18. Konstantin says:

    <block type=”catalogsearch/layer” name=”catalogsearch.leftnav” after=”currency” template=”catalog/layer/view.phtml”/>
    at section
    catalogsearch_result_index > reference name=”left”

  19. SC says:

    So same issue with 1.6.2.0. Regardless of what term is searched, same set of results show up. In fact if i put some random term like ‘timbaktu” same result. Will the above solution fix that?

  20. Nick says:

    I want to express my thanks for this information. I have spent countless hours trying to figure out the search problem. The fix works perfectly.

    I still have one other annoying search problem. Can anyone help with this?

    We sell posters of a band called “the wanted” . If you search for “the wanted” it brings up 1500 unrelated products. I guess it is showing anything with the word “the”.

    If you just search “wanted” it only shows the relevant results.

    This problem is common with may product searches. Does anyone know what I can do? Is there a way to force search just to look at titles?

    Thanks.

  21. Prabhu says:

    excellent work.

  22. Ankur says:

    Very nice fix

  23. johan says:

    Thanks! Works perfectly for Enterprise 1.11.2.0

  24. Felix Buenemann says:

    The proper fix for this is to make sure the catalogsearch/layer block is included in your catalogsearch.xml layout file.

    If you do not want layered search navigation to show up, disable it for all attributes from the backend. To also remove categories, change the catalogsearch/layer block like this in your catalogsearch.xml:


    category_filter

  25. Nayan says:

    Thank you so much…!!!!
    Its works perfectly in Magento 1.5.0.1. …………

  26. Kunjesh Sukhadia says:

    Hello Sid Vel,

    Thank you your help. You really save my lots of hours.

    Thank you,
    Kunjesh Sukhadia.

  27. Worked great for some front end search issues on 1.7. Thanks Sid!

  28. Nanyak says:

    Thanks a lot… I am running Magento 1.7.0.2 and this fix works very well.

    Thanks again!

34 Comments Trackbacks For This Post

  1. Magento 1.5 quick search returns all the products or unexpected result – a discussion and collected solutions | LAMP stuffs you look for
  2. Magento 1.5 quick search returns all the products or unexpected result – a discussion and collected solutions | Experience Explored
  3. Magento 1.5 quick search returns all the products or unexpected result – a discussion and collected solutions | Experience Explored
  4. Magento search returning 0 results, despite products enabled and proper visibility | BlogoSfera
  5. Magento search returning 0 results, despite products enabled and proper visibility