highlights and weights
This commit is contained in:
@@ -24,17 +24,25 @@ def es_query(query:str):
|
||||
query ={
|
||||
"multi_match":{
|
||||
"query": query,
|
||||
"fields": ["title^20","title.ngrams^10","text","text.ngrams"],
|
||||
"type": "most_fields"
|
||||
"fields": ["title^20","title.ngrams^10","text^5","text.ngrams"],
|
||||
"tie_breaker": 0.3
|
||||
#"type": "most_fields"
|
||||
}
|
||||
}
|
||||
return query
|
||||
|
||||
|
||||
def es_highlight():
|
||||
highlight = {
|
||||
"fields": {
|
||||
"title": {},
|
||||
"text": {}
|
||||
"text": {"fragment_size" : 150},
|
||||
"title.ngrams": {},
|
||||
"text.ngrams": {"fragment_size" : 150},
|
||||
|
||||
}
|
||||
}
|
||||
return highlight
|
||||
|
||||
def es_search(query:str):
|
||||
with es_client() as client:
|
||||
@@ -57,4 +65,5 @@ if __name__ =="__main__":
|
||||
hit.get("_source",{}).get("title",""),
|
||||
" ".join(hit.get("highlight",{}).get("title",[""])),
|
||||
" ".join(hit.get("highlight",{}).get("text",[""]))
|
||||
))
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user