feat: index public search with FTS5

This commit is contained in:
2026-07-19 12:52:44 +08:00
parent 428ee50cd6
commit 82879a36cc
4 changed files with 24 additions and 3 deletions
+18
View File
@@ -154,6 +154,24 @@ db.prepare("UPDATE source_members SET role='editor' WHERE role='member'").run();
db.prepare("INSERT OR IGNORE INTO schema_migrations(version) VALUES(36)").run();
db.prepare("INSERT OR IGNORE INTO schema_migrations(version) VALUES(37)").run();
applyColumnMigration(38, "sources", "attachment_archive_after_days", "ALTER TABLE sources ADD COLUMN attachment_archive_after_days INTEGER");
const ftsSchema = `
CREATE VIRTUAL TABLE IF NOT EXISTS posts_fts USING fts5(content, tags);
CREATE TRIGGER IF NOT EXISTS posts_fts_insert AFTER INSERT ON posts BEGIN
INSERT INTO posts_fts(rowid,content,tags) VALUES(new.id,new.content,new.tags_json);
END;
CREATE TRIGGER IF NOT EXISTS posts_fts_delete AFTER DELETE ON posts BEGIN
DELETE FROM posts_fts WHERE rowid=old.id;
END;
CREATE TRIGGER IF NOT EXISTS posts_fts_update AFTER UPDATE OF content,tags_json ON posts BEGIN
DELETE FROM posts_fts WHERE rowid=old.id;
INSERT INTO posts_fts(rowid,content,tags) VALUES(new.id,new.content,new.tags_json);
END;
`;
db.exec(ftsSchema);
const hasFtsMigration = db.prepare("SELECT 1 FROM schema_migrations WHERE version=39").get();
if (!hasFtsMigration) { db.prepare("INSERT INTO posts_fts(rowid,content,tags) SELECT id,content,tags_json FROM posts").run(); db.prepare("INSERT INTO schema_migrations(version) VALUES(39)").run(); }
db.exec("CREATE INDEX IF NOT EXISTS posts_source_visibility_idx ON posts(source_id,visibility,hidden); CREATE INDEX IF NOT EXISTS posts_author_visibility_idx ON posts(author_id,visibility,hidden);");
db.prepare("INSERT OR IGNORE INTO schema_migrations(version) VALUES(40)").run();
const admin = process.env.ADMIN_USERNAME;
const adminPassword = process.env.ADMIN_PASSWORD;