繁体   English   中英

Elasticsearch + Tire不能忽略口音

[英]Elasticsearch + Tire not ignore accents

我正在尽一切努力解决这个问题。

我有一个简单的应用程序搜索栏。 当我搜索带有重音符号的单词时,搜索工作正常,但是如果我搜索不带重音符号的单词,则结果为空。

我阅读了Tire和Elasticsearch的文档,但不知道发生了什么

class Article < ActiveRecord::Base
  attr_accessible :description, :title, :user_id

  belongs_to :user

  include Tire::Model::Search
  include Tire::Model::Callbacks

  mapping do
    indexes :_id, index: :not_analyzed
    indexes :title, analyzer: 'snowball', boost: 100
    indexes :description, analyzer: 'snowball'
  end

  def self.search(params)
    tire.search(page: params[:page], per_page: 10) do
      query { string params[:q], default_operator: "AND" } if params[:q].present?
    end
  end
end

在贝娄,我尝试使用asciifolding,但是没有用。

  class Article < ActiveRecord::Base
  attr_accessible :description, :title, :user_id

  include Tire::Model::Search
  include Tire::Model::Callbacks

  tire.settings :index => {
      :analysis => {
          :analyzer => {
              :index_analyzer => {
                  :tokenizer => "whitespace",
                  :filter => ["asciifolding", "lowercase", "snowball"]
              },
              :search_analyzer => {
                  :tokenizer => "whitespace",
                  :filter => ["asciifolding", "lowercase", "snowball"]
              }
          },
          :filter => {
              :snowball => {
                  :type => "snowball",
                  :language => "Portuguese"
              }
          }
      }
  }

  mapping do
    indexes :_id, index: :not_analyzed
    indexes :title, analyzer: 'snowball', boost: 100
    indexes :description, analyzer: 'snowball'
  end

  def self.search(params)
    tire.search(page: params[:page], per_page: 10) do
      query { string params[:q], default_operator: "AND" } if params[:q].present?
    end
  end
end

我在Chrome上使用Sense进行测试,映射和所有配置都可以!

发生了什么???

谢谢

您必须使用在索引中指定的分析器。 您当前正在使用“雪球”分析器来进行标题和描述,而不会进行Asciifolding:

mapping do
  indexes :_id, index: :not_analyzed
  indexes :title, analyzer: 'snowball', boost: 100
  indexes :description, analyzer: 'snowball'
end

改为这样做

mapping do
  indexes :_id, index: :not_analyzed
  indexes :title, analyzer: :index_analyzer, boost: 100
  indexes :description, analyzer: :index_analyzer
end

假设您要使用query_analyzer。 然后,当您要搜索时,请使用其他分析器:

tire.search(page: params[:page], per_page: 10) do
  query { string params[:q], 
          analyzer: :search_analyzer, 
          default_operator: "AND" } if params[:q].present?
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM