feat(storage): SQLite FTS5+BM25 log search#52
Merged
Conversation
SQLite log search now routes through an FTS5 virtual table (`logs_fts`) over `(body, service_name)` with `bm25()` ranking. The index is kept in sync via AFTER INSERT/DELETE/UPDATE triggers on `logs`, so retention purges and manual deletes propagate automatically. The setup is idempotent and backfills existing rows on first boot via FTS5's `rebuild` command. User input is escaped and prefix-suffixed (`*`) so partial words still match (e.g., `conn` matches `connection`); the porter tokenizer covers inflectional matches (`panic` matches `panicked`). On any FTS5 query error the repository transparently falls back to LIKE so a misbehaving index never surfaces as a 500. Postgres keeps the existing `pg_trgm` GIN path; MySQL/SQL Server keep LIKE. New tests cover BM25 ordering, prefix and stemming matches, tenant isolation, the delete trigger sync, special-character escaping, and the GetLogsV2 search path. Docs updated in CLAUDE.md and OPERATIONS.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
logs_fts) overlogs(body, service_name)on every SQLite boot viaAutoMigrateModels— idempotent, withrebuildbackfill for pre-existing rows.SearchLogsandGetLogsV2through the FTS5 path on SQLite ordered bybm25()(lower = more relevant). Postgres keeps the existingpg_trgmGIN path; MySQL/SQL Server keep LIKE.*) soconnstill matchesconnection; theportertokenizer handles English stems (panicmatchespanicked);unicode61is case- and accent-insensitive.Why
Phase 3a of the 7-day-retention robustness initiative. Replaces full-table LIKE scans for log search on the default SQLite storage adaptor with a BM25-ranked inverted index. Postgres already had
pg_trgm; this brings the SQLite path to parity for substring/relevance search. Phase 3b will follow with Postgres declarative partitioning as an opt-in adapter.Test plan
go test ./internal/storage/ -run 'TestFTS5|TestSearchLogs|TestGetLogsV2|TestSetupSQLite|TestSQLite_LIKE|TestPurgeLogs|TestCompressedText'— passgo test ./... -race -count=1— full tree green under race detectorgo vet ./...— cleangolangci-lint run --new-from-rev=origin/main— cleantenant_id)PurgeLogsBatchedAND OR NOT,",* + -,{ } ( )) escape safelysetupSQLiteFTS5is idempotent on re-runTestSearchLogs_*andTestSQLite_LIKE_CaseInsensitivityForASCIIstill pass🤖 Generated with Claude Code