Magento Forum

   
Search Logic Fix - Improved user experience on CE 1.5
 
whiteswan
Jr. Member
 
Total Posts:  3
Joined:  2011-08-02
 

I’m writing this because it needs to be written down somewhere. It’s an issue that’s almost ungoogleable because the only terms I could think of were “Or” and “And”, both of which google omits.

Also I’m just really annoyed I had to fix it in the first place

As you may or may not know, Magento (or at least CE 1.5) selects search results by searching through the database and selecting all items that have the user-selected keywords in the ‘searchable’ fields. In short, it uses OR logic. This is absolutely the worst way to do a search.

Background

Let me explain why. Let’s say that I’m running a search on a store that sells a variety of sweets. Lets say I was trying to find something with chocolate and orange marmalade. The search query I’d use is “chocolate and orange marmalade”. Using OR logic like Magento is set up to use would show me a set of results that would include everything that includes or tastes like chocolate, everything with marmalade, everything that has or tastes like oranges, things that are described as orange-colored, and, worst of all, everything with the word “and” in the description. How much money has the site’s owner lost in lost sales because of this?

The solution is to switch from OR logic to AND logic. AND logic is what practically every mass-market focused search engine ever made uses by default. Using AND logic on the above example would only give me results that contained all three (technically four) keywords I typed in, giving me results that are actually relevant to what I was looking for, such as Lindt’s Intense Orange chocolate bar. The store owner will be happy because he just made that sale, and the customer will be happy because he found what he was looking for.

Solution

Luckally, the solution is easy to implement. Unfortunately, though, it requires you to edit the core source files, which is a big no if you ever plan to upgrade.

Simply change the two mentions of

' OR '
to
' AND '
in app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php and it will switch to AND logic.

Naturally, since you are editing the core source files, it will be deleted once you upgrade magento. If there’s anyway to use an override file or the likes, I would be appreciative.

P.S., in my 1.5, they were on lines 353 and 345

 
Magento Community Magento Community
Magento Community
Magento Community
 
pspahn
Jr. Member
 
Total Posts:  30
Joined:  2010-03-07
 

You should be able to simply copy that file to:

app/code/local/Mage/CatalogSearch/Model/Resource/Fulltext.php

and edit it how you like. This leaves the core file intact.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Borduhh
Member
 
Avatar
Total Posts:  39
Joined:  2010-09-14
Rochester, NY
 

Thank you so much WhiteSwan!

This is one thing that bugged me so much when I was building stores with Magento that I really could never find a fix for. Now, 30 secs and switching one file to local code and BOOM… works like a charm!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mirasvit
Guru
 
Avatar
Total Posts:  638
Joined:  2009-08-22
 

Check out these extension. They greatly improve the quality and relevance of search results Advanced Sphinx Search Pro http://mirasvit.com/magento-extensions/magento-sphinx-search.html

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top