papertrail/db/migrations/0018_search.sql
caelum0x 695a365ae4 feat: PaperTrail — enterprise evidence-verification platform
Multi-tenant platform (182 pages, 228 API routes, ~30 modules) built on a
deterministic verification core: clinical-trial claims checked against
ClinicalTrials.gov registered results and raw event counts (ARR/NNT/RR+CI
recomputed in code, oracle-tested), code-enforced exact-span grounding, and
multi-source cross-verification. Auth/RBAC/multi-tenancy, document processing
at scale (unpdf + Docling), agentic workflows, Claude Science connector,
compliance/audit, billing, public API, and more.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 07:21:22 +03:00

29 lines
1.3 KiB
SQL

-- Global search: trigram indexes to keep org-scoped ILIKE lookups across
-- claims, documents, evidence, and verifications fast. Indexes only — the
-- searched tables are created by earlier migrations. Idempotent: safe to run
-- repeatedly.
-- pg_trgm powers the trigram (gin_trgm_ops) indexes that make `column ilike
-- '%term%'` queries index-assisted instead of full scans.
create extension if not exists pg_trgm;
-- Claims: match against the claim text, scoped to the org.
create index if not exists claims_text_trgm_idx
on claims using gin (text gin_trgm_ops);
-- Documents: match against filename and extracted body text.
create index if not exists documents_filename_trgm_idx
on documents using gin (filename gin_trgm_ops);
create index if not exists documents_extracted_text_trgm_idx
on documents using gin (extracted_text gin_trgm_ops);
-- Evidence items: match against the curated title.
create index if not exists evidence_items_title_trgm_idx
on evidence_items using gin (title gin_trgm_ops);
-- Verifications: match against the verified claim text. Verifications are
-- org-scoped in search by joining through claims(claim_id -> claims.org_id),
-- so index claim_id to keep that join cheap.
create index if not exists verifications_claim_text_trgm_idx
on verifications using gin (claim_text gin_trgm_ops);