我想将一组自定义停用词添加到模型中的一个特定字段。所以我为该字段添加了一个自定义分析器。但是,当我使用停用词进行搜索时,仍然会显示结果。我的模型里面的代码如下:
settings :analysis => {
:filter => {
:stop_filter => {
:type => "stop",
:stopwords => ["how", "when", "where", "who", "which", "what", "do", "the", "a", "is", "to"]
}
},
:analyzer => {
:my_analyzer => {
:type => "standard",
:filter => "stop_filter",
:tokenizer => "standard"
}
}
} do
mapping do
indexes :id, :type => 'integer', :index => :not_analyzed
indexes :sortable_id, :type => 'integer', :index => :not_analyzed
indexes :summary, :type => 'string', :analyzer => 'my_analyzer'
end
end
def self.search_all(search_string = nil, options = {})
tire.search(:load => true, :page => options[:page] || 1, :per_page => options[:per_page] || 10) do
query {search_string.present? ? string(search_string) : all}
filter :term, {:topics_list_filter => options[:topic_id]} if options[:topic_id]
sort {by options[:sort], options[:order] || 'desc'} if options[:sort].present?
end
end
我还尝试通过stopwords
在分析器中提供选项,而不创建stop_filter
. 我不确定我哪里出错了。