From d83b459408384a28428718760fcb340058834e4e Mon Sep 17 00:00:00 2001 From: Untone Date: Sun, 2 Jun 2024 17:56:24 +0300 Subject: [PATCH] search-with-images120 --- resolvers/reader.py | 2 +- services/search.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/resolvers/reader.py b/resolvers/reader.py index d72326f3..7b6fc6b7 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -306,7 +306,7 @@ async def load_shouts_search(_, _info, text, limit=50, offset=0): shout_id = str(shout_id) scores[shout_id] = sr.get("score") hits_ids.append(shout_id) - [shouts] = local_session().execute(query_shouts()) + [shouts] = local_session().execute(query_shouts()).unique() for shout in shouts: shout.score = scores[f"{shout.id}"] shouts.sort(key=lambda x: x.score, reverse=True) diff --git a/services/search.py b/services/search.py index 7d457f0c..fcf4790f 100644 --- a/services/search.py +++ b/services/search.py @@ -174,7 +174,12 @@ class SearchService: } 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"] results = [{"id": hit["_id"], "score": hit["_score"]} for hit in hits] # results = [{**hit["_source"], "score": hit["_score"]} for hit in hits]