ruby - 使用 Elasticsearch 和轮胎忽略口音

标签 ruby elasticsearch tire

我继承了一个通过轮胎进行 Elasticsearch 的项目。

搜索正在运行,但重音通过它关闭。例如,搜索“this”需要返回“thís”和“thiš”。

我已阅读此轮胎文档:http://karmi.github.com/tire/

以及:http://railscasts.com/episodes/306-elasticsearch-part-1?view=asciicast

其中提到了 elasticsearch 的大部分选项都可以在 tire 中使用。

关于忽略重音的搜索,asciifolding 不断出现,但 Elasticsearch 只是这样说:

http://www.elasticsearch.org/guide/reference/index-modules/analysis/asciifolding-tokenfilter.html

此外,我还发现了一些关于过滤器/重音等的信息,例如:

https://github.com/elasticsearch/elasticsearch/issues/890
https://gist.github.com/2142635

但他们都在使用裸 Elasticsearch 选项。

当我尝试在我的 ruby​​ 代码中使用 asciifolding 过滤器时,我收到关于没有为“asciifolding”定义的过滤器的错误。

这是在我的代码中完成的搜索的核心——我如何修改它以进行不区分重音的搜索。它是 asciifolding 吗?如果是,我该如何在这里声明它?

result = tire.search(:load => true,page: params[:page], per_page: params[:per_page] ) do
  query { string "#{params[:term]}", :default_operator => 'and' }  if params[:term].present?
  filter  :missing,   :field => 'original_media_id' #see above
  #asciifolding?
  sort { by :updated_at, :desc } if params[:term].present?
  facet 'files' do
    terms  'indexed_files.file.id'  
  end
end

编辑:或者它应该在映射/索引中完成?然后重新运行索引器。这是映射,我尝试将 :filter => "asciifolding"放入一些索引,但这似乎不起作用(也没有产生任何错误输出):

tire.mapping do
    indexes :id, :index => :not_analyzed
    indexes :name, :filter => "asciifolding"
    indexes :description, :filter => "asciifolding"
    indexes :created_at, :type => 'date'
    indexes :updated_at, :type => 'date'
    indexes :file_type
    indexes :indexed_files, :type => 'object' do
        indexes :file, :type => 'object', 
            :properties => { 
            :title => {
            :type => "multi_field",
              :fields => {
                :raw => { :type => 'string', :index => 'not_analyzed'},
                :title => { :type => 'string', :filter => "asciifolding" }
              }
            },
            :description => { :type => "string", :filter => "asciifolding" }
           }
    end
end

最佳答案

本文中有一个非常好的“asciifolding”示例(在索引文本时从标记中删除重音符号):Autocomplete with Tire

关于ruby - 使用 Elasticsearch 和轮胎忽略口音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10825242/

相关文章:

Ruby 找不到 nokogiri/nokogiri

elasticsearch - ElasticSearch集群复制

elasticsearch - 无法将Filebeat连接到Logstash以使用ELK进行日志记录

ruby-on-rails - 轮胎搜索不能忽略口音

ruby-on-rails - 如何手动删除轮胎索引

elasticsearch - 在 ElasticSearch 中忽略撇号(所有格)

ruby-on-rails - Twilio Rails 项目的推荐结构?

c# - 类似于 C# 的 ERB 库

ruby-on-rails - 如何在 Ruby 中保存 Google API 凭据?

java - 无法为类型 'x.y.z.package' 构建查询,该类型既未配置,也没有任何配置的子类型