Google+

Pages

Tuesday, June 4, 2013

Catalog Search not returning expected results in Magento

Many customers complain about Magento's default catalog search results. Here is the solution to get better results from Magento Catalog Search.

1. Copy app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php to app/code/local/Mage/CatalogSearch/Model/Resource/ folder and open file.

2. Navigate to function prepareResult() and find below set of code:

$words = Mage::helper('core/string')->splitWords($queryText, true, $query->getMaxQueryWords());
foreach ($words as $word) {
$like[] = $helper->getCILike('s.data_index', $word, array('position' => 'any'));
}

and replace it with:

$like[] = '`s`.`data_index` LIKE :likew';
$bind[':likew'] = '%' . $queryText . '%';

Next replace

$likeCond = '(' . join(' OR ', $like) . ')';

with

$likeCond = '(' . join(' AND ', $like) . ')';

3. Login to Admin Panel of your magento. Navigate to System --> Configuration.

4. Now click on  Catalog --> Catalog tab on left. In Catalog Search panel, set Search Type to like.

5. Just reindex all data and your store's search should be working fine now.
 
This process was tested on magento version 1.7.0 and  above.

6 comments:

Anonymous said...

Friend Can u tell me how to include a Jquery file in magento?
I am giving U a reference site:
http://www.biosculpture.com.au

I want footer section images just like the site.
I have download a js file just like this ,I have js,css and images file.
Can u please tell me how should i integrate it in magento

MOHIT KUMAR ARORA said...

Thanks for query..

To include js file i your theme's layout, follow these simple steps:

1. Place your js files in
skin/frontend/[your package]/[your theme]/js folder.

for example:
your package is default
and
your theme is modern

then place your js files in
skin/frontend/default/modern/js folder.


2. Open your layout xml file.
For reference:

app/design/frontend/[your package]/[your theme]/layout/page.xml

Now you will find code block like:


<block type="page/html_head" name="head" as="head">
---
---
</block>

within default tag.

Here you can use below syntax to add your js file:

<action method="addItem"><type>skin_js</type><name>js/[your_file_name].js</name></action>

Change [your_file_name] with your file name accordingly.


Hope this will help. :)

Anonymous said...

Hi Mohit..
For the above code
I have Jquery Code like


jQuery('#dock2').Fisheye(
{
maxWidth: 40,
items: 'a',
itemsText: 'span',
container: '.dock-container2',
itemWidth: 40,
proximity: 40,
alignment : 'left',
valign: 'bottom',
halign : 'center'
//align: 'middle',
//size: 110,
//distance: 90
}
)


where should I put this code???

Anonymous said...

Hi'
I have include the js file,css file as per you said...

Can you help regarding the above problem i.e for Jquery code?

I have to paste this
jQuery('#dock2').Fisheye(
{
maxWidth: 40,
items: 'a',
itemsText: 'span',
container: '.dock-container2',
itemWidth: 40,
proximity: 40,
alignment : 'left',
valign: 'bottom',
halign : 'center'
//align: 'middle',
//size: 110,
//distance: 90
}

in some page so that it will be available to all the pages.there must be a phtml file so that I can put it ...
Waiting for your reply..

Easy Ajax Cart said...

Thanks for the steps and the replacement code. I'm new to Magento and its helps me a lot.

Anonymous said...

Nice Post,helps to increase accuracy in the search.