我正在继承一个通过轮胎进行弹性搜索的项目 .
搜索正在进行中,但通过它进行了重点调整 . 搜索“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 回答
这篇文章中有一个非常好的例子"asciifolding"(在索引文本时删除标记的重音符号):Autocomplete with Tire