fix(reader.py): change sorting and answer on querys
All checks were successful
Deploy on push / deploy (push) Successful in 50s
All checks were successful
Deploy on push / deploy (push) Successful in 50s
This commit is contained in:
parent
bc4ec79240
commit
78326047bf
|
@ -410,8 +410,8 @@ async def load_shouts_search(_, info, text, options):
|
||||||
if not results:
|
if not results:
|
||||||
logger.info(f"No search results found for '{text}'")
|
logger.info(f"No search results found for '{text}'")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# Build a map of document IDs to their search scores
|
# Extract IDs and scores
|
||||||
scores = {}
|
scores = {}
|
||||||
hits_ids = []
|
hits_ids = []
|
||||||
for sr in results:
|
for sr in results:
|
||||||
|
@ -426,18 +426,14 @@ async def load_shouts_search(_, info, text, options):
|
||||||
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", {}))
|
||||||
|
|
||||||
# Fetch shout details
|
#
|
||||||
shouts = get_shouts_with_links(info, q, limit, offset)
|
shouts = get_shouts_with_links(info, q, len(hits_ids), 0)
|
||||||
|
|
||||||
# Populate search scores in results and sort by score
|
# Add scores and sort
|
||||||
for shout in shouts:
|
for shout in shouts:
|
||||||
shout_id = str(shout['id'])
|
shout_id = str(shout['id'])
|
||||||
if shout_id in scores:
|
shout["score"] = scores.get(shout_id, 0)
|
||||||
shout["score"] = scores[shout_id]
|
|
||||||
else:
|
|
||||||
shout["score"] = 0 # Default score if not found in search results
|
|
||||||
|
|
||||||
# Sort by score (highest first)
|
|
||||||
shouts.sort(key=lambda x: x["score"], reverse=True)
|
shouts.sort(key=lambda x: x["score"], reverse=True)
|
||||||
|
|
||||||
return shouts
|
return shouts
|
||||||
|
|
|
@ -574,7 +574,7 @@ class SearchService:
|
||||||
try:
|
try:
|
||||||
search_limit = limit
|
search_limit = limit
|
||||||
search_offset = offset
|
search_offset = offset
|
||||||
|
|
||||||
# Always prefetch full results when caching is enabled
|
# Always prefetch full results when caching is enabled
|
||||||
if SEARCH_CACHE_ENABLED:
|
if SEARCH_CACHE_ENABLED:
|
||||||
search_limit = SEARCH_PREFETCH_SIZE # Always fetch a large set
|
search_limit = SEARCH_PREFETCH_SIZE # Always fetch a large set
|
||||||
|
@ -592,7 +592,7 @@ class SearchService:
|
||||||
|
|
||||||
# logger.info(f"Raw search response: {response.text}")
|
# logger.info(f"Raw search response: {response.text}")
|
||||||
result = response.json()
|
result = response.json()
|
||||||
logger.info(f"Parsed search response: {result}")
|
# logger.info(f"Parsed search response: {result}")
|
||||||
|
|
||||||
formatted_results = result.get("results", [])
|
formatted_results = result.get("results", [])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user