如何在太阳黑子多模型搜索中识别模型?

时间:2014-06-07 11:30:02

标签: ruby-on-rails ruby solr sunspot

我想搜索商店,图表和最后一个模型 对于时间和坐标,我把id放在会话中 我想将id用于其他目的。
有什么方法可以识别id的源模型吗?

@searchs = Sunspot.search store, chart, last do |s|
      s.fulltext params[:search]
      s.with(:end_at).greater_than(Time.now) 
    end.results
    ar=[]
    @searchs.each do |a|
      if a.coordinate_x.nil? || a.coordinate_y.nil?
        next
      end
      ar << a.id 
    end
    session[:stores_id] = ar

1 个答案:

答案 0 :(得分:0)

您必须存储更多信息才能识别源模型。在迭代结果时,您可以获取并存储类的名称。根据这些信息,您可以确定要检查类型的源模型。

@searchs = Sunspot.search store, chart, last do |s|
  s.fulltext params[:search]
  s.with(:end_at).greater_than(Time.now) 
end.results
ar=[]
@searchs.each do |a|
  if a.coordinate_x.nil? || a.coordinate_y.nil?
    next
  end
  # Store the type of the item and its id.
  ar << {type: a.class.name, id: a.id}
end
session[:stores_id] = ar