Repository navigation
Add full-text search and verify PostgreSQL support - #11
Merged
Merged
Conversation
A SearchIndex service with two engines: an FTS5 table on SQLite, and a tsvector + pg_trgm table on PostgreSQL (data-storage-backup.md 2.5, master plan step 7). A session listener re-indexes what each commit touches, backup imports rebuild the index, and the app fills an empty index at startup. Guests never match serials, MACs, or vendors. Adds GET /api/v1/search, a header search box, and a search page. Posted by Claude on behalf of @ShaneCurcuru Generated-by: Claude Code
Add pg8000 (BSD-3-Clause) as the optional `postgres` extra, as Shane approved, requiring 1.31.5 or later for the CVE-2025-61385 fix. Its dependencies are scramp (MIT-0) and asn1crypto (MIT). Setting DOMUS_TEST_DATABASE_URL runs the whole suite against Postgres, with one fresh database per test. Fixes found that way: - Backup import: pg8000 reports constraint violations as ProgrammingError, so treat SQLSTATE class 23 as bad import data too. - Search: index Postgres text split the same way as queries, since the Postgres parser reads "SN-77441" as "sn" and "-77441"; type the @@ comparison as boolean; match title typos with word_similarity. - Tests: skip the SQLite pragma test on Postgres, and use the right search table name per engine. Posted by Claude on behalf of @ShaneCurcuru Generated-by: Claude Code
Main added migration 0002 (canvases and placement), so the search index migration becomes 0003 and follows it. openapi.json, schema.d.ts, and uv.lock are regenerated. Posted by Claude on behalf of @ShaneCurcuru Generated-by: Claude Code
Shane decided that packages whose metadata says only "BSD License" are acceptable without a per-package review (decision 21). The alias maps it to BSD-3-Clause, so the pg8000 override is no longer needed. Posted by Claude on behalf of @ShaneCurcuru Generated-by: Claude Code
Main's PR #10 took decisions 21 and 22, so the generic BSD license decision becomes 23. openapi.json, schema.d.ts, and uv.lock are regenerated; the search router and nav entry sit alongside the new Home Assistant and sample-data ones. Posted by Claude on behalf of @ShaneCurcuru Generated-by: Claude Code
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.
Requested by Shane · project thread
What this does
This PR implements the search index from the end of step 7 in
docs/_prompts/plan/HomeIOT-Master-Plan.mdand section 2.5 ofdata-storage-backup.md. It also checks the experimental PostgreSQL support (decision 2) by running the whole test suite against Postgres.Search
There is one
SearchIndexservice (src/domus/services/search.py) with two engines behind it.search_fts. It uses the unicode61 tokenizer with diacritics removed, and bm25 ranking that weights title matches highest.search_doctable with generatedtsvectorcolumns. It uses thesimpleconfiguration, so model numbers are not stemmed. A pg_trgm word-similarity match on the title catches typos such as "hallwya".GET /api/v1/search?q=&property_id=&limit=returns{query, assets, areas}. Every word has to match as the start of a word. Results go through the same access checks as the list endpoints, so hidden items are left out and guests get the guest schemas./searchpage that lists matching areas and devices.The index is kept in sync by the application, not by database triggers:
make_session_factory, re-indexes whatever each commit touched. That includes devices created by the Home Assistant import.delete()(asset tags) marks its asset by hand.Base.metadata, so backups never carry them, and the Alembic schema comparison skips them.PostgreSQL
domus[postgres]=pg8000>=1.31.5. Shane approved it on the decision card. The licenses are pg8000 BSD-3-Clause, scramp MIT-0 and asn1crypto MIT. Versions 1.31.4 and older have CVE-2025-61385 (SQL injection viapg8000.native.literal), hence the minimum version. Domus doesn't call that function.docs/_prompts/01-decisions.md; 21 and 22 were taken by Add Home Assistant device import (v0.1 step 10) #10.scripts/check_licenses.pynow maps it to BSD-3-Clause, so pg8000 needs no override of its own.DOMUS_TEST_DATABASE_URLruns the whole suite against Postgres, with one fresh database per test. CONTRIBUTING.md has the steps.ProgrammingError, so a backup import with a missing parent row crashed instead of failing cleanly. The importer now treats SQLSTATE class 23 the same asIntegrityError.How I read the ask
sensitivityrules, so indexing them is a follow-up.GET /api/v1/searchis a new endpoint, so the published API grows.openapi.jsonandschema.d.tsare regenerated.Left undone
--all-groupsbut not--all-extras, so its license check doesn't cover thepostgresextra. I checked it locally and all 62 distributions pass.word_similarity()function rather than pg_trgm's<%operator. SQLAlchemy doesn't escape a%in a custom operator name, and pg8000 would read it as a parameter marker. So the trigram index on the title isn't used. That's fine at home scale.A gotcha worth knowing
SQLAlchemy's
event.contains()gives false positives for a newsessionmakeronce an old one has been garbage collected, because its registry is keyed byid(). A quick script showed 2,981 false positives out of 3,000. An "already installed?" guard made search tests fail at random in the full suite, soinstall()has no guard and is called once per factory.Checks
These were run after merging main, which now includes #8, #9 and #10.
uv run ruff check .,uv run ruff format --check .,uv run pyright(strict): cleanuv run pyteston SQLite: 428 passed, 1 skipped (the Postgres-only typo test)npm run lint,npm run typecheck,npx vitest run(76 passed),prettier: cleanPosted by Claude on behalf of @ShaneCurcuru
🤖 Generated with Claude Code
https://claude.ai/code/session_012UmrcoAD3ijA8mYmuzLyKz