search-with-images120
All checks were successful
Deploy on push / deploy (push) Successful in 1m34s

This commit is contained in:
Untone 2024-06-02 17:56:24 +03:00
parent db8472ae06
commit d83b459408
2 changed files with 7 additions and 2 deletions

View File

@ -306,7 +306,7 @@ async def load_shouts_search(_, _info, text, limit=50, offset=0):
shout_id = str(shout_id) shout_id = str(shout_id)
scores[shout_id] = sr.get("score") scores[shout_id] = sr.get("score")
hits_ids.append(shout_id) hits_ids.append(shout_id)
[shouts] = local_session().execute(query_shouts()) [shouts] = local_session().execute(query_shouts()).unique()
for shout in shouts: for shout in shouts:
shout.score = scores[f"{shout.id}"] shout.score = scores[f"{shout.id}"]
shouts.sort(key=lambda x: x.score, reverse=True) shouts.sort(key=lambda x: x.score, reverse=True)

View File

@ -174,7 +174,12 @@ class SearchService:
} }
if self.client: if self.client:
search_response = self.client.search(index=self.index_name, body=search_body, size=limit, from_=offset) search_response = self.client.search(
index=self.index_name,
body=search_body,
size=limit,
from_=offset,
_source_includes=["_id", "_score"])
hits = search_response["hits"]["hits"] hits = search_response["hits"]["hits"]
results = [{"id": hit["_id"], "score": hit["_score"]} for hit in hits] results = [{"id": hit["_id"], "score": hit["_score"]} for hit in hits]
# results = [{**hit["_source"], "score": hit["_score"]} for hit in hits] # results = [{**hit["_source"], "score": hit["_score"]} for hit in hits]