我已经设置了弹性搜索和轮胎进行搜索。
我的模型有以下设置:
tire.settings :analysis => {
:analyzer => {
:spanish_snowball => {
:type => "snowball",
:language => "Spanish",
:filter => %w{asciifolding lowercase}
}
}
}
以及以下映射:
tire.mapping do
indexes :id, :index => :not_analyzed
indexes :name, :analyzer => 'spanish_snowball', :boost => 3
indexes :urbanization, :analyzer => 'spanish_snowball'
indexes :categories do
indexes :name, :analyzer => 'spanish_snowball'
end
indexes :tags do
indexes :name, :analyzer => 'spanish_snowball'
end
end
我还定义了to_indexed_json
方法
def to_indexed_json
to_json include: { categories: { only: [:name]}, tags: { only: [:name]} }
end
我想在我的搜索中忽略重音符号,所以我asciifolding
在我的spanish_snowball
分析器中使用。然而,口音并没有被忽视。
Business.tire.search("japonés").size
=> 10
Business.tire.search("japones").size
=> 0
我用 curl 测试了分析仪,分析仪似乎工作正常
➜ ~ curl -XGET 'localhost:9200/businesses/_analyze?pretty=1&text=Japonés%20nobu&analyzer=spanish_snowball'
{
"tokens" : [ {
"token" : "japones",
"start_offset" : 0,
"end_offset" : 7,
"type" : "<ALPHANUM>",
"position" : 1
}, {
"token" : "nobu",
"start_offset" : 8,
"end_offset" : 12,
"type" : "<ALPHANUM>",
"position" : 2
} ]
}%