Magento 搜索引擎相关性问题

发布于 2024-12-03 02:11:23 字数 668 浏览 1 评论 0原文

我们目前有一个拥有大量库存的 Magento 网站,但我们在现场搜索结果的相关性方面遇到了一些问题。我们目前设置为“合并相似文本和全文”,但结果并非我们所期望的。例如,搜索“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 搜索结果的相关性,或者您能否在代码中为我指出正确的方向?

We currently have a Magento website with a large inventory, we are having some issues with relevance of ON SITE search results. We are currently set to 'combine like and fulltext' but the results are aren't what we expected. For example searching for 'Lee Child' (the author), brings up three Lee Child books, then three books with author as 'Lauren Child' and then the rest of the Lee Child books.

So essentially we want to give preference to the full text search and view those results BEFORE the like search results. We also want to display in stock products before out of stock products.

We have a test server and I read a forum post that said at the moment magento splits the search query and show products which have at least one of the words.

We modified line 342 (for CE1.4.2) of the Mage_CatalogSearch_Model_Mysql4_Fulltext:

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

and change “OR” with “AND”`

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

This is a fix for an earlier edition and we are currently running 1.5.0.1.

Is there something I'm missing to tinker with the Magento search results relevance or can you point me in the right direction in the code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

dawn曙光 2024-12-10 02:11:23

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

Mage_CatalogSearch_Model_Resource_Fulltext

方法

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

中要切换部分的

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

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

确保之后重新索引搜索索引才能生效。

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.

○闲身 2024-12-10 02:11:23

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

<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”中。 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

希望这是有意义的并且有帮助。

I believe the missing "keys" are the following two items:

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

You should be able to acomplish this a couple different ways... in either case you'll need to make local copies of the said files.

1) If you don't already have one, add a local copy of 'catalogsearch.xml'

Note:
Since Magento layouts work "cascading" it's a good idea to first check any "other" Magento layout directories available (other than the 'base'). For example, in my case we use EE, so we check the 'enterprise' layout directory first to copy files before looking in the 'base' directory.

Common locations of 'catalogsearch.xml':

/app/design/frontend/base/default/layout/catalogsearch.xml (as last resort)
/app/design/frontend/enterprise/default/layout/catalogsearch.xml (for EE)
Note: There may be a different location with PE as well... I'm not 100%.

2) Add the following within the 'catalogsearch_result_index' section in 'catalogsearch.xml':

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

For example:

Referencing the 'search_result_list' handle (ie enterprise layout):

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

So it would end up looking similar to:

<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>

Or you can place directly within the 'search_result_list' block (ie base layout):

<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) Make sure to dump the Magento cache/storage and reindex.

The other option would be to place them as 'hidden' form elements in 'form.mini.phtml'

1) Place the following within the form in 'form.mini.phtml':

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

Now, the beginning of the form in 'form.mini.phtml' would look similar to:

<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) Change the path to 'form.mini.phtml' template within the 'default' section ('header' reference handle) in 'catalogsearch.xml':

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

3) Make sure to dump the Magento cache/storage and reindex.

Final note...
Below is the "custom template" path structure we have it setup as. Located in the 'enterprise' directory, so my custom files would be located:
/app/design/frontend/enterprise/custom_template/layout/catalogsearch.xml
/app/design/frontend/enterprise/custom_template/template/catalogsearch/form.mini.phtml

Hope this makes sense and helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文