mediacloud / news-search-api

Internal API server that offers search access to the Media Cloud Online News Archive (in Elasticsearch).
https://mediacloud.org
GNU Affero General Public License v3.0
1 stars 3 forks source link

Extract ES interface from FastAPI routing definition #85

Closed pgulley closed 1 month ago

pgulley commented 1 month ago

Creates queries.py, which contains a QueryBuilder and an EsClientWrapper, separating concerns more explicitly. Also removes unused significant/rare term query logic. (Addressing #71)

Questions:

pgulley commented 1 month ago
1. I agree we need to choose whether to continue using `config.yml` or not. I like the idea of `config`/`settings` module that abstract pulling things from system env vars (or `.env` file) in a type-safe manner. This being a FastAPI app, my vote would be to switch to using [`pydantic settings`](https://fastapi.tiangolo.com/advanced/settings/#settings-in-another-module) instead of building one from scratch around `getnev`.

Quick glance at pydantic_settings and I'm impressed- I'll experiment weaving it in now. It should drop-in no problem to the way we're passing in environment variables now, and it would be a one-line change to go back to using a .env file if needed in the future for some reason.

pgulley commented 1 month ago

Floating back through here to reiterate that pydantic_settings is wonderful- one of those tools that makes me wonder how I got by without it. Thanks for the tip @kilemensi