This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import asyncio
|
||||
import json
|
||||
from typing import List
|
||||
|
||||
import aiohttp
|
||||
from services.rediscache import redis
|
||||
|
||||
from orm.shout import Shout
|
||||
from services.rediscache import redis
|
||||
|
||||
|
||||
class SearchService:
|
||||
@@ -16,11 +19,12 @@ class SearchService:
|
||||
SearchService.cache = {}
|
||||
|
||||
@staticmethod
|
||||
async def search(text, limit, offset) -> [Shout]:
|
||||
async def search(text, limit: int = 50, offset: int = 0) -> List[Shout]:
|
||||
cached = await redis.execute("GET", text)
|
||||
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:
|
||||
|
Reference in New Issue
Block a user