Rails アプリには次のモデルがあります。
class User < ActiveRecord::Base
has_many :tags
has_many :talents, :through => :tags
has_many :ratings
define_index do
indexes [:first_name, :last_name], :as => :name, :type => :string
has 'AVG(ratings.value)', :as => :ratings, :type => :integer
has tags(:talent_id), :as => :talent_id
set_property :delta => true
end
def self.ts_search(q, talent)
User.search q, :with => {:talent_id => talent.id}, :order => 'ratings DESC', :sort_mode => :extended
end
end
class Talent < ActiveRecord::Base
has_many :users, :through => :tags
end
class Rating < ActiveRecord::Base
belongs_to :user
belongs_to :talent
end
ここで、Thinking Sphinx 2.0.14 を使用して、特定の才能を持つすべてのユーザーを取得し、その特定の才能の評価の平均値で並べ替える必要があります。
関数を使用して、特定の才能def ts_search(q, talent)
を持つすべてのユーザーを取得し、すべての才能の評価の平均値で並べ替えます。
この関数を変更して、特定の才能の評価の平均値でユーザーを並べ替えるにはどうすればよいですか?
ありがとうございます!