2011-09-06 80 views
2

我们目前有一个Magento网站,有大量的库存,我们有一些与ON SITE搜索结果相关的问题。我们现在正在设置'结合喜欢和全文',但结果不是我们所期望的。例如,搜索'Lee Child'(作者),带来了三本Lee Child书籍,然后是三本书籍,分别是作者'劳伦儿童',然后是李儿童书籍的其余部分。Magento搜索引擎相关问题

所以基本上我们希望优先考虑全文搜索并查看搜索结果之前的结果。我们还希望在缺货产品之前显示库存产品。

我们有一个测试服务器,我读了一篇论坛帖子,称此刻magento分割搜索查询并显示至少有一个单词的产品。

我们修改了Mage_CatalogSearch_Model_Mysql4_Fulltext线342(用于CE1.4.2):

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

和更改“或”与“和”`

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

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

是否有东西我失踪修补Magento搜索结果的相关性,或者你可以指出我在代码中的正确方向吗?

+1

我看到了这个问题:http://stackoverflow.com/questions/1953715/magento-search-not-returning-expected-results但我不确定这是真的,Magento显示最不相关的第一?! – WOBenji

回答

0

要制作和搜索,而不是OR,您将需要重写类

Mage_CatalogSearch_Model_Resource_Fulltext 

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

要切换部分

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

方法到

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

请务必重新索引搜索索引后才能生效。

0

我相信失踪的“钥匙”有以下两个项目:在任何情况下

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

你应该能够acomplish这几种不同的方法......你需要做的本地副本所述文件。

1)如果你不已经有一个,加上“catalogsearch.xml”的本地副本

注: 由于Magento的布局作品“级联”这是一个好主意,先检查任何“其他”Magento布局目录(除了“基础”)。例如,在我的例子中,我们使用EE,所以我们在查看'base'目录之前先检查'enterprise'布局目录以复制文件。

/应用程序/设计/前端/基/默认/布局/ catalogsearch: 'catalogsearch.xml' 的

常见位置。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的缓存/存储和REINDEX。

另一个选项将是将它们作为“隐藏”在“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)“默认”内将路径更改为“form.mini.phtml”模板部分('头'参考手le)在'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)确保转储Magento缓存/存储和重新索引。

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

希望这是有道理的,并帮助。