1
我想要做什麼:輪胎沒有發現局部字(2場搜索)
- 我有2場模型「項目」我想elasticsearch對搜索:標題和描述。
- 我希望搜索找到部分字詞,例如:bicycl應該對陣自行車,自行車等...
現狀:
- 搜索只顯示完美匹配
這是我現在所擁有的在我的項目模型:
include Tire::Model::Search
include Tire::Model::Callbacks
class << self
def search_index
Tire.index(Item.index_name)
end
end
settings :analysis => {
:filter => {
:my_ngram => {
"type" => "nGram",
"max_gram" => 10,
"min_gram" => 3 }
},
:analyzer => {
:my_analyzer => {
"type" => "custom",
"tokenizer" => "standard",
"filter" => ["my_ngram"]
}
}
} do
mapping do
indexes :title, boost: 10, analyzer: 'my_analyzer'
indexes :description, boost: 5, analyzer: 'my_analyzer'
end
end
def self.search(query_string)
tire.search(load: true) do
if query_string.present?
query do
string query_string, default_operator: "AND"
end
end
end
end