elastic_search_manager.py 559 B

1234567891011121314151617
  1. from __future__ import annotations
  2. from app.core.config import GlobalConfigSettings
  3. from app.infra.external import AsyncElasticSearchClient
  4. class ElasticSearchManager:
  5. def __init__(self, config: GlobalConfigSettings):
  6. self.config = config
  7. async def search(self, keywords: str, size: int = 10) -> dict:
  8. async with AsyncElasticSearchClient(self.config) as client:
  9. results = await client.search(search_keys=keywords, size=size)
  10. return {
  11. "total": len(results),
  12. "results": results,
  13. }