2011-05-03 59 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。

相关问题