From c1fe419ff965dfd173efbed539a0fffb371abcee Mon Sep 17 00:00:00 2001 From: Untone Date: Sun, 2 Jun 2024 18:34:15 +0300 Subject: [PATCH] search-with-images22 --- resolvers/reader.py | 12 +++++++----- services/search.py | 3 +-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/resolvers/reader.py b/resolvers/reader.py index b6aa7391..ae7b70d3 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -307,11 +307,13 @@ async def load_shouts_search(_, _info, text, limit=50, offset=0): scores[shout_id] = sr.get("score") hits_ids.append(shout_id) result = local_session().execute(query_shouts()).unique() - shouts = [] - for shout in result: - shout.score = scores[f"{shout.id}"] - shouts.append(shout) - shouts.sort(key=lambda x: x.score, reverse=True) + if result: + logger.debug(result) + shouts = [] + for shout in result: + shout.score = scores[f"{shout.id}"] + shouts.append(shout) + shouts.sort(key=lambda x: x.score, reverse=True) return shouts return [] diff --git a/services/search.py b/services/search.py index fcf4790f..22856fa9 100644 --- a/services/search.py +++ b/services/search.py @@ -179,10 +179,9 @@ class SearchService: body=search_body, size=limit, from_=offset, - _source_includes=["_id", "_score"]) + _source_excludes=["title", "body", "subtitle", "media", "lead"]) 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] # если результаты не пустые if results: