Magento搜索的“相关性"值始终为0 [英] Magento Search 'relevance' Value is Always 0

查看:105
本文介绍了Magento搜索的“相关性"值始终为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到我似乎无法在默认搜索中根据相关性进行排序.无论我尝试使用ASC还是DESC,结果始终是相同的,而相关性却很差.

I noticed that I seemingly wasn't able to sort on relevance in a default search. Whether I tried ASC or DESC, the results were always the same and rather poorly relevant at that.

进一步调查后,我在 Mage_CatalogSearch_Model_Resource_Fulltext_Collection 中找到了addSearchFilter()方法:

Upon further investigating, I found the addSearchFilter() method in Mage_CatalogSearch_Model_Resource_Fulltext_Collection :

/**
 * Add search query filter
 *
 * @param string $query
 * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
 */
public function addSearchFilter($query)
{
    Mage::getSingleton('catalogsearch/fulltext')->prepareResult();

    $this->getSelect()->joinInner(
        array('search_result' => $this->getTable('catalogsearch/result')),
        $this->getConnection()->quoteInto(
            'search_result.product_id=e.entity_id AND search_result.query_id=?',
            $this->_getQuery()->getId()
        ),
        array('relevance' => 'relevance')
    );

    Zend_Debug::dump($this->getData());exit;

    return $this;
}

我的数据转储结果显示结果很好,但是相关性"列始终为0.00000.我没有对目录搜索进行任何更改,这是Magento 1.6.0.

The result of my data dump shows the results just fine, but the 'relevance' column is always 0.00000. I have not made any changes to the catalog search and this is Magento 1.6.0.

我也转储了实际的SQL:

I dumped the actual SQL as well:

SELECT `e`.*, `search_result`.`relevance` FROM `catalog_product_entity` AS `e` INNER JOIN `catalogsearch_result` AS `search_result` ON search_result.product_id=e.entity_id AND search_result.query_id='33'

如果其他人在计算相关性方面有更多经验,我将非常感谢指导.

If anyone else has more experience with calculating relevance I would greatly appreciate direction.

推荐答案

简短答案:相关性仅在全文搜索模式下使用.

Short answer: the relevance is only used in full text search mode.

在管理界面中,您可以为Magento配置搜索类型".
可以在系统>配置>目录>目录搜索>搜索类型

In the admin interface you can configure a "Search Type" for Magento.
This setting can be found under System > Config > Catalog > Catalog Search > Search Type

如果切换到全文本(并在重新索引之后),并清除catalogsearch_query表,Magento将使用MySQL全文本搜索功能,在查询中指定WHERE条件,如下所示:

If switched to Fulltext (and after reindexing), and clearing the catalogsearch_query table, Magento will use the MySQL Fulltext Search capability, specifying a WHERE condition in the query as follows:

...MATCH (s.data_index) AGAINST (:query IN BOOLEAN MODE) AS `relevance`...

这将返回一个浮点数,该浮点数将用作相关值.普通匹配将使您的相关性为1.如果索引包含搜索词的次数超过一次,则其相关性就会更高.

This will return a floating point number that will be used as the relevance value. A plain hit will give you a relevance of 1. If the index contains the search term more then once, it will be given a higher relevance.

布尔全文搜索还可以使用搜索修饰符,例如"+ this -notThis".
有关MySQL布尔全文搜索的相关权重的更多信息,请参见 http://dev.mysql.com/doc/refman/5.1/de/fulltext-boolean.html

Also the boolean fulltext search enables the use of search modifiers like "+this -notThis".
More information on the relevance weighting of the MySQL boolean fulltext search can be found here http://dev.mysql.com/doc/refman/5.1/de/fulltext-boolean.html

如果使用搜索模式赞",则相关性始终为0(如您所注意到的那样).

If the search mode "Like" is used, the relevance always is 0 (as you noticed).

Magento建立搜索索引的方式不是很直观,我建议看一下表catalogsearch_fulltext.然后通过调整在快速搜索中使用的属性来调整要在搜索中使用的属性.可以在目录>属性>管理属性下找到此设置.然后为目录搜索索引重新编制索引.
我还建议您在调整属性后清除catalogsearch_result表.

The way Magento builds the search index isn't very intuitive, I recommend a look at the table catalogsearch_fulltext. Then tune the attributes you want to use in the search by adjusting the Used in Quick Search property for them. This setting can be found under Catalog > Attributes > Manage Attributes. Then reindex the catalog search index.
I also recommend clearing out the catalogsearch_result table after you adjust the attributes.

这篇关于Magento搜索的“相关性"值始终为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