我想尽一切办法来解决这个问题。
我有一个简单的应用程序与搜索rails。当我搜索带有重音的东西时,搜索工作得很好,但是如果我搜索没有重音的单词,我的结果是空的。
我读了Tire和Elasticsearch的文档,但我不知道发生了什么
class Article < ActiveRecord::Base
attr_accessible :description, :title, :user_id
belongs_to :user
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :_id, index: :not_analyzed
indexes :title, analyzer: 'snowball', boost: 100
indexes :description, analyzer: 'snowball'
end
def self.search(params)
tire.search(page: params[:page], per_page: 10) do
query { string params[:q], default_operator: "AND" } if params[:q].present?
end
end
end下面我试着使用asciifolding,但它不起作用。
class Article < ActiveRecord::Base
attr_accessible :description, :title, :user_id
include Tire::Model::Search
include Tire::Model::Callbacks
tire.settings :index => {
:analysis => {
:analyzer => {
:index_analyzer => {
:tokenizer => "whitespace",
:filter => ["asciifolding", "lowercase", "snowball"]
},
:search_analyzer => {
:tokenizer => "whitespace",
:filter => ["asciifolding", "lowercase", "snowball"]
}
},
:filter => {
:snowball => {
:type => "snowball",
:language => "Portuguese"
}
}
}
}
mapping do
indexes :_id, index: :not_analyzed
indexes :title, analyzer: 'snowball', boost: 100
indexes :description, analyzer: 'snowball'
end
def self.search(params)
tire.search(page: params[:page], per_page: 10) do
query { string params[:q], default_operator: "AND" } if params[:q].present?
end
end
end我正在使用Chrome上的Sense进行测试,映射和所有配置都是正常的!
怎么回事?
谢谢
发布于 2014-02-07 06:17:56
您必须使用在索引中指定的分析器。您当前正在为您的标题和描述使用"snowball“分析器,但不执行asciifolding:
mapping do
indexes :_id, index: :not_analyzed
indexes :title, analyzer: 'snowball', boost: 100
indexes :description, analyzer: 'snowball'
end改为这样做
mapping do
indexes :_id, index: :not_analyzed
indexes :title, analyzer: :index_analyzer, boost: 100
indexes :description, analyzer: :index_analyzer
end假设你想要query_analyzer。然后,当您想要搜索时,使用其他分析器:
tire.search(page: params[:page], per_page: 10) do
query { string params[:q],
analyzer: :search_analyzer,
default_operator: "AND" } if params[:q].present?
endhttps://stackoverflow.com/questions/18582069
复制相似问题