From 465d9093bdd26bcf0895065f9cca193967ed6f99 Mon Sep 17 00:00:00 2001 From: Untone Date: Sun, 2 Jun 2024 15:56:17 +0300 Subject: [PATCH] search-with-images --- resolvers/reader.py | 11 ++++++++--- services/search.py | 7 +------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/resolvers/reader.py b/resolvers/reader.py index ff128b3e..d2c3bc26 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -297,14 +297,19 @@ async def load_shouts_feed(_, info, options): async def load_shouts_search(_, _info, text, limit=50, offset=0): if isinstance(text, str) and len(text) > 2: results = await search_text(text, limit, offset) - shouts_ids = [] + scores = {} + hits_ids = [] for sr in results: shout_id = sr.get("id") if shout_id: - shouts_ids.append(int(shout_id)) + shout_id = int(shout_id) + scores[shout_id] = sr.get("score") + hits_ids.append(shout_id) shouts = [] with local_session() as session: - shouts = session.query(Shout).filter(Shout.id.in_(shouts_ids)).all() + shouts = session.query(Shout).filter(Shout.id.in_(hits_ids)).all() + for shout in shouts: + shout["score"] = scores[int(shout.id)] return shouts return [] diff --git a/services/search.py b/services/search.py index 6e0511cc..a4c8f6cc 100644 --- a/services/search.py +++ b/services/search.py @@ -166,12 +166,7 @@ class SearchService: async def search(self, text, limit, offset): logger.debug(f"Ищем: {text}") search_body = { - "query": { - "multi_match": { - "query": text, - "fields": ["title", "lead", "subtitle", "body", "media"] - } - } + "query": {"multi_match": {"query": text, "fields": ["title", "lead", "subtitle", "body", "media"]}} } if self.client: