2011-05-03 57 views
1

我在Rails 3.0應用程序中使用思維獅身人面像,並試圖在呈現搜索結果時利用「摘錄」和「matching_fields」方法。說我有以下型號:思維獅身人面像:matching_fields方法返回零

class Journal < ActiveRecord::Base 
    has_many :entries 

    define_index do 
    indexes description # This is an attribute of the Journal class 
    indexes entries.note, :as => :entry_note 
    # ...additional indexes 

    set_property :delta => true 
    end 
end 

在搜索控制器我有以下幾點:

class SearchResultsController < ApplicationController 
    def index 
    @search_results = Journal.search params[:q], :star => true, :match_mode => :fieldmask 
    respond_with(@search_results) 
    end 
end 

在我看來,我想構建包括僅領域的摘錄的搜索結果與搜索項匹配的。例如,如果搜索字詞與:description字段匹配,我希望顯示突出顯示的搜索字詞的描述摘錄。但是,如果搜索與期刊的條目註釋(:entry_note字段)相匹配,我希望搜索結果顯示該註釋的摘錄並突出顯示搜索詞。

我讀過this regarding excerptsthis regarding matching_fields,但是,matching_fields方法總是返回nil,我一直無法找到它的其他文檔(甚至在源代碼中)。匹配字段應該返回什麼?

謝謝!

回答

0

Matching_fields返回字段數組與字段名稱。應該針對每個特定的搜索結果調用它。爲了使它起作用,你需要設置:rank_mode爲:fieldmask,而不是:match_mode。

相關問題