2

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

どんなヒントでも大歓迎です!

4

3 に答える 3

6

このコミットhttps://github.com/karmi/tire/commit/730813f in Tire は、「用語」ファセットで複数のフィールドを集約するためのサポートをもたらします。

インターフェイスは次のとおりです。

Tire.search('articles-test') do
  query { string 'foo' }
  # Pass fields as an array, not string
  facet('multi') { terms ['bar', 'baz'] }
end
于 2012-07-25T10:51:23.327 に答える
0

用語ファセットhttp://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.htmlのelasticsearchドキュメントによると、これは可能であるはずです。

マルチフィールド:

ファセットという用語は、複数のフィールドに対して実行でき、それらのフィールド全体の集計結果を返します。例えば:

{
    "query" : {
        "match_all" : {  }
    },
    "facets" : {
        "tag" : {
            "terms" : {
                "fields" : ["tag1", "tag2"],
                "size" : 10
            }
        }
    }
}

ファセットという用語にフィールドの配列を提供しようとしましたterms :country1, :country2か?

于 2012-06-06T23:50:37.460 に答える
0

これはうまくいくようですが、もっとテストする必要があります: facet('country') { terms fields: [:country1, :country2]}

于 2012-07-14T13:47:14.160 に答える