datamade / how-to

📚 Doing all sorts of things, the DataMade way
MIT License
89 stars 12 forks source link

Build haystack plugin for postgresql FTS #367

Open fgregg opened 6 months ago

fgregg commented 6 months ago

Background

Managed elasticsearch is pretty expensive, and adds another service to interact with.

Postgres full text search (FTS) is pretty good, and we basically always already have a postgres database.

Django has good support for FTS, and we've used in the the past, but in our projects this has meant building custom search interfaces. It would be be able to use Haystack and have postgres be a backend for haystack.

Proposal

  1. A public repo of a hastack backend that is installable from github
  2. A migration document from using elasticsearch as the backend to using postgres

Notes on implementation

Haystack's SimpleBackend would be the starting point. Like that model, we would not implement the methods that are used to create the index, because we would handle those on the models, with GeneratedFields and SearchVectorFields.

SimpleBackend is very simple, and we would want to implement at least faceting, and maybe also "more like this".

Here are some notes on an implementation of facetting with postgres FTS that could be useful.

Here's an example of a third-party haystack backend that is a good bit more complicated than we need, but should give us some guidance on organizing the code and entry points.

derekeder commented 3 weeks ago

@fgregg and I have started working on a package repo here: https://github.com/datamade/postgres-fts-backend

derekeder commented 3 days ago

working on wiring it up to Chicago Councilmatic here: https://github.com/datamade/chi-councilmatic/pull/423