关于suggests的疑问
来源:15-2 es完成搜索建议-搜索建议字段保存 - 2
慕尼黑530398
2017-12-06
老师好,在代码了设置了一个used_word = set().但是这个set在后面中一直是空的。是不是在最后应该加一句
used_word = used_word.union(new_word) 呢?
写回答
1回答
-
def gen_suggests(index, info_tuple): used_words = set() suggests = [] for key, weight in info_tuple: if key: result = es.indices.analyze(index=index, analyzer='ik_max_word', params={'filter': ['lowercase']}, body=key) words = set([r['token'] for r in result['tokens'] if len(r['token']) > 1]) new_words = words - used_words used_words.update(words) else: new_words = set() if new_words: suggests.append({'input': list(new_words), 'weight': weight}) return suggests
亲 你可以看看这个逻辑
012017-12-07
相似问题