【发布时间】:2011-05-03 19:14:02
【问题描述】:
我在 Rails 3.0 应用程序中使用 Thinking Sphinx,并尝试利用“excerpts”和“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 excerpts 和this regarding matching_fields,但是,matching_fields 方法总是返回 nil,我无法找到它的其他文档(即使在源代码中)。 match_fields 应该返回什么?
谢谢!
【问题讨论】:
标签: ruby-on-rails thinking-sphinx