cancel
Showing results for 
Search instead for 
Did you mean: 

Reverse search funcionality

Reverse search funcionality

Hello friends,

 

I need to create a search form that looks for products that DOES NOT CONTAIN the search term.

 

The idea behind it is a element that says "Find products that you're not allergic to. I'm allergic to: 'search term' ". When the user types something and searches, the search results will show results that does not have that keyword.

 

Anyone have a clue on how to do it? Googled a bit but havent found anything.

 

Thanks in advice! Smiley Happy

3 REPLIES

Re: Reverse search funcionality

Hi @MatheusConrado,

 

You'll be using the regultar search and the a second one with the same features but only that want to exclude that key word, right?

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: Reverse search funcionality

Hi @MatheusConrado

 

Try the below solution. I had used the same kind of scenario in one of my project to disallow search term from the prepared search result. 

 

Go to location /app/code/core/Mage/CatalogSearch/Model/Resource/ and override prepareResult() method in Fulltext.php at line number 334.

In the method, there is the code that splits the query string into words and generates a where condition to prepare search result. You can rewrite the class and method below in your way. Notice this line:

 

        if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
            || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
        ) {
            $helper = Mage::getResourceHelper('core');
            $words = Mage::helper('core/string')->splitWords($queryText, true, $query->getMaxQueryWords());
            foreach ($words as $word) {
                $like[] = $helper->getCILike('s.data_index', $word, array('position' => 'any'));
            }
            if ($like) {
                $likeCond = '(' . join(' OR ', $like) . ')';
            }
        }

Hope this could help you to sort out your problem. Smiley Happy

-- Ravindra

Re: Reverse search funcionality

@Ravindra Pratap  Solutions works perfect in my case. You saved my googling time. @MatheusConrado thank you for posting this problem.