Rails 3 と Tire gem で Elasticsearch を使用します。
私はいくつかの分野に取り組む面を持っていますが、今は特別な要件があり、それが可能かどうか確信が持てません。モデル プロジェクトに 2 つのフィールドがあり、どちらも同じ値を格納します: Country1 と Country2
ユーザーは、1 つのプロジェクトに対して最大 2 つの国を保存できます。両方のドロップダウン メニューは同じです。どちらのフィールドも必須ではありません。
私が望むのは、Country1 と Country2 の値を「マージ」し、それらのファセットのクリックをインテリジェントに処理する単一のファセットです (つまり、それが 1 か 2 かにかかわらず、それを見つけます)。
これまでの私のモデルは次のとおりです:(Country1/2は複数の単語になる可能性があることに注意してください)
class Project < ActiveRecord::Base
mapping do
indexes :id
indexes :title, :boost => 100
indexes :subtitle
indexes :country1, :type => 'string', :index => 'not_analyzed'
indexes :country2, :type => 'string', :index => 'not_analyzed'
end
def self.search(params)
tire.search(load: true, page: params[:page], per_page: 10) do
query do
boolean do
must { string params[:query], default_operator: "AND" } if params[:query].present?
must { term :country1, params[:country] } if params[:country].present?
end
end
sort { by :display_type, "desc" }
facet "country" do
terms :country1
end
end
end
どんなヒントでも大歓迎です!