嗨,我使用Sunspot Solr构建了一个Ruby on Rails应用程序进行搜索。
@search = Answer.search do
with(:question_id, @question_ids)
paginate :page => 1, :per_page => Answer.count
end
return question_id
在这里,我想使用问题数组(例如:[1,2,3,4,5])搜索此答案模型。
怎么做?请帮助我。
答案 0 :(得分:0)
如果您的问题与答案有关联,则
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
我认为它会对你有所帮助。