2011-09-06 83 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

希望這是有道理的,並幫助。