Fossil SCM

Get "fossil rebuild" to work on an indexed database, and automatically recompute the index.

drh 2015-02-03 16:54 trunk
Commit 18c0ab6bf1f79a5c71e897cd7e298b638253855e
--- src/allrepo.c
+++ src/allrepo.c
@@ -229,10 +229,12 @@
229229
collect_argument(&extra, "vacuum",0);
230230
collect_argument(&extra, "deanalyze",0);
231231
collect_argument(&extra, "analyze",0);
232232
collect_argument(&extra, "wal",0);
233233
collect_argument(&extra, "stats",0);
234
+ collect_argument(&extra, "index",0);
235
+ collect_argument(&extra, "no-index",0);
234236
}else if( strncmp(zCmd, "setting", n)==0 ){
235237
zCmd = "setting -R";
236238
collect_argv(&extra, 3);
237239
}else if( strncmp(zCmd, "unset", n)==0 ){
238240
zCmd = "unset -R";
239241
--- src/allrepo.c
+++ src/allrepo.c
@@ -229,10 +229,12 @@
229 collect_argument(&extra, "vacuum",0);
230 collect_argument(&extra, "deanalyze",0);
231 collect_argument(&extra, "analyze",0);
232 collect_argument(&extra, "wal",0);
233 collect_argument(&extra, "stats",0);
 
 
234 }else if( strncmp(zCmd, "setting", n)==0 ){
235 zCmd = "setting -R";
236 collect_argv(&extra, 3);
237 }else if( strncmp(zCmd, "unset", n)==0 ){
238 zCmd = "unset -R";
239
--- src/allrepo.c
+++ src/allrepo.c
@@ -229,10 +229,12 @@
229 collect_argument(&extra, "vacuum",0);
230 collect_argument(&extra, "deanalyze",0);
231 collect_argument(&extra, "analyze",0);
232 collect_argument(&extra, "wal",0);
233 collect_argument(&extra, "stats",0);
234 collect_argument(&extra, "index",0);
235 collect_argument(&extra, "no-index",0);
236 }else if( strncmp(zCmd, "setting", n)==0 ){
237 zCmd = "setting -R";
238 collect_argv(&extra, 3);
239 }else if( strncmp(zCmd, "unset", n)==0 ){
240 zCmd = "unset -R";
241
--- src/rebuild.c
+++ src/rebuild.c
@@ -533,10 +533,12 @@
533533
** --vacuum Run VACUUM on the database after rebuilding
534534
** --deanalyze Remove ANALYZE tables from the database
535535
** --analyze Run ANALYZE on the database after rebuilding
536536
** --wal Set Write-Ahead-Log journalling mode on the database
537537
** --stats Show artifact statistics after rebuilding
538
+** --index Always add in the full-text search index
539
+** --no-index Always omit the full-text search index
538540
**
539541
** See also: deconstruct, reconstruct
540542
*/
541543
void rebuild_database(void){
542544
int forceFlag;
@@ -550,10 +552,11 @@
550552
int runVacuum;
551553
int runDeanalyze;
552554
int runAnalyze;
553555
int runCompress;
554556
int showStats;
557
+ int runReindex;
555558
556559
omitVerify = find_option("noverify",0,0)!=0;
557560
forceFlag = find_option("force","f",0)!=0;
558561
randomizeFlag = find_option("randomize", 0, 0)!=0;
559562
doClustering = find_option("cluster", 0, 0)!=0;
@@ -580,15 +583,19 @@
580583
usage("?REPOSITORY-FILENAME?");
581584
}
582585
db_close(1);
583586
db_open_repository(g.zRepositoryName);
584587
}
588
+ runReindex = search_index_exists();
589
+ if( find_option("index",0,0)!=0 ) runReindex = 1;
590
+ if( find_option("no-index",0,0)!=0 ) runReindex = 0;
585591
586592
/* We should be done with options.. */
587593
verify_all_options();
588594
589595
db_begin_transaction();
596
+ search_drop_index();
590597
ttyOutput = 1;
591598
errCnt = rebuild_db(randomizeFlag, 1, doClustering);
592599
reconstruct_private_table();
593600
db_multi_exec(
594601
"REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
@@ -634,10 +641,11 @@
634641
}
635642
if( activateWal ){
636643
db_multi_exec("PRAGMA journal_mode=WAL;");
637644
}
638645
}
646
+ if( runReindex ) search_rebuild_index();
639647
if( showStats ){
640648
static const struct { int idx; const char *zLabel; } aStat[] = {
641649
{ CFTYPE_ANY, "Artifacts:" },
642650
{ CFTYPE_MANIFEST, "Manifests:" },
643651
{ CFTYPE_CLUSTER, "Clusters:" },
644652
--- src/rebuild.c
+++ src/rebuild.c
@@ -533,10 +533,12 @@
533 ** --vacuum Run VACUUM on the database after rebuilding
534 ** --deanalyze Remove ANALYZE tables from the database
535 ** --analyze Run ANALYZE on the database after rebuilding
536 ** --wal Set Write-Ahead-Log journalling mode on the database
537 ** --stats Show artifact statistics after rebuilding
 
 
538 **
539 ** See also: deconstruct, reconstruct
540 */
541 void rebuild_database(void){
542 int forceFlag;
@@ -550,10 +552,11 @@
550 int runVacuum;
551 int runDeanalyze;
552 int runAnalyze;
553 int runCompress;
554 int showStats;
 
555
556 omitVerify = find_option("noverify",0,0)!=0;
557 forceFlag = find_option("force","f",0)!=0;
558 randomizeFlag = find_option("randomize", 0, 0)!=0;
559 doClustering = find_option("cluster", 0, 0)!=0;
@@ -580,15 +583,19 @@
580 usage("?REPOSITORY-FILENAME?");
581 }
582 db_close(1);
583 db_open_repository(g.zRepositoryName);
584 }
 
 
 
585
586 /* We should be done with options.. */
587 verify_all_options();
588
589 db_begin_transaction();
 
590 ttyOutput = 1;
591 errCnt = rebuild_db(randomizeFlag, 1, doClustering);
592 reconstruct_private_table();
593 db_multi_exec(
594 "REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
@@ -634,10 +641,11 @@
634 }
635 if( activateWal ){
636 db_multi_exec("PRAGMA journal_mode=WAL;");
637 }
638 }
 
