Magento Quick Search

2019-07-17 21:20发布

问题:

I am having a small problem with the Magento quick search. When I search in the box say

ice machine

Then everything will be retuernd where it has ice or machine in the title. I need it so it would just search products with the exact string ice machine in the title.

I found out if I put "ice machine" with the double speech marks it will return only products names that match that exactly.

So I need a way so that the double speech marks get added around the search query automaticlly so it will search the full text not both words seperatly.

Is there a way to do this in the form HTML?

回答1:

This issue is covered over in the MagentoCommerce forums multiple times. The Like search logic was changed from AND to OR. For it to give better results, it needs to be changed back to AND so all items in the search query must match.

Search Logic Fix

In app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext.php find the class public function prepareResult($object, $queryText, $query)

The following piece of code:

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

needs to be

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

Create your own rewrite module to overwrite just this class or do an override by copying the whole file Fulltext.php over to app/code/local/Mage/CatalogSearch/Model/Mysql4/Fulltext.php and modifying OR to AND. The module is preferable.



回答2:

Using the form you can do that using javascript, but you would have to watch out if the customer enters double quotes himself already.
My suggestion would be to rewrite the Mage_CatalogSearch_Helper_Data helper and override the getQueryText() method. There you can quote existing quotes and add your own quotes around the query.