From c061e5cdb39d5646b9c7263f41c1a3d335fe9f8e Mon Sep 17 00:00:00 2001 From: Untone Date: Sun, 28 Jan 2024 23:27:40 +0300 Subject: [PATCH] search-simpler-query-fix-2 --- resolvers/reader.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/resolvers/reader.py b/resolvers/reader.py index 8e45dfef..7f4932d6 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -345,7 +345,7 @@ async def load_shouts_search(_, _info, text, limit=50, offset=0): shouts_data = [] with local_session() as session: - results = list(session.execute(q).unique()) + results = set(session.execute(q).all()) # print(results) logger.debug(f'search found {len(results)} results') for x in results: @@ -382,7 +382,11 @@ async def load_shouts_search(_, _info, text, limit=50, offset=0): score = results_dict.get(shout_slug, {}).get('score', 0) shout_data['score'] = score # Add the score to the dictionary shouts_data.append(shout_data) - + shouts_data = sorted( + shouts_data, + key=lambda x: float(x.get('score', '0')), + reverse=True, + ) return shouts_data else: return []