0

モデル内の特定のフィールドにストップワードのカスタム セットを追加したいと考えています。そのため、そのフィールドにカスタム アナライザーを追加しました。それでも、ストップワードで検索すると、結果が表示されます。私のモデル内のコードは次のとおりです。

settings :analysis => {
 :filter  => {
  :stop_filter => {
    :type        => "stop",
    :stopwords   => ["how", "when", "where", "who", "which", "what", "do", "the", "a", "is", "to"]
  }
 },
 :analyzer => {
  :my_analyzer => {
    :type         => "standard",
    :filter       => "stop_filter",
    :tokenizer    => "standard"
  }
 }
} do
 mapping do
  indexes :id,              :type => 'integer',     :index    => :not_analyzed
  indexes :sortable_id,     :type => 'integer',     :index    => :not_analyzed
  indexes :summary,         :type => 'string',      :analyzer => 'my_analyzer'
 end
end

def self.search_all(search_string = nil, options = {})
  tire.search(:load => true, :page => options[:page] || 1, :per_page => options[:per_page] || 10) do
    query {search_string.present? ? string(search_string) : all}
    filter :term, {:topics_list_filter =>  options[:topic_id]} if options[:topic_id]
    sort {by options[:sort], options[:order] || 'desc'} if options[:sort].present?
  end
end

stopwordsを作成せずに、アナライザーのオプションとして指定することも試しましたstop_filter。どこが間違っているのかわかりません。

4

2 に答える 2

2

クエリは、_allデフォルトのアナライザーを使用してインデックス付けされたフィールドを検索しています。クエリの既定のフィールドを置き換えるかsummary、既定のアナライザーを置き換えることができます。タイヤを使用した弾性検索のデフォルト アナライザーを設定するにはどうすればよいですか? を参照してください。詳細については。

于 2012-11-16T12:55:33.477 に答える
0

ドキュメントを再インデックスしましたか? ドキュメントが作成されたとき、場合によってはインデックスが作成されたときにのみ、マッピング基準がElasticSearchに送信されると思います。

于 2012-11-16T12:09:23.833 に答える