[英]Using sunspot_solr search array of values
嗨,我用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
在这里,我想使用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
我认为它将为您提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.