feat(reader,search,graphql): added pagination for test only
All checks were successful
Deploy on push / deploy (push) Successful in 51s

This commit is contained in:
Stepan Vladovskiy
2025-04-01 13:57:26 -03:00
parent ecc443c3ad
commit e6adb143fb
2 changed files with 121 additions and 8 deletions

View File

@@ -10,7 +10,7 @@ from orm.shout import Shout, ShoutAuthor, ShoutTopic
from orm.topic import Topic
from services.db import json_array_builder, json_builder, local_session
from services.schema import query
from services.search import search_text
from services.search import search_text, search_text_paginated
from services.viewed import ViewedStorage
from utils.logger import root_logger as logger
@@ -399,10 +399,17 @@ async def load_shouts_search(_, info, text, options):
:param options: Опции фильтрации и сортировки.
:return: Список публикаций, найденных по тексту.
"""
limit = options.get("limit", 10)
limit = options.get("limit", 20)
offset = options.get("offset", 0)
full_limit = options.get("full_limit", 100) # Maximum results to fetch
if isinstance(text, str) and len(text) > 2:
results = await search_text(text, limit, offset)
# Use the new paginated search function
results, total_results = await search_text_paginated(text, limit, offset, full_limit)
# Add the total count to the contextual info for the frontend
logger.info(f"Search '{text}' found {total_results} total results, returning {len(results)} from offset {offset}")
scores = {}
hits_ids = []
for sr in results:
@@ -412,17 +419,29 @@ async def load_shouts_search(_, info, text, options):
scores[shout_id] = sr.get("score")
hits_ids.append(shout_id)
if not hits_ids:
# Return an empty list with total count info
return {"items": [], "total_count": total_results}
q = query_with_stat(info)
q = q.filter(Shout.id.in_(hits_ids))
q = apply_filters(q, options)
shouts = get_shouts_with_links(info, q, limit, offset)
# Add score to each shout
for shout in shouts:
shout["score"] = scores[f"{shout['id']}"]
shouts.sort(key=lambda x: x["score"], reverse=True)
return shouts
return []
shout_id = f"{shout['id']}"
if shout_id in scores:
shout["score"] = scores[shout_id]
# Sort by search relevance score
shouts.sort(key=lambda x: x.get("score", 0), reverse=True)
# Return with total count information
return {"items": shouts, "total_count": total_results}
return {"items": [], "total_count": 0}
@query.field("load_shouts_unrated")