2

我们目前有一个拥有大量库存的 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 搜索结果的相关性,或者你能在代码中指出我正确的方向吗?

4

2 回答 2

0

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

Mage_CatalogSearch_Model_Resource_Fulltext

在方法中

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

你想切换部分

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

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

请务必在之后重新索引搜索索引以产生效果。

于 2013-01-22T18:02:03.583 回答
0

我相信缺少的“钥匙”是以下两项:

<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

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

于 2013-01-22T18:07:50.730 回答