Skip to content

Add Elasticsearch as optional search backend#230

Draft
jakebromberg wants to merge 1 commit intomainfrom
feature/elasticsearch-search
Draft

Add Elasticsearch as optional search backend#230
jakebromberg wants to merge 1 commit intomainfrom
feature/elasticsearch-search

Conversation

@jakebromberg
Copy link
Member

Summary

  • Adds Elasticsearch as an optional search backend for the library catalog with graceful degradation to PostgreSQL pg_trgm
  • Introduces a search facade pattern (apps/backend/services/search/) that routes to ES when ELASTICSEARCH_URL is set, falls back to pg_trgm on any error
  • Renames existing pg_trgm search functions with pgTrgm prefix and re-exports facade versions under the original names (no callers need to change)
  • Expands /healthcheck to report ES status (connected, unavailable, or disabled)
  • Adds Docker Compose ES services for dev and ci profiles with 256MB memory cap
  • Includes 25 new unit tests covering ES client, search queries, and facade fallback behavior

Closes #229

Test plan

  • npm run test:unit -- all 266 tests pass (21 suites)
  • npm run typecheck -- no type errors
  • npm run lint -- 0 errors (143 pre-existing warnings)
  • Local dev without ES: npm run dev starts normally, search works via pg_trgm, healthcheck shows elasticsearch: "disabled"
  • Local dev with ES: Set ELASTICSEARCH_URL=http://localhost:9200, run ES container, healthcheck shows elasticsearch: "connected"

…adation to pg_trgm

Adds a search facade that routes library catalog queries to Elasticsearch when ELASTICSEARCH_URL is set, falling back to PostgreSQL pg_trgm on any ES error or when the env var is unset. This enables Lucene-powered fuzzy matching, stemming, and relevance ranking while preserving the existing pg_trgm behavior as the default.

New files: ES client singleton, index mapping/lifecycle, ES search implementations (searchLibraryES, findSimilarArtistES, searchAlbumsByTitleES, searchByArtistES), sync stubs (PR 2), and the search facade. Renames pg_trgm functions with pgTrgm prefix and re-exports facade versions under the original names so no callers need to change imports.

Also adds: Docker Compose ES services (dev + ci profiles), expanded /healthcheck with ES status, unit tests for client, search, and facade, updated CLAUDE.md and .env.example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Elasticsearch as optional search backend for library catalog

2 participants