Fossil SCM

Add the "fossil chat reindex" command. Add buttons in the /srchsetup and /setup_chat pages that will rebuild the chat FTS index.

drh 2025-12-11 12:40 trunk
Commit 43af043bd7e33e5a517129c797ff18edb1e66ceefd3e28a329a3aea0912bbc4a
2 files changed +16 -1 +25 -10
+16 -1
--- src/chat.c
+++ src/chat.c
@@ -296,10 +296,11 @@
296296
** chatfts1 table and recreate/reindex it. If bForce is 0, it will
297297
** only index the chat content if the chatfts1 table does not already
298298
** exist.
299299
*/
300300
void chat_rebuild_index(int bForce){
301
+ if( !db_table_exists("repository","chat") ) return;
301302
if( bForce!=0 ){
302303
db_multi_exec("DROP TABLE IF EXISTS chatfts1");
303304
}
304305
if( bForce!=0 || !db_table_exists("repository", "chatfts1") ){
305306
const int tokType = search_tokenizer_type(0);
@@ -1245,10 +1246,19 @@
12451246
**
12461247
** > fossil chat url
12471248
**
12481249
** Show the default URL used to access the chat server.
12491250
**
1251
+** > fossil chat purge
1252
+**
1253
+** Remove chat messages that are older than chat-keep-days and
1254
+** which are not one of the most recent chat-keep-count message.
1255
+**
1256
+** > fossil chat reindex
1257
+**
1258
+** Rebuild the full-text search index for chat
1259
+**
12501260
** Additional subcommands may be added in the future.
12511261
*/
12521262
void chat_command(void){
12531263
const char *zUrl = find_option("remote",0,1);
12541264
int urlFlags = 0;
@@ -1452,12 +1462,17 @@
14521462
}
14531463
}else if( strcmp(g.argv[2],"url")==0 ){
14541464
/* Show the URL to access chat. */
14551465
fossil_print("%s/chat\n", zUrl);
14561466
}else if( strcmp(g.argv[2],"purge")==0 ){
1457
- /* Undocumented debugging command that calls chat_purge() */
1467
+ /* clear out expired chat messages: chat messages that are older then
1468
+ ** chat-keep-days and that are not one or the most recent chat-keep-count
1469
+ ** messages. */
14581470
chat_create_tables();
14591471
chat_purge();
1472
+ }else if( strcmp(g.argv[2],"reindex")==0 ){
1473
+ /* Rebuild the FTS5 index on chat content */
1474
+ chat_rebuild_index(1);
14601475
}else{
14611476
fossil_fatal("no such subcommand \"%s\". Use --help for help", g.argv[2]);
14621477
}
14631478
}
14641479
--- src/chat.c
+++ src/chat.c
@@ -296,10 +296,11 @@
296 ** chatfts1 table and recreate/reindex it. If bForce is 0, it will
297 ** only index the chat content if the chatfts1 table does not already
298 ** exist.
299 */
300 void chat_rebuild_index(int bForce){
 
301 if( bForce!=0 ){
302 db_multi_exec("DROP TABLE IF EXISTS chatfts1");
303 }
304 if( bForce!=0 || !db_table_exists("repository", "chatfts1") ){
305 const int tokType = search_tokenizer_type(0);
@@ -1245,10 +1246,19 @@
1245 **
1246 ** > fossil chat url
1247 **
1248 ** Show the default URL used to access the chat server.
1249 **
 
 
 
 
 
 
 
 
 
1250 ** Additional subcommands may be added in the future.
1251 */
1252 void chat_command(void){
1253 const char *zUrl = find_option("remote",0,1);
1254 int urlFlags = 0;
@@ -1452,12 +1462,17 @@
1452 }
1453 }else if( strcmp(g.argv[2],"url")==0 ){
1454 /* Show the URL to access chat. */
1455 fossil_print("%s/chat\n", zUrl);
1456 }else if( strcmp(g.argv[2],"purge")==0 ){
1457 /* Undocumented debugging command that calls chat_purge() */
 
 
1458 chat_create_tables();
1459 chat_purge();
 
 
 
1460 }else{
1461 fossil_fatal("no such subcommand \"%s\". Use --help for help", g.argv[2]);
1462 }
1463 }
1464
--- src/chat.c
+++ src/chat.c
@@ -296,10 +296,11 @@
296 ** chatfts1 table and recreate/reindex it. If bForce is 0, it will
297 ** only index the chat content if the chatfts1 table does not already
298 ** exist.
299 */
300 void chat_rebuild_index(int bForce){
301 if( !db_table_exists("repository","chat") ) return;
302 if( bForce!=0 ){
303 db_multi_exec("DROP TABLE IF EXISTS chatfts1");
304 }
305 if( bForce!=0 || !db_table_exists("repository", "chatfts1") ){
306 const int tokType = search_tokenizer_type(0);
@@ -1245,10 +1246,19 @@
1246 **
1247 ** > fossil chat url
1248 **
1249 ** Show the default URL used to access the chat server.
1250 **
1251 ** > fossil chat purge
1252 **
1253 ** Remove chat messages that are older than chat-keep-days and
1254 ** which are not one of the most recent chat-keep-count message.
1255 **
1256 ** > fossil chat reindex
1257 **
1258 ** Rebuild the full-text search index for chat
1259 **
1260 ** Additional subcommands may be added in the future.
1261 */
1262 void chat_command(void){
1263 const char *zUrl = find_option("remote",0,1);
1264 int urlFlags = 0;
@@ -1452,12 +1462,17 @@
1462 }
1463 }else if( strcmp(g.argv[2],"url")==0 ){
1464 /* Show the URL to access chat. */
1465 fossil_print("%s/chat\n", zUrl);
1466 }else if( strcmp(g.argv[2],"purge")==0 ){
1467 /* clear out expired chat messages: chat messages that are older then
1468 ** chat-keep-days and that are not one or the most recent chat-keep-count
1469 ** messages. */
1470 chat_create_tables();
1471 chat_purge();
1472 }else if( strcmp(g.argv[2],"reindex")==0 ){
1473 /* Rebuild the FTS5 index on chat content */
1474 chat_rebuild_index(1);
1475 }else{
1476 fossil_fatal("no such subcommand \"%s\". Use --help for help", g.argv[2]);
1477 }
1478 }
1479
+25 -10
--- src/setup.c
+++ src/setup.c
@@ -1591,10 +1591,13 @@
15911591
}
15921592
15931593
style_set_current_feature("setup");
15941594
style_header("Chat Configuration");
15951595
db_begin_transaction();
1596
+ if( P("rbldchatidx") && cgi_csrf_safe(2) ){
1597
+ chat_rebuild_index(1);
1598
+ }
15961599
@ <form action="%R/setup_chat" method="post"><div>
15971600
login_insert_csrf_secret();
15981601
@ <input type="submit" name="submit" value="Apply Changes"></p>
15991602
@ <hr>
16001603
entry_attribute("Initial Chat History Size", 10,
@@ -1643,12 +1646,15 @@
16431646
"chat-alert-sound", "snd", azAlerts[0],
16441647
count(azAlerts)/2, azAlerts);
16451648
@ <p>The sound used in the client-side chat to indicate that a new
16461649
@ chat message has arrived.
16471650
@ (Property: "chat-alert-sound")</p>
1651
+
16481652
@ <hr/>
1649
- @ <p><input type="submit" name="submit" value="Apply Changes"></p>
1653
+ @ <p><input type="submit" name="submit" value="Apply Changes">
1654
+ @ <input type="submit" name="rbldchatidx"\
1655
+ @ value="Rebuild Full-Text Search Index"></p>
16501656
@ </div></form>
16511657
db_end_transaction(0);
16521658
@ <script nonce="%h(style_nonce())">
16531659
@ (function(){
16541660
@ var w = document.getElementById('idsnd');
@@ -2342,19 +2348,24 @@
23422348
@ <br>
23432349
onoff_attribute("Search Built-in Help Text", "search-help", "sh", 0, 0);
23442350
@ <hr>
23452351
@ <p><input type="submit" name="submit" value="Apply Changes"></p>
23462352
@ <hr>
2347
- if( P("fts0") ){
2348
- search_drop_index();
2349
- }else if( P("fts1") ){
2350
- const char *zTokenizer = PD("ftstok","off");
2351
- search_set_tokenizer(zTokenizer);
2352
- search_drop_index();
2353
- search_create_index();
2354
- search_fill_index();
2355
- search_update_index(search_restrict(SRCH_ALL));
2353
+ if( cgi_csrf_safe(2) ){
2354
+ if( P("fts0") ){
2355
+ search_drop_index();
2356
+ }else if( P("fts1") ){
2357
+ const char *zTokenizer = PD("ftstok","off");
2358
+ search_set_tokenizer(zTokenizer);
2359
+ search_drop_index();
2360
+ search_create_index();
2361
+ search_fill_index();
2362
+ search_update_index(search_restrict(SRCH_ALL));
2363
+ }
2364
+ if( P("rbldchatidx") ){
2365
+ chat_rebuild_index(1);
2366
+ }
23562367
}
23572368
if( search_index_exists() ){
23582369
int pgsz = db_int64(0, "PRAGMA repository.page_size;");
23592370
i64 nTotal = db_int64(0, "PRAGMA repository.page_count;")*pgsz;
23602371
i64 nFts = db_int64(0, "SELECT count(*) FROM dbstat"
@@ -2367,10 +2378,14 @@
23672378
@ but takes up space. The index is currently using about %s(zSize)
23682379
@ or %.1f(100.0*(double)nFts/(double)nTotal)%% of the repository.</p>
23692380
select_fts_tokenizer();
23702381
@ <p><input type="submit" name="fts0" value="Delete The Full-Text Index">
23712382
@ <input type="submit" name="fts1" value="Rebuild The Full-Text Index">
2383
+ if( db_table_exists("repository","chat") ){
2384
+ @ <input type="submit" name="rbldchatidx" \
2385
+ @ value="Rebuild The Chat FTS Index">
2386
+ }
23722387
style_submenu_element("FTS Index Debugging","%R/test-ftsdocs");
23732388
}else{
23742389
@ <p>The SQLite search index is disabled. All searching will be
23752390
@ a full-text scan. This usually works fine, but can be slow for
23762391
@ larger repositories.</p>
23772392
--- src/setup.c
+++ src/setup.c
@@ -1591,10 +1591,13 @@
1591 }
1592
1593 style_set_current_feature("setup");
1594 style_header("Chat Configuration");
1595 db_begin_transaction();
 
 
 
1596 @ <form action="%R/setup_chat" method="post"><div>
1597 login_insert_csrf_secret();
1598 @ <input type="submit" name="submit" value="Apply Changes"></p>
1599 @ <hr>
1600 entry_attribute("Initial Chat History Size", 10,
@@ -1643,12 +1646,15 @@
1643 "chat-alert-sound", "snd", azAlerts[0],
1644 count(azAlerts)/2, azAlerts);
1645 @ <p>The sound used in the client-side chat to indicate that a new
1646 @ chat message has arrived.
1647 @ (Property: "chat-alert-sound")</p>
 
1648 @ <hr/>
1649 @ <p><input type="submit" name="submit" value="Apply Changes"></p>
 
 
1650 @ </div></form>
1651 db_end_transaction(0);
1652 @ <script nonce="%h(style_nonce())">
1653 @ (function(){
1654 @ var w = document.getElementById('idsnd');
@@ -2342,19 +2348,24 @@
2342 @ <br>
2343 onoff_attribute("Search Built-in Help Text", "search-help", "sh", 0, 0);
2344 @ <hr>
2345 @ <p><input type="submit" name="submit" value="Apply Changes"></p>
2346 @ <hr>
2347 if( P("fts0") ){
2348 search_drop_index();
2349 }else if( P("fts1") ){
2350 const char *zTokenizer = PD("ftstok","off");
2351 search_set_tokenizer(zTokenizer);
2352 search_drop_index();
2353 search_create_index();
2354 search_fill_index();
2355 search_update_index(search_restrict(SRCH_ALL));
 
 
 
 
 
2356 }
2357 if( search_index_exists() ){
2358 int pgsz = db_int64(0, "PRAGMA repository.page_size;");
2359 i64 nTotal = db_int64(0, "PRAGMA repository.page_count;")*pgsz;
2360 i64 nFts = db_int64(0, "SELECT count(*) FROM dbstat"
@@ -2367,10 +2378,14 @@
2367 @ but takes up space. The index is currently using about %s(zSize)
2368 @ or %.1f(100.0*(double)nFts/(double)nTotal)%% of the repository.</p>
2369 select_fts_tokenizer();
2370 @ <p><input type="submit" name="fts0" value="Delete The Full-Text Index">
2371 @ <input type="submit" name="fts1" value="Rebuild The Full-Text Index">
 
 
 
 
2372 style_submenu_element("FTS Index Debugging","%R/test-ftsdocs");
2373 }else{
2374 @ <p>The SQLite search index is disabled. All searching will be
2375 @ a full-text scan. This usually works fine, but can be slow for
2376 @ larger repositories.</p>
2377
--- src/setup.c
+++ src/setup.c
@@ -1591,10 +1591,13 @@
1591 }
1592
1593 style_set_current_feature("setup");
1594 style_header("Chat Configuration");
1595 db_begin_transaction();
1596 if( P("rbldchatidx") && cgi_csrf_safe(2) ){
1597 chat_rebuild_index(1);
1598 }
1599 @ <form action="%R/setup_chat" method="post"><div>
1600 login_insert_csrf_secret();
1601 @ <input type="submit" name="submit" value="Apply Changes"></p>
1602 @ <hr>
1603 entry_attribute("Initial Chat History Size", 10,
@@ -1643,12 +1646,15 @@
1646 "chat-alert-sound", "snd", azAlerts[0],
1647 count(azAlerts)/2, azAlerts);
1648 @ <p>The sound used in the client-side chat to indicate that a new
1649 @ chat message has arrived.
1650 @ (Property: "chat-alert-sound")</p>
1651
1652 @ <hr/>
1653 @ <p><input type="submit" name="submit" value="Apply Changes">
1654 @ <input type="submit" name="rbldchatidx"\
1655 @ value="Rebuild Full-Text Search Index"></p>
1656 @ </div></form>
1657 db_end_transaction(0);
1658 @ <script nonce="%h(style_nonce())">
1659 @ (function(){
1660 @ var w = document.getElementById('idsnd');
@@ -2342,19 +2348,24 @@
2348 @ <br>
2349 onoff_attribute("Search Built-in Help Text", "search-help", "sh", 0, 0);
2350 @ <hr>
2351 @ <p><input type="submit" name="submit" value="Apply Changes"></p>
2352 @ <hr>
2353 if( cgi_csrf_safe(2) ){
2354 if( P("fts0") ){
2355 search_drop_index();
2356 }else if( P("fts1") ){
2357 const char *zTokenizer = PD("ftstok","off");
2358 search_set_tokenizer(zTokenizer);
2359 search_drop_index();
2360 search_create_index();
2361 search_fill_index();
2362 search_update_index(search_restrict(SRCH_ALL));
2363 }
2364 if( P("rbldchatidx") ){
2365 chat_rebuild_index(1);
2366 }
2367 }
2368 if( search_index_exists() ){
2369 int pgsz = db_int64(0, "PRAGMA repository.page_size;");
2370 i64 nTotal = db_int64(0, "PRAGMA repository.page_count;")*pgsz;
2371 i64 nFts = db_int64(0, "SELECT count(*) FROM dbstat"
@@ -2367,10 +2378,14 @@
2378 @ but takes up space. The index is currently using about %s(zSize)
2379 @ or %.1f(100.0*(double)nFts/(double)nTotal)%% of the repository.</p>
2380 select_fts_tokenizer();
2381 @ <p><input type="submit" name="fts0" value="Delete The Full-Text Index">
2382 @ <input type="submit" name="fts1" value="Rebuild The Full-Text Index">
2383 if( db_table_exists("repository","chat") ){
2384 @ <input type="submit" name="rbldchatidx" \
2385 @ value="Rebuild The Chat FTS Index">
2386 }
2387 style_submenu_element("FTS Index Debugging","%R/test-ftsdocs");
2388 }else{
2389 @ <p>The SQLite search index is disabled. All searching will be
2390 @ a full-text scan. This usually works fine, but can be slow for
2391 @ larger repositories.</p>
2392

Keyboard Shortcuts

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