639 if( showStats ){
640 static const struct { int idx; const char *zLabel; } aStat[] = {
641 { CFTYPE_ANY, "Artifacts:" },
642 { CFTYPE_MANIFEST, "Manifests:" },
643 { CFTYPE_CLUSTER, "Clusters:" },
644
--- src/rebuild.c
+++ src/rebuild.c
@@ -533,10 +533,12 @@
533 ** --vacuum Run VACUUM on the database after rebuilding
534 ** --deanalyze Remove ANALYZE tables from the database
535 ** --analyze Run ANALYZE on the database after rebuilding
536 ** --wal Set Write-Ahead-Log journalling mode on the database
537 ** --stats Show artifact statistics after rebuilding
538 ** --index Always add in the full-text search index
539 ** --no-index Always omit the full-text search index
540 **
541 ** See also: deconstruct, reconstruct
542 */
543 void rebuild_database(void){
544 int forceFlag;
@@ -550,10 +552,11 @@
552 int runVacuum;
553 int runDeanalyze;
554 int runAnalyze;
555 int runCompress;
556 int showStats;
557 int runReindex;
558
559 omitVerify = find_option("noverify",0,0)!=0;
560 forceFlag = find_option("force","f",0)!=0;
561 randomizeFlag = find_option("randomize", 0, 0)!=0;
562 doClustering = find_option("cluster", 0, 0)!=0;
@@ -580,15 +583,19 @@
583 usage("?REPOSITORY-FILENAME?");
584 }
585 db_close(1);
586 db_open_repository(g.zRepositoryName);
587 }
588 runReindex = search_index_exists();
589 if( find_option("index",0,0)!=0 ) runReindex = 1;
590 if( find_option("no-index",0,0)!=0 ) runReindex = 0;
591
592 /* We should be done with options.. */
593 verify_all_options();
594
595 db_begin_transaction();
596 search_drop_index();
597 ttyOutput = 1;
598 errCnt = rebuild_db(randomizeFlag, 1, doClustering);
599 reconstruct_private_table();
600 db_multi_exec(
601 "REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
@@ -634,10 +641,11 @@
641 }
642 if( activateWal ){
643 db_multi_exec("PRAGMA journal_mode=WAL;");
644 }
645 }
646 if( runReindex ) search_rebuild_index();
647 if( showStats ){
648 static const struct { int idx; const char *zLabel; } aStat[] = {
649 { CFTYPE_ANY, "Artifacts:" },
650 { CFTYPE_MANIFEST, "Manifests:" },
651 { CFTYPE_CLUSTER, "Clusters:" },
652
+20 -9
--- src/search.c
+++ src/search.c
@@ -1136,28 +1136,32 @@
11361136
;
11371137
11381138
/*
11391139
** Create or drop the tables associated with a full-text index.
11401140
*/
1141
+static int searchIdxExists = -1;
11411142
void search_create_index(void){
11421143
const char *zDb = db_name("repository");
11431144
search_sql_setup(g.db);
11441145
db_multi_exec(zFtsSchema/*works-like:"%w%w%w%w%w"*/,
11451146
zDb, zDb, zDb, zDb, zDb);
1147
+ searchIdxExists = 1;
11461148
}
11471149
void search_drop_index(void){
11481150
const char *zDb = db_name("repository");
11491151
db_multi_exec(zFtsDrop/*works-like:"%w%w%w"*/, zDb, zDb, zDb);
1152
+ searchIdxExists = 0;
11501153
}
11511154
11521155
/*
11531156
** Return true if the full-text search index exists
11541157
*/
11551158
int search_index_exists(void){
1156
- static int fExists = -1;
1157
- if( fExists<0 ) fExists = db_table_exists("repository","ftsdocs");
1158
- return fExists;
1159
+ if( searchIdxExists<0 ){
1160
+ searchIdxExists = db_table_exists("repository","ftsdocs");
1161
+ }
1162
+ return searchIdxExists;
11591163
}
11601164
11611165
/*
11621166
** Fill the FTSDOCS table with unindexed entries for everything
11631167
** in the repository. This uses INSERT OR IGNORE so entries already
@@ -1361,10 +1365,22 @@
13611365
}
13621366
if( srchFlags & SRCH_WIKI ){
13631367
search_update_wiki_index();
13641368
}
13651369
}
1370
+
1371
+/*
1372
+** Construct, prepopulate, and then update the full-text index.
1373
+*/
1374
+void search_rebuild_index(void){
1375
+ fossil_print("rebuilding the search index...");
1376
+ fflush(stdout);
1377
+ search_create_index();
1378
+ search_fill_index();
1379
+ search_update_index(search_restrict(SRCH_ALL));
1380
+ fossil_print(" done\n");
1381
+}
13661382
13671383
/*
13681384
** COMMAND: fts-config*
13691385
**
13701386
** Usage: fossil fts-config ?SUBCOMMAND? ?ARGUMENT?
@@ -1443,16 +1459,11 @@
14431459
/* destroy or rebuild the index, if requested */
14441460
if( iAction>=1 ){
14451461
search_drop_index();
14461462
}
14471463
if( iAction>=2 ){
1448
- fossil_print("rebuilding the search index...");
1449
- fflush(stdout);
1450
- search_create_index();
1451
- search_fill_index();
1452
- search_update_index(search_restrict(SRCH_ALL));
1453
- fossil_print(" done\n");
1464
+ search_rebuild_index();
14541465
}
14551466
14561467
/* Always show the status before ending */
14571468
for(i=0; i<ArraySize(aSetng); i++){
14581469
fossil_print("%-16s %s\n", aSetng[i].zName,
14591470
--- src/search.c
+++ src/search.c
@@ -1136,28 +1136,32 @@
1136 ;
1137
1138 /*
1139 ** Create or drop the tables associated with a full-text index.
1140 */
 
1141 void search_create_index(void){
1142 const char *zDb = db_name("repository");
1143 search_sql_setup(g.db);
1144 db_multi_exec(zFtsSchema/*works-like:"%w%w%w%w%w"*/,
1145 zDb, zDb, zDb, zDb, zDb);
 
1146 }
1147 void search_drop_index(void){
1148 const char *zDb = db_name("repository");
1149 db_multi_exec(zFtsDrop/*works-like:"%w%w%w"*/, zDb, zDb, zDb);
 
1150 }
1151
1152 /*
1153 ** Return true if the full-text search index exists
1154 */
1155 int search_index_exists(void){
1156 static int fExists = -1;
1157 if( fExists<0 ) fExists = db_table_exists("repository","ftsdocs");
1158 return fExists;
 
1159 }
1160
1161 /*
1162 ** Fill the FTSDOCS table with unindexed entries for everything
1163 ** in the repository. This uses INSERT OR IGNORE so entries already
@@ -1361,10 +1365,22 @@
1361 }
1362 if( srchFlags & SRCH_WIKI ){
1363 search_update_wiki_index();
1364 }
1365 }
 
 
 
 
 
 
 
 
 
 
 
 
1366
1367 /*
1368 ** COMMAND: fts-config*
1369 **
1370 ** Usage: fossil fts-config ?SUBCOMMAND? ?ARGUMENT?
@@ -1443,16 +1459,11 @@
1443 /* destroy or rebuild the index, if requested */
1444 if( iAction>=1 ){
1445 search_drop_index();
1446 }
1447 if( iAction>=2 ){
1448 fossil_print("rebuilding the search index...");
1449 fflush(stdout);
1450 search_create_index();
1451 search_fill_index();
1452 search_update_index(search_restrict(SRCH_ALL));
1453 fossil_print(" done\n");
1454 }
1455
1456 /* Always show the status before ending */
1457 for(i=0; i<ArraySize(aSetng); i++){
1458 fossil_print("%-16s %s\n", aSetng[i].zName,
1459
--- src/search.c
+++ src/search.c
@@ -1136,28 +1136,32 @@
1136 ;
1137
1138 /*
1139 ** Create or drop the tables associated with a full-text index.
1140 */
1141 static int searchIdxExists = -1;
1142 void search_create_index(void){
1143 const char *zDb = db_name("repository");
1144 search_sql_setup(g.db);
1145 db_multi_exec(zFtsSchema/*works-like:"%w%w%w%w%w"*/,
1146 zDb, zDb, zDb, zDb, zDb);
1147 searchIdxExists = 1;
1148 }
1149 void search_drop_index(void){
1150 const char *zDb = db_name("repository");
1151 db_multi_exec(zFtsDrop/*works-like:"%w%w%w"*/, zDb, zDb, zDb);
1152 searchIdxExists = 0;
1153 }
1154
1155 /*
1156 ** Return true if the full-text search index exists
1157 */
1158 int search_index_exists(void){
1159 if( searchIdxExists<0 ){
1160 searchIdxExists = db_table_exists("repository","ftsdocs");
1161 }
1162 return searchIdxExists;
1163 }
1164
1165 /*
1166 ** Fill the FTSDOCS table with unindexed entries for everything
1167 ** in the repository. This uses INSERT OR IGNORE so entries already
@@ -1361,10 +1365,22 @@
1365 }
1366 if( srchFlags & SRCH_WIKI ){
1367 search_update_wiki_index();
1368 }
1369 }
1370
1371 /*
1372 ** Construct, prepopulate, and then update the full-text index.
1373 */
1374 void search_rebuild_index(void){
1375 fossil_print("rebuilding the search index...");
1376 fflush(stdout);
1377 search_create_index();
1378 search_fill_index();
1379 search_update_index(search_restrict(SRCH_ALL));
1380 fossil_print(" done\n");
1381 }
1382
1383 /*
1384 ** COMMAND: fts-config*
1385 **
1386 ** Usage: fossil fts-config ?SUBCOMMAND? ?ARGUMENT?
@@ -1443,16 +1459,11 @@
1459 /* destroy or rebuild the index, if requested */
1460 if( iAction>=1 ){
1461 search_drop_index();
1462 }
1463 if( iAction>=2 ){
1464 search_rebuild_index();
 
 
 
 
 
1465 }
1466
1467 /* Always show the status before ending */
1468 for(i=0; i<ArraySize(aSetng); i++){
1469 fossil_print("%-16s %s\n", aSetng[i].zName,
1470

Keyboard Shortcuts

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