This commit is contained in:
parent
f52db8f9e5
commit
71000aad35
|
@ -24,13 +24,14 @@ class SearchService:
|
|||
if not cached:
|
||||
async with SearchService.lock:
|
||||
# Use aiohttp to send a request to ElasticSearch
|
||||
# TODO: add limit offset usage
|
||||
async with aiohttp.ClientSession() as session:
|
||||
search_url = f"https://search.discours.io/search?q={text}"
|
||||
async with session.get(search_url) as response:
|
||||
if response.status == 200:
|
||||
payload = await response.json()
|
||||
await redis.execute("SET", text, json.dumps(payload))
|
||||
return payload
|
||||
return payload[offset : offset + limit]
|
||||
else:
|
||||
print(f"[services.search] response: {response.status} {response.text}")
|
||||
else:
|
||||
return json.loads(cached)
|
||||
return json.loads(cached)[offset : offset + limit]
|
||||
|
|
Loading…
Reference in New Issue
Block a user