我有一个属性,叫做偏差“文件”(activerecords)。 该属性有像“斌X”“宾$”“宾Q”“宾%”等价值观
我试图用轮胎/ elasticsearch要搜索的属性。 我使用的空白分析仪指数的偏差属性。 这里是我创建索引的代码:
settings :analysis => {
:filter => {
:ngram_filter => {
:type => "nGram",
:min_gram => 2,
:max_gram => 255
},
:deviation_filter => {
:type => "word_delimiter",
:type_table => ['$ => ALPHA']
}
},
:analyzer => {
:ngram_analyzer => {
:type => "custom",
:tokenizer => "standard",
:filter => ["lowercase", "ngram_filter"]
},
:deviation_analyzer => {
:type => "custom",
:tokenizer => "whitespace",
:filter => ["lowercase"]
}
}
} do
mapping do
indexes :id, :type => 'integer'
[:equipment, :step, :recipe, :details, :description].each do |attribute|
indexes attribute, :type => 'string', :analyzer => 'ngram_analyzer'
end
indexes :deviation, :analyzer => 'whitespace'
end
end
搜索似乎在查询字符串中包含特殊字符做工精细。 例如Bin X
将只返回有话这些记录Bin
和X
在其中。 然而,寻找类似Bin $
或Bin %
显示有字的所有结果Bin
几乎忽略了符号(用符号结果也显示在导致没有寻求更高)。
下面是我创建的搜索方法
def self.search(params)
tire.search(load: true) do
query { string "#{params[:term].downcase}:#{params[:query]}", default_operator: "AND" }
size 1000
end
end
这里是怎么了建立搜索方式:
<div>
<%= form_tag issues_path, :class=> "formtastic issue", method: :get do %>
<fieldset class="inputs">
<ol>
<li class="string input medium search query optional stringish inline">
<% opts = ["Description", "Detail","Deviation","Equipment","Recipe", "Step"] %>
<%= select_tag :term, options_for_select(opts, params[:term]) %>
<%= text_field_tag :query, params[:query] %>
<%= submit_tag "Search", name: nil, class: "btn" %>
</li>
</ol>
</fieldset>
<% end %>
</div>