[英]Ordering by count with Thinking Sphinx
我希望我的搜索引擎能夠根據某種案件類型的案件來命令律師。 最多的律師已經確定某種類型的案件,他的排名越高。
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"
我走錯了路嗎? 我應該想一個更少的面向Sphinx的方法嗎? 問題是我需要在@lawyers上做一個each_with_geodist,所以我需要讓我的律師通過Sphinx搜索。
將以下內容添加到define_index:
has "COUNT(case_types.id)", :as => :case_type_count, :type => :integer
join case_types
然后通過case_count檢索:
Lawyer.search("", :order => "case_type_count desc")
我發現在development.sphinx.conf
讀取sql代碼很有用,它允許我查看生成的列名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.