1

how can i set the search keyword (input by customer) default display to "NO" in magento backend so i can moderate the suggested search keyword below the searchbar?

3 Answers 3

2

The quick and dirty way is to change the column display_in_terms of the catalogsearch_query table to default to 0 instead of 1.

The long and clean way is to rewrite the method Mage_CatalogSearch_ResultController::indexAction() and replace this:

if (!Mage::helper('catalogsearch')->isMinQueryLength()) {
    $query->save();
}

with this:

if (!Mage::helper('catalogsearch')->isMinQueryLength()) {
    if (!$query->getId()) { //if is a new search word
         $query->setDisplayInTerms(0); //don't display it in search terms.
    }
    $query->save();
}
2
  • Where can I find this code?
    – paddotk
    Commented Sep 28, 2015 at 15:09
  • in app/code/core/Mage/CatalogSearch/controllers/ResultController.php
    – Marius
    Commented Sep 28, 2015 at 15:23
1

I'am allowing myself to give a slight modification for the answer above as for magento 1.7.0.2 the code was not working.

Indeed the condition is not working because an Id is automatically attributed before in the code on line 14.

if (Mage::helper('catalogsearch')->isMinQueryLength()) {
            $query->setId(0)
                ->setIsActive(1)
                ->setIsProcessed(1);
} 

Therefore the interpreter never enter into the condition.

For myself I did the following. I added a bit of code at the beginning of the method

At line 12 I added the following

if ($query->getQueryText() != '') {

            /* Added code */
            $newsearchterm = false; //creation of a boolean
            if (!$query->getId()) { 
                $newsearchterm=true; // if the there is no id we set to true
            }
            /* End Added code by */

            if (Mage::helper('catalogsearch')->isMinQueryLength()) {
                $query->setId(0)
                    ->setIsActive(1)
                    ->setIsProcessed(1);
            }

And then at below I added

if (!Mage::helper('catalogsearch')->isMinQueryLength()) {
                // Added code 
                if ($newsearchterm) { //if is a new search word (boolean true)
                    $query->setDisplayInTerms(0); //don't display it in search terms.
                }
                // End of added code 
                $query->save();
            }

Finnally I would like to add that you cannot override a controller, but you will have to rewrite it. So it means the creation of a little module for making it work.

Thanks and don't hesitate to suggest any code improvements.

Have a great day,

-1

app/code/core/Mage/CatalogSearch/Model/Resource edit file : Fulltext.php

just change this line $likeCond = ‘(‘ . join(‘ OR ‘, $like) . ‘)’; $likeCond = ‘(‘ . join(‘ AND ‘, $like) . ‘)’;

2
  • Welcome to Magento SE. It looks like you answered the wrong question. This is a solution for a completely different problem. Please check again Commented Jul 27, 2017 at 14:46
  • It's forbidden to update the Magento core !
    – PЯINCƎ
    Commented Jul 27, 2017 at 15:51

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.