【问题标题】:Magento Search Engine Relevance IssuesMagento 搜索引擎相关性问题
【发布时间】:2011-11-11 08:31:09
【问题描述】:

我们目前有一个拥有大量库存的 Magento 网站,但在 ON SITE 搜索结果的相关性方面存在一些问题。我们目前设置为“组合喜欢和全文”,但结果不是我们预期的。例如搜索“Lee Child”(作者),会找到三本 Lee Child 书籍,然后是三本作者为“Lauren Child”的书籍,然后是其余的 Lee Child 书籍。

因此,基本上我们希望优先考虑全文搜索,并在类似搜索结果之前查看这些结果。我们还希望在缺货产品之前显示库存产品。

我们有一个测试服务器,我阅读了一篇论坛帖子,该帖子说目前 magento 拆分搜索查询并显示至少包含一个单词的产品。

我们修改了 Mage_CatalogSearch_Model_Mysql4_Fulltext 的第 342 行(针对 CE1.4.2):

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

将“OR”改为“AND”`

路径:app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext.php

这是对早期版本的修复,我们目前正在运行 1.5.0.1。

我在修改 Magento 搜索结果的相关性方面是否缺少一些东西,或者您能在代码中指出我正确的方向吗?

【问题讨论】:

标签: magento search search-engine relevance


【解决方案1】:

要进行 AND 搜索而不是 OR,您需要重写类

Mage_CatalogSearch_Model_Resource_Fulltext

在方法中

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

你想切换部分

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

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

之后一定要重新索引搜索索引才能生效。

【讨论】:

    【解决方案2】:

    我认为缺少的“钥匙”是以下两项:

    <action method="setDefaultDirection"><string>desc</string></action>
    <action method="setDefaultOrder"><string>relevance</string></action>
    

    您应该能够以几种不同的方式完成此操作...在任何一种情况下,您都需要制作所述文件的本地副本。

    1) 如果您还没有,请添加“catalogsearch.xml”的本地副本

    注意: 由于 Magento 布局“级联”工作,因此最好先检查任何“其他”可用的 Magento 布局目录(“基础”除外)。例如,在我的例子中,我们使用 EE,因此我们首先检查“企业”布局目录以复制文件,然后再查看“基本”目录。

    “catalogsearch.xml”的常见位置:

    /app/design/frontend/base/default/layout/catalogsearch.xml(作为最后的手段) /app/design/frontend/enterprise/default/layout/catalogsearch.xml(用于 EE) 注意:PE 可能也有不同的位置...我不是 100%。

    2) 在“catalogsearch.xml”的“catalogsearch_result_index”部分添加以下内容:

    <action method="setDefaultDirection"><string>desc</string></action>
    <action method="setDefaultOrder"><string>relevance</string></action>
    

    例如:

    引用“search_result_list”句柄(即企业布局):

    <reference name="search_result_list">
        <action method="setDefaultDirection"><string>desc</string></action>
        <action method="setDefaultOrder"><string>relevance</string></action>
    </reference>
    

    所以它最终看起来类似于:

    <catalogsearch_result_index>
    ...other code
    
        <reference name="search_result_list">
            <action method="setDefaultDirection"><string>desc</string></action>
            <action method="setDefaultOrder"><string>relevance</string></action>
        </reference>
    
    ...other code
    
    </catalogsearch_result_index>
    

    或者您可以直接放置在“search_result_list”块中(即基本布局):

    <catalogsearch_result_index translate="label">
        <label>Quick Search Form</label>
        <reference name="root">
            <action method="setTemplate"><template>page/3columns.phtml</template></action>
        </reference>
        <reference name="left">
            <block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
        </reference>
        <reference name="content">
            <block type="catalogsearch/result" name="search.result" template="catalogsearch/result.phtml">
                <block type="catalog/product_list" name="search_result_list" template="catalog/product/list.phtml">
    
                   <action method="setDefaultDirection"><string>desc</string></action>
                   <action method="setDefaultOrder"><string>relevance</string></action>
    
                    <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                        <block type="page/html_pager" name="product_list_toolbar_pager"/>
                    </block>
                    <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
                    <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
                </block>
                <action method="setListOrders"/>
                <action method="setListModes"/>
                <action method="setListCollection"/>
            </block>
        </reference>
    </catalogsearch_result_index>
    

    3) 确保转储 Magento 缓存/存储并重新索引。

    另一种选择是将它们作为“隐藏”表单元素放置在“form.mini.phtml”中

    1) 将以下内容放在“form.mini.phtml”的表单中:

    <input type="hidden" name="order" value="relevance">
    <input type="hidden" name="dir" value="desc">
    

    现在,“form.mini.phtml”中表单的开头类似于:

    <form id="search_mini_form" action="<?php echo $this->helper('catalogsearch')->getResultUrl() ?>" method="get">
            <input type="hidden" name="order" value="relevance">
            <input type="hidden" name="dir" value="desc">
        ...other code
    

    2) 在“catalogsearch.xml”中的“default”部分(“header”引用句柄)中更改“form.mini.phtml”模板的路径:

    <default>
            <reference name="header">
                <block type="core/template" name="top.search" as="topSearch" template="custom_template/catalogsearch/form.mini.phtml"/>
            </reference>
    ... other code
    

    3) 确保转储 Magento 缓存/存储并重新索引。

    最后说明... 下面是我们设置的“自定义模板”路径结构。位于“企业”目录中,因此我的自定义文件将位于: /app/design/frontend/enterprise/custom_template/layout/catalogsearch.xml /app/design/frontend/enterprise/custom_template/template/catalogsearch/form.mini.phtml

    希望这有意义并有所帮助。

    【讨论】: