我希望我的搜索引擎能够根据某种案件类型的案件数量来订购律师。律师完成某一类型案件的次数越多,他的排名就越高。
lawyer.rb
has_many :cases
has_many :case_types, :through => :cases
define_index do
indexes case_types.name, :as => :case_types
has case_types(:id), :as => :case_types_id
has "SUM(case_types)", :as => :case_type_count #this line gives an error, as my lawyer table does't have a case_type column, also, I need to count DISTINCT case_types
end
在我的search_controller.rb
,我想做类似的事情,建议是案例类型的名称
@lawyers = Lawyer.search params[:suggestion], :order => "@case_type_count DESC"
我走错路了吗?我应该考虑一种较少面向狮身人面像的方法吗?问题是我需要在@lawyers 上做一个 each_with_geodist,所以我需要让我的律师通过 Sphinx 搜索。