如何从思维狮身人面像将额外的字段加载到模型中



我用这样的思维思考狮身人面像:

class Project < ActiveRecord::Base
  define_index do
    indexes title
    indexes comments.message, as: :comment_message
    indexes category_projects.description, as: :category_description
  end
  class << self
    def text_search(word)
      ThinkingSphinx.search(word, include: :comments)
    end
  end
end

当我做这个Project.text_search('test')时,它有效,但我想做这个:

@projects = Project.text_search('test')
@projects.each do |project|
  puts project.comment_message
end

目前我有这样的信息:

undefined method `comment_message' for #<ThinkingSphinx::Search:0x000000057e11c0>
    from /home/dougui/.rvm/gems/ruby-1.9.3-p194-perf@comment_my_projects/bundler/gems/thinking-sphinx-b293abdbdf0c/lib/thinking_sphinx/search.rb:185:in `method_missing'
    from (irb):1
    from /home/dougui/.rvm/gems/ruby-1.9.3-p194-perf@comment_my_projects/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
    from /home/dougui/.rvm/gems/ruby-1.9.3-p194-perf@comment_my_projects/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
    from /home/dougui/.rvm/gems/ruby-1.9.3-p194-perf@comment_my_projects/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

那么,如何将思维中的斯芬克斯的场加载到模型中呢?

我什么也没找到——医生。

谢谢!

在TS邮件列表上也有回答,但本质上,字段不是由Sphinx返回的,所以您只需要参考构建字段的关联/列:

projects.each do |project|
  puts project.comments.message.join("n")
end

最新更新