ruby on rails -使用sunspot_solr搜索值数组



嗨,我用太阳黑子Solr构建了一个Ruby on Rails应用程序用于搜索。

@search = Answer.search do
  with(:question_id, @question_ids) 
  paginate :page => 1, :per_page => Answer.count
end
return question_id

这里我想用数组的question_ids(例如:[1,2,3,4,5])来搜索这个答案模型。

怎么做?

如果你的问题和答案有关联

class Question < ActiveRecord::Base
   has_many :answers
end
class Answer < ActiveRecord::Base
  belongs_to :question
end

然后你可以添加可搜索到你的问题模型,像这样

class Question < ActiveRecord::Base
  searchable do
    text :title, :body
    text :answers do
      answers.map { |answer| answer.body }
    end
    integer :questions_ids, :multiple => true
  end
    // your another methods
end

在你的索引操作

@search = Answer.search do
  with(:questions_ids, @question_ids) 
  paginate :page => 1, :per_page => Answer.count
end
return question_id

我想这会对你有帮助。

相关内容

  • 没有找到相关文章

最新更新