0

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)を持つすべてのユーザーを取得し、すべての才能の評価の平均値で並べ替えます。

この関数を変更して、特定の才能の評価の平均値でユーザーを並べ替えるにはどうすればよいですか?

ありがとうございます!

4

2 に答える 2

0

次の方法で「OR」および「And」クエリを作成できます。 Or 条件 query_arr = ["test", "test-xyz"] で検索したいとします。

次のような検索クエリ: User.search query_arr.join("( | )") したがって、"( test )|( test-xyz )" のようなクエリを実行すると、test または test-xyz に一致するすべてのユーザーのテキストが検索されます。

| を置き換えるだけで「And」クエリを作成できます。に &。

于 2016-07-26T14:48:52.240 に答える