示例:
我有以下几点:
class Person < ActiveRecord::Base
has_many :educations
end
class Education < ActiveRecord::Base
belongs_to :school
belongs_to :degree
belongs_to :major
end
class School < ActiveRecord::Base
has_many :educations
# has a :name
end
我希望能够返回所有去过特定学校的人,所以在我的PeopleController#index中我有
@search = Person.search do
keywords params[:query]
end
@people = @search.results
如何在Person模型上创建可搜索方法,以深入到学校?我应该这样做吗:
searchable do
text :school_names do
educations.map { |e| e.school.name }
end
end
我最终必须对教育上的每个属性(学位等)做什么,或者我是否可以在教育上创建一个可搜索的方法,并以某种方式从Person.searchable中“调用”它?
谢谢
发布于 2013-08-29 09:01:08
最好将特定模型的所有索引字段的声明放在同一位置。
另外,您在索引:school_names方面做得很好,只需对要索引的其余关联字段执行相同的操作即可。
https://stackoverflow.com/questions/17604765
复制相似问题