我已在rails中实现弹性搜索,以便在产品数据库中进行全文搜索,但它不会返回我期望的结果。
例如,当我搜索" samsung galaxy s5"手机,我大多是案件,而不是手机。我测试了其他的网上商店,当我搜索相同的单词时,我得到的主要是移动电话的结果。
是否有任何改善搜索结果的建议,以便在搜索产品时表现得像往常一样?
这是我目前的搜索查询:
def self.search(query)
__elasticsearch__.search(
{
size: 1000,
query: {
filtered: {
query: {
multi_match: {
query: query,
fields: ['manufacturer^2', 'en_product^10', 'ma_product^10', 'cs_product^10', 'ma_description', 'cs_description', 'en_description', 'ma_specification', 'cs_specification', 'en_specification']
}
},
filter: {
term: {
active: true
}
}
}
},
}
)
end
并映射:
settings index: {
number_of_shards: 1,
analysis: {
filter: {
trigrams_filter: {
type: 'ngram',
min_gram: 2,
max_gram: 10
},
content_filter: {
type: 'ngram',
min_gram: 4,
max_gram: 20
}
},
analyzer: {
index_trigrams_analyzer: {
type: 'custom',
tokenizer: 'standard',
filter: ['lowercase', 'trigrams_filter', 'asciifolding']
},
search_trigrams_analyzer: {
type: 'custom',
tokenizer: 'whitespace',
filter: ['lowercase']
},
english: {
tokenizer: 'standard',
filter: ['standard', 'lowercase', 'content_filter']
},
czech: {
tokenizer: 'standard',
filter: ['asciifolding','standard','lowercase','content_filter' ]
}
}
}
} do
mappings dynamic: 'false' do
indexes :active, type: 'boolean'
indexes :manufacturer, index_analyzer: 'index_trigrams_analyzer', search_analyzer: 'search_trigrams_analyzer'
indexes :en_product, index_analyzer: 'english', search_analyzer: 'english'
indexes :ma_product, index_analyzer: 'czech', search_analyzer: 'czech'
indexes :cs_product, index_analyzer: 'czech', search_analyzer: 'czech'
indexes :en_description, index_analyzer: 'english', search_analyzer: 'english'
indexes :ma_description, index_analyzer: 'czech', search_analyzer: 'czech'
indexes :cs_description, index_analyzer: 'czech', search_analyzer: 'czech'
indexes :en_specification, index_analyzer: 'english', search_analyzer: 'english'
indexes :ma_specification, index_analyzer: 'czech', search_analyzer: 'czech'
indexes :cs_specification, index_analyzer: 'czech', search_analyzer: 'czech'
end
end
谢谢你, 米罗