How and where to modify Magento search query?

自闭症网瘾萝莉.ら 提交于 2019-12-01 02:48:45

In Mage_CatalogSearch_Model_Resource_Fulltext check out prepareResult (line 310 in 1.7 CE) and look for the following:

$select->columns(array('relevance'  => new Zend_Db_Expr(0)));

Magento sets all search result relevances as 0 (!); add the relevances you want (higher is better) here. You can create a custom query in Zend_Db_Expr() to generate higher relevances on attribute matches.

The answer to your first question (1): To make an AND search instead of OR, you will need to rewrite the class

Mage_CatalogSearch_Model_Resource_Fulltext

In the method

public function prepareResult($object, $queryText, $query)

you want to switch the part

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

to

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

Be sure to reindex the search index afterwards to have an effect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!