This commit is contained in:
parent
258bb4e779
commit
6c398fc593
|
@ -24,7 +24,12 @@ class SearchService:
|
||||||
async def __init__(self, index_name='search_index'):
|
async def __init__(self, index_name='search_index'):
|
||||||
logger.info('initialized')
|
logger.info('initialized')
|
||||||
self.index_name = index_name
|
self.index_name = index_name
|
||||||
self.elasticsearch_client = Elasticsearch(f'{ELASTIC_URL}', verify_certs=False)
|
self.disabled = False
|
||||||
|
try:
|
||||||
|
self.elasticsearch_client = Elasticsearch(f'{ELASTIC_URL}', verify_certs=False)
|
||||||
|
except Exception as exc:
|
||||||
|
logger.error(exc)
|
||||||
|
self.disabled = True
|
||||||
self.check_index()
|
self.check_index()
|
||||||
|
|
||||||
if ELASTIC_REINDEX:
|
if ELASTIC_REINDEX:
|
||||||
|
@ -129,10 +134,11 @@ async def search_text(text: str, limit: int = 50, offset: int = 0):
|
||||||
try:
|
try:
|
||||||
# Use a key with a prefix to differentiate search results from other Redis data
|
# Use a key with a prefix to differentiate search results from other Redis data
|
||||||
redis_key = f'search:{text}'
|
redis_key = f'search:{text}'
|
||||||
# Use OpenSearchService.search_post method
|
if not search.disabled:
|
||||||
payload = search.search_post(text, limit, offset)
|
# Use OpenSearchService.search_post method
|
||||||
# Use Redis as cache with TTL
|
payload = search.search_post(text, limit, offset)
|
||||||
await redis.execute('SETEX', redis_key, REDIS_TTL, json.dumps(payload))
|
# Use Redis as cache with TTL
|
||||||
|
await redis.execute('SETEX', redis_key, REDIS_TTL, json.dumps(payload))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f'Error during search: {e}')
|
logging.error(f'Error during search: {e}')
|
||||||
return payload
|
return payload
|
||||||
|
|
Loading…
Reference in New Issue
Block a user