使用弹性搜索和轮胎忽略重音

时间:2012-05-30 22:35:25

标签: ruby elasticsearch tire

我正在继承一个通过轮胎进行弹性搜索的项目。

搜索工作正在进行,但通过它进行了重点调整。搜索“this”需要返回“thís”和“thiš”等。

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

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

其中提到大多数弹性搜索选项都适用于轮胎。

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

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

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

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

但他们都使用裸弹性搜索选项。

当我尝试在我的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

1 个答案:

答案 0 :(得分:3)

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

相关问题