【问题标题】:Thinking Sphinx: matching_fields method returning nil思考狮身人面像:matching_fields 方法返回 nil
【发布时间】: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 excerptsthis regarding matching_fields,但是,matching_fields 方法总是返回 nil,我无法找到它的其他文档(即使在源代码中)。 match_fields 应该返回什么?

谢谢!

【问题讨论】:

    标签: ruby-on-rails thinking-sphinx


    【解决方案1】:

    Matching_fields 返回带有字段名称的字符串数组。应该在每个特定的搜索结果上调用它。要让它工作,您需要将 :rank_mode 设置为 :fieldmask,而不是 :match_mode。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多