gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 07:17:55 24 4
gpt4 key购买 nike

我继承了一个通过轮胎进行 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com