0

我像这样使用thinking-sphinx:

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>'

那么,如何从thinking-sphinx 中将字段加载到模型中呢?

我没有找到任何医生。

谢谢!

4

1 回答 1

0

在 TS 邮件列表中也有回答,但本质上,Sphinx 不会返回这些字段,因此您只需要参考构建这些字段的关联/列:

projects.each do |project|
  puts project.comments.message.join("\n")
end
于 2012-08-04T13:21:23.237 回答