fix(reader): sorting by rang not by id in cash
All checks were successful
Deploy on push / deploy (push) Successful in 6s

This commit is contained in:
Stepan Vladovskiy 2025-04-03 13:51:13 -03:00
parent 78326047bf
commit c533241d1e

View File

@ -421,7 +421,7 @@ async def load_shouts_search(_, info, text, options):
scores[shout_id] = sr.get("score") scores[shout_id] = sr.get("score")
hits_ids.append(shout_id) hits_ids.append(shout_id)
# Build query to fetch shout details # Query DB for only the IDs in the current page
q = query_with_stat(info) q = query_with_stat(info)
q = q.filter(Shout.id.in_(hits_ids)) q = q.filter(Shout.id.in_(hits_ids))
q = apply_filters(q, options.get("filters", {})) q = apply_filters(q, options.get("filters", {}))
@ -429,12 +429,13 @@ async def load_shouts_search(_, info, text, options):
# #
shouts = get_shouts_with_links(info, q, len(hits_ids), 0) shouts = get_shouts_with_links(info, q, len(hits_ids), 0)
# Add scores and sort # Add scores from search results
for shout in shouts: for shout in shouts:
shout_id = str(shout['id']) shout_id = str(shout['id'])
shout["score"] = scores.get(shout_id, 0) shout["score"] = scores.get(shout_id, 0)
shouts.sort(key=lambda x: x["score"], reverse=True) # Re-sort by search score to maintain ranking
shouts.sort(key=lambda x: scores.get(str(x['id']), 0), reverse=True)
return shouts return shouts
return [] return []