如何解决在弹性搜索中实现伪相关反馈
我的弹性搜索索引只创建了一个字段 -“title”,如代码段所示。我想使用伪相关反馈,结合 BM25 排名功能来优化我的搜索结果。如果我不必明确指定查询聚合的重要术语,我该如何处理,即我希望自动聚合相关术语。
settings = {
'settings': {
'index': {
'number_of_shards': 1,'number_of_replicas': 1,'similarity': {
'default': {
'type': 'BM25',"b": 0.3,"k1": 0
}
}
}
},'mappings': {
# this key is the "type",which will be explained in the next code chunk
'properties': {
'title': {
'type': 'text',}
}
}
}
query = {
'query': {
'match': {
# search against the 'title' field
'title': line
}
}
}
def search(q_idx,query,headers):
url = 'http://localhost:9200/bm25/_doc/_search?size=22' ### for top20
response = requests.get(url,data=json.dumps(query),headers=headers)
idx_list = []
try:
search_hits = json.loads(response.text)['hits']['hits']
for idx,hit in enumerate(search_hits):
idx_list.append(hit['_source']['id'])
return q_idx,idx_list
except:
return [],[]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。