Fossil SCM

Use temporary triggers, instead of normal schema triggers, to populate the fts index. Fossil disables schema triggers to prevent malicious uses.

dan 2024-07-01 15:22 fts5-chat-search
Commit 21d9ea4adeb3a28c48070da091b9aa09fc42aa954be35e1bc8f9b3df86f91a4b
1 file changed +11 -7
+11 -7
--- src/chat.c
+++ src/chat.c
@@ -301,20 +301,24 @@
301301
if( !db_table_exists("repository", "chatfts1") ){
302302
db_multi_exec(
303303
"CREATE VIRTUAL TABLE repository.chatfts1 USING fts5("
304304
" xmsg, content=chat, content_rowid=msgid, tokenize=porter"
305305
");"
306
- "CREATE TRIGGER repository.chat_ai AFTER INSERT ON chat BEGIN "
307
- " INSERT INTO chatfts1(rowid, xmsg) VALUES(new.msgid, new.xmsg);"
308
- "END;"
309
- "CREATE TRIGGER repository.chat_ad AFTER DELETE ON chat BEGIN "
310
- " INSERT INTO chatfts1(chatfts1, rowid, xmsg) "
311
- " VALUES('delete', old.msgid, old.xmsg);"
312
- "END;"
313306
"INSERT INTO repository.chatfts1(chatfts1) VALUES('rebuild');"
314307
);
315308
}
309
+ db_multi_exec(
310
+ "DROP TRIGGER IF EXISTS chat_ai;"
311
+ "DROP TRIGGER IF EXISTS chat_ad;"
312
+ "CREATE TEMP TRIGGER chat_ai AFTER INSERT ON chat BEGIN "
313
+ " INSERT INTO chatfts1(rowid, xmsg) VALUES(new.msgid, new.xmsg);"
314
+ "END;"
315
+ "CREATE TEMP TRIGGER chat_ad AFTER DELETE ON chat BEGIN "
316
+ " INSERT INTO chatfts1(chatfts1, rowid, xmsg) "
317
+ " VALUES('delete', old.msgid, old.xmsg);"
318
+ "END;"
319
+ );
316320
}
317321
318322
/*
319323
** Delete old content from the chat table.
320324
*/
321325
--- src/chat.c
+++ src/chat.c
@@ -301,20 +301,24 @@
301 if( !db_table_exists("repository", "chatfts1") ){
302 db_multi_exec(
303 "CREATE VIRTUAL TABLE repository.chatfts1 USING fts5("
304 " xmsg, content=chat, content_rowid=msgid, tokenize=porter"
305 ");"
306 "CREATE TRIGGER repository.chat_ai AFTER INSERT ON chat BEGIN "
307 " INSERT INTO chatfts1(rowid, xmsg) VALUES(new.msgid, new.xmsg);"
308 "END;"
309 "CREATE TRIGGER repository.chat_ad AFTER DELETE ON chat BEGIN "
310 " INSERT INTO chatfts1(chatfts1, rowid, xmsg) "
311 " VALUES('delete', old.msgid, old.xmsg);"
312 "END;"
313 "INSERT INTO repository.chatfts1(chatfts1) VALUES('rebuild');"
314 );
315 }
 
 
 
 
 
 
 
 
 
 
 
316 }
317
318 /*
319 ** Delete old content from the chat table.
320 */
321
--- src/chat.c
+++ src/chat.c
@@ -301,20 +301,24 @@
301 if( !db_table_exists("repository", "chatfts1") ){
302 db_multi_exec(
303 "CREATE VIRTUAL TABLE repository.chatfts1 USING fts5("
304 " xmsg, content=chat, content_rowid=msgid, tokenize=porter"
305 ");"
 
 
 
 
 
 
 
306 "INSERT INTO repository.chatfts1(chatfts1) VALUES('rebuild');"
307 );
308 }
309 db_multi_exec(
310 "DROP TRIGGER IF EXISTS chat_ai;"
311 "DROP TRIGGER IF EXISTS chat_ad;"
312 "CREATE TEMP TRIGGER chat_ai AFTER INSERT ON chat BEGIN "
313 " INSERT INTO chatfts1(rowid, xmsg) VALUES(new.msgid, new.xmsg);"
314 "END;"
315 "CREATE TEMP TRIGGER chat_ad AFTER DELETE ON chat BEGIN "
316 " INSERT INTO chatfts1(chatfts1, rowid, xmsg) "
317 " VALUES('delete', old.msgid, old.xmsg);"
318 "END;"
319 );
320 }
321
322 /*
323 ** Delete old content from the chat table.
324 */
325

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button