V3 S4 : recherche FTS + facettes (serveur + mobile)

Backend : search_tsv french + GIN (000020), SearchDocumentsVisible
(nom + TS + faits, rang nom > TS > fait sûr > fait douteux, jamais
d'exclusion), facettes issuer/type/montant/période sur
GET /files/search (400 si malformée). Tests repo + handlers + migrations.

Mobile (Room v21) : FTS4 files_fts + triggers partagés
(fresh-install/migration, entité déclarée pour KSP, SQL aligné 21.json),
searchDocuments offline (même rang, accents préservés) + UI filtres
(émetteur, types chips, montants, période ISO, compteur, effacer).

Contrat docs/api-v1.md, V3.md (S4 livré, migrations renumérotées
links->000021, token->000022).
This commit is contained in:
venture
2026-09-26 10:53:56 +02:00
parent ac8bd9acb4
commit 2d984fd665
25 changed files with 2362 additions and 25 deletions
@@ -0,0 +1,2 @@
DROP INDEX IF EXISTS idx_resources_search_tsv;
ALTER TABLE resources DROP COLUMN IF EXISTS search_tsv;
@@ -0,0 +1,13 @@
-- V3 recherche (S4) : plein-texte français sur (nom + OCR).
-- Colonne générée stockée (`to_tsvector(regconfig, text)` est IMMUTABLE,
-- donc autorisée en GENERATED) : pas de trigger, backfill automatique des
-- lignes existantes. Index GIN. Les faits (`resource_facts`) sont joints à
-- la requête (jamais dupliqués) : ils pondèrent le rang sans jamais exclure
-- (humble par design — une confiance < 0.5 déclasse, cf. SearchDocuments).
ALTER TABLE resources
ADD COLUMN search_tsv TSVECTOR
GENERATED ALWAYS AS (
to_tsvector('french', COALESCE(name, '') || ' ' || COALESCE(ocr_text, ''))
) STORED;
CREATE INDEX IF NOT EXISTS idx_resources_search_tsv ON resources USING GIN (search_tsv);
+25
View File
@@ -422,6 +422,31 @@ func TestMigrationsUpDown(t *testing.T) {
t.Error("CHECK fact_type manquant sur resource_facts après 000019")
}
// --- 000020 : plein-texte ----------------------------------------------
var tsvCol int
err = conn.QueryRow(`
SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'resources' AND column_name = 'search_tsv'`).Scan(&tsvCol)
if err != nil {
t.Fatalf("search_tsv column: %v", err)
}
if tsvCol == 0 {
t.Error("colonne resources.search_tsv manquante après 000020")
}
var tsvIdx int
err = conn.QueryRow(`
SELECT COUNT(*) FROM pg_index i
JOIN pg_class t ON t.oid = i.indrelid
WHERE t.relname = 'resources' AND i.indisvalid
AND pg_get_indexdef(i.indexrelid) LIKE '%idx_resources_search_tsv%'`).Scan(&tsvIdx)
if err != nil {
t.Fatalf("000020 index: %v", err)
}
if tsvIdx == 0 {
t.Error("index idx_resources_search_tsv manquant après 000020")
}
if err := MigrateDownDatabase(url); err != nil {
t.Fatalf("migrate down: %v", err)
}