SQLite FTS5 Full-Text Search Schema & Sync Triggers
-- High-Performance SQLite FTS5 External Content Virtual Table
-- Synchronizes search index with the primary 'articles' table
-- 1. Create FTS5 Virtual Table
CREATE VIRTUAL TABLE IF NOT EXISTS articles_fts USING fts5(
title,
body,
content='articles',
content_rowid='id',
tokenize='unicode61 remove_diacritics 2'
);
-- 2. After Insert Trigger
CREATE TRIGGER IF NOT EXISTS articles_ai AFTER INSERT ON articles
BEGIN
INSERT INTO articles_fts(rowid, title, body)
VALUES (new.id, new.title, new.body);
END;
-- 3. After Delete Trigger
CREATE TRIGGER IF NOT EXISTS articles_ad AFTER DELETE ON articles
BEGIN
INSERT INTO articles_fts(articles_fts, rowid, title, body)
VALUES ('delete', old.id, old.title, old.body);
END;
-- 4. After Update Trigger
CREATE TRIGGER IF NOT EXISTS articles_au AFTER UPDATE ON articles
BEGIN
INSERT INTO articles_fts(articles_fts, rowid, title, body)
VALUES ('delete', old.id, old.title, old.body);
INSERT INTO articles_fts(rowid, title, body)
VALUES (new.id, new.title, new.body);
END;