Fossil SCM
Incremental check-in: added the "fossil test-fts fill" test command.
Commit
32d904e9cff95cf0e049d60f66a31bc84fb5c3e7
Parent
64e6a10013aee7d…
1 file changed
+97
-9
+97
-9
| --- src/search.c | ||
| +++ src/search.c | ||
| @@ -968,10 +968,39 @@ | ||
| 968 | 968 | int search_index_exists(void){ |
| 969 | 969 | static int fExists = -1; |
| 970 | 970 | if( fExists<0 ) fExists = db_table_exists("repository","ftsdocs"); |
| 971 | 971 | return fExists; |
| 972 | 972 | } |
| 973 | + | |
| 974 | +/* | |
| 975 | +** Fill the FTSDOCS table with unindexed entries for everything | |
| 976 | +** in the repository. This uses INSERT OR IGNORE so entries already | |
| 977 | +** in FTSDOCS are unchanged. | |
| 978 | +*/ | |
| 979 | +void search_fill_index(void){ | |
| 980 | + if( !search_index_exists() ) return; | |
| 981 | + search_sql_setup(g.db); | |
| 982 | + db_multi_exec( | |
| 983 | + "INSERT OR IGNORE INTO ftsdocs(type,rid,idxed)" | |
| 984 | + " SELECT 'c', objid, 0 FROM event WHERE type='ci';" | |
| 985 | + ); | |
| 986 | + db_multi_exec( | |
| 987 | + "WITH latest_wiki(rid,name,mtime) AS (" | |
| 988 | + " SELECT tagxref.rid, substr(tag.tagname,6), max(tagxref.mtime)" | |
| 989 | + " FROM tag, tagxref" | |
| 990 | + " WHERE tag.tagname GLOB 'wiki-*'" | |
| 991 | + " AND tagxref.tagid=tag.tagid" | |
| 992 | + " AND tagxref.value>0" | |
| 993 | + " GROUP BY 2" | |
| 994 | + ") INSERT OR IGNORE INTO ftsdocs(type,rid,name,idxed)" | |
| 995 | + " SELECT 'w', rid, name, 0 FROM latest_wiki;" | |
| 996 | + ); | |
| 997 | + db_multi_exec( | |
| 998 | + "INSERT OR IGNORE INTO ftsdocs(type,rid,idxed)" | |
| 999 | + " SELECT 't', tkt_id, 0 FROM ticket;" | |
| 1000 | + ); | |
| 1001 | +} | |
| 973 | 1002 | |
| 974 | 1003 | /* |
| 975 | 1004 | ** The document described by cType,rid,zName is about to be added or |
| 976 | 1005 | ** updated. If the document has already been indexed, then unindex it |
| 977 | 1006 | ** now while we still have access to the old content. Add the document |
| @@ -995,22 +1024,81 @@ | ||
| 995 | 1024 | /* |
| 996 | 1025 | ** COMMAND: test-fts |
| 997 | 1026 | */ |
| 998 | 1027 | void test_fts_cmd(void){ |
| 999 | 1028 | char *zSubCmd; |
| 1000 | - int n; | |
| 1029 | + int i, n; | |
| 1030 | + static const struct { int iCmd; const char *z; } aCmd[] = { | |
| 1031 | + { 1, "create" }, | |
| 1032 | + { 2, "drop" }, | |
| 1033 | + { 3, "exists" }, | |
| 1034 | + { 4, "fill" }, | |
| 1035 | + { 5, "pending" }, | |
| 1036 | + { 6, "all" }, | |
| 1037 | + }; | |
| 1001 | 1038 | db_find_and_open_repository(0, 0); |
| 1002 | 1039 | if( g.argc<3 ) usage("SUBCMD ..."); |
| 1003 | 1040 | zSubCmd = g.argv[2]; |
| 1004 | 1041 | n = (int)strlen(zSubCmd); |
| 1042 | + for(i=0; i<ArraySize(aCmd); i++){ | |
| 1043 | + if( fossil_strncmp(aCmd[i].z, zSubCmd, n)==0 ) break; | |
| 1044 | + } | |
| 1045 | + if( i>=ArraySize(aCmd) ){ | |
| 1046 | + Blob all; | |
| 1047 | + blob_init(&all,0,0); | |
| 1048 | + for(i=0; i<ArraySize(aCmd); i++) blob_appendf(&all, " %s", aCmd[i].z); | |
| 1049 | + fossil_fatal("unknown \"%s\" - should be:%s", zSubCmd, blob_str(&all)); | |
| 1050 | + return; | |
| 1051 | + } | |
| 1005 | 1052 | db_begin_transaction(); |
| 1006 | - if( fossil_strncmp(zSubCmd, "create", n)==0 ){ | |
| 1007 | - search_create_index(); | |
| 1008 | - }else if( fossil_strncmp(zSubCmd, "drop",n)==0 ){ | |
| 1009 | - search_drop_index(); | |
| 1010 | - }else if( fossil_strncmp(zSubCmd, "exists",n)==0 ){ | |
| 1011 | - fossil_print("search_index_exists() = %d\n", search_index_exists()); | |
| 1012 | - }else{ | |
| 1013 | - fossil_fatal("unknown subcommand \"%s\"", zSubCmd); | |
| 1053 | + switch( aCmd[i].iCmd ){ | |
| 1054 | + case 1: { assert( fossil_strncmp(zSubCmd, "create", n)==0 ); | |
| 1055 | + search_create_index(); | |
| 1056 | + break; | |
| 1057 | + } | |
| 1058 | + case 2: { assert( fossil_strncmp(zSubCmd, "drop", n)==0 ); | |
| 1059 | + search_drop_index(); | |
| 1060 | + break; | |
| 1061 | + } | |
| 1062 | + case 3: { assert( fossil_strncmp(zSubCmd, "exist", n)==0 ); | |
| 1063 | + fossil_print("search_index_exists() = %d\n", search_index_exists()); | |
| 1064 | + break; | |
| 1065 | + } | |
| 1066 | + case 4: { assert( fossil_strncmp(zSubCmd, "fill", n)==0 ); | |
| 1067 | + search_fill_index(); | |
| 1068 | + break; | |
| 1069 | + } | |
| 1070 | + case 5: { assert( fossil_strncmp(zSubCmd, "pending", n)==0 ); | |
| 1071 | + Stmt q; | |
| 1072 | + if( !search_index_exists() ) break; | |
| 1073 | + db_prepare(&q, "SELECT id, type, rid, quote(name) FROM ftsdocs" | |
| 1074 | + " WHERE NOT idxed"); | |
| 1075 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 1076 | + fossil_print("%6d: %s %6d %s\n", | |
| 1077 | + db_column_int(&q, 0), | |
| 1078 | + db_column_text(&q, 1), | |
| 1079 | + db_column_int(&q, 2), | |
| 1080 | + db_column_text(&q, 3) | |
| 1081 | + ); | |
| 1082 | + } | |
| 1083 | + db_finalize(&q); | |
| 1084 | + break; | |
| 1085 | + } | |
| 1086 | + case 6: { assert( fossil_strncmp(zSubCmd, "all", n)==0 ); | |
| 1087 | + Stmt q; | |
| 1088 | + if( !search_index_exists() ) break; | |
| 1089 | + db_prepare(&q, "SELECT id, type, rid, quote(name), idxed FROM ftsdocs"); | |
| 1090 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 1091 | + fossil_print("%6d: %s %6d %s%s\n", | |
| 1092 | + db_column_int(&q, 0), | |
| 1093 | + db_column_text(&q, 1), | |
| 1094 | + db_column_int(&q, 2), | |
| 1095 | + db_column_text(&q, 3), | |
| 1096 | + db_column_int(&q, 4) ? "" : " (NOT INDEXED)" | |
| 1097 | + ); | |
| 1098 | + } | |
| 1099 | + db_finalize(&q); | |
| 1100 | + break; | |
| 1101 | + } | |
| 1014 | 1102 | } |
| 1015 | 1103 | db_end_transaction(0); |
| 1016 | 1104 | } |
| 1017 | 1105 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -968,10 +968,39 @@ | |
| 968 | int search_index_exists(void){ |
| 969 | static int fExists = -1; |
| 970 | if( fExists<0 ) fExists = db_table_exists("repository","ftsdocs"); |
| 971 | return fExists; |
| 972 | } |
| 973 | |
| 974 | /* |
| 975 | ** The document described by cType,rid,zName is about to be added or |
| 976 | ** updated. If the document has already been indexed, then unindex it |
| 977 | ** now while we still have access to the old content. Add the document |
| @@ -995,22 +1024,81 @@ | |
| 995 | /* |
| 996 | ** COMMAND: test-fts |
| 997 | */ |
| 998 | void test_fts_cmd(void){ |
| 999 | char *zSubCmd; |
| 1000 | int n; |
| 1001 | db_find_and_open_repository(0, 0); |
| 1002 | if( g.argc<3 ) usage("SUBCMD ..."); |
| 1003 | zSubCmd = g.argv[2]; |
| 1004 | n = (int)strlen(zSubCmd); |
| 1005 | db_begin_transaction(); |
| 1006 | if( fossil_strncmp(zSubCmd, "create", n)==0 ){ |
| 1007 | search_create_index(); |
| 1008 | }else if( fossil_strncmp(zSubCmd, "drop",n)==0 ){ |
| 1009 | search_drop_index(); |
| 1010 | }else if( fossil_strncmp(zSubCmd, "exists",n)==0 ){ |
| 1011 | fossil_print("search_index_exists() = %d\n", search_index_exists()); |
| 1012 | }else{ |
| 1013 | fossil_fatal("unknown subcommand \"%s\"", zSubCmd); |
| 1014 | } |
| 1015 | db_end_transaction(0); |
| 1016 | } |
| 1017 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -968,10 +968,39 @@ | |
| 968 | int search_index_exists(void){ |
| 969 | static int fExists = -1; |
| 970 | if( fExists<0 ) fExists = db_table_exists("repository","ftsdocs"); |
| 971 | return fExists; |
| 972 | } |
| 973 | |
| 974 | /* |
| 975 | ** Fill the FTSDOCS table with unindexed entries for everything |
| 976 | ** in the repository. This uses INSERT OR IGNORE so entries already |
| 977 | ** in FTSDOCS are unchanged. |
| 978 | */ |
| 979 | void search_fill_index(void){ |
| 980 | if( !search_index_exists() ) return; |
| 981 | search_sql_setup(g.db); |
| 982 | db_multi_exec( |
| 983 | "INSERT OR IGNORE INTO ftsdocs(type,rid,idxed)" |
| 984 | " SELECT 'c', objid, 0 FROM event WHERE type='ci';" |
| 985 | ); |
| 986 | db_multi_exec( |
| 987 | "WITH latest_wiki(rid,name,mtime) AS (" |
| 988 | " SELECT tagxref.rid, substr(tag.tagname,6), max(tagxref.mtime)" |
| 989 | " FROM tag, tagxref" |
| 990 | " WHERE tag.tagname GLOB 'wiki-*'" |
| 991 | " AND tagxref.tagid=tag.tagid" |
| 992 | " AND tagxref.value>0" |
| 993 | " GROUP BY 2" |
| 994 | ") INSERT OR IGNORE INTO ftsdocs(type,rid,name,idxed)" |
| 995 | " SELECT 'w', rid, name, 0 FROM latest_wiki;" |
| 996 | ); |
| 997 | db_multi_exec( |
| 998 | "INSERT OR IGNORE INTO ftsdocs(type,rid,idxed)" |
| 999 | " SELECT 't', tkt_id, 0 FROM ticket;" |
| 1000 | ); |
| 1001 | } |
| 1002 | |
| 1003 | /* |
| 1004 | ** The document described by cType,rid,zName is about to be added or |
| 1005 | ** updated. If the document has already been indexed, then unindex it |
| 1006 | ** now while we still have access to the old content. Add the document |
| @@ -995,22 +1024,81 @@ | |
| 1024 | /* |
| 1025 | ** COMMAND: test-fts |
| 1026 | */ |
| 1027 | void test_fts_cmd(void){ |
| 1028 | char *zSubCmd; |
| 1029 | int i, n; |
| 1030 | static const struct { int iCmd; const char *z; } aCmd[] = { |
| 1031 | { 1, "create" }, |
| 1032 | { 2, "drop" }, |
| 1033 | { 3, "exists" }, |
| 1034 | { 4, "fill" }, |
| 1035 | { 5, "pending" }, |
| 1036 | { 6, "all" }, |
| 1037 | }; |
| 1038 | db_find_and_open_repository(0, 0); |
| 1039 | if( g.argc<3 ) usage("SUBCMD ..."); |
| 1040 | zSubCmd = g.argv[2]; |
| 1041 | n = (int)strlen(zSubCmd); |
| 1042 | for(i=0; i<ArraySize(aCmd); i++){ |
| 1043 | if( fossil_strncmp(aCmd[i].z, zSubCmd, n)==0 ) break; |
| 1044 | } |
| 1045 | if( i>=ArraySize(aCmd) ){ |
| 1046 | Blob all; |
| 1047 | blob_init(&all,0,0); |
| 1048 | for(i=0; i<ArraySize(aCmd); i++) blob_appendf(&all, " %s", aCmd[i].z); |
| 1049 | fossil_fatal("unknown \"%s\" - should be:%s", zSubCmd, blob_str(&all)); |
| 1050 | return; |
| 1051 | } |
| 1052 | db_begin_transaction(); |
| 1053 | switch( aCmd[i].iCmd ){ |
| 1054 | case 1: { assert( fossil_strncmp(zSubCmd, "create", n)==0 ); |
| 1055 | search_create_index(); |
| 1056 | break; |
| 1057 | } |
| 1058 | case 2: { assert( fossil_strncmp(zSubCmd, "drop", n)==0 ); |
| 1059 | search_drop_index(); |
| 1060 | break; |
| 1061 | } |
| 1062 | case 3: { assert( fossil_strncmp(zSubCmd, "exist", n)==0 ); |
| 1063 | fossil_print("search_index_exists() = %d\n", search_index_exists()); |
| 1064 | break; |
| 1065 | } |
| 1066 | case 4: { assert( fossil_strncmp(zSubCmd, "fill", n)==0 ); |
| 1067 | search_fill_index(); |
| 1068 | break; |
| 1069 | } |
| 1070 | case 5: { assert( fossil_strncmp(zSubCmd, "pending", n)==0 ); |
| 1071 | Stmt q; |
| 1072 | if( !search_index_exists() ) break; |
| 1073 | db_prepare(&q, "SELECT id, type, rid, quote(name) FROM ftsdocs" |
| 1074 | " WHERE NOT idxed"); |
| 1075 | while( db_step(&q)==SQLITE_ROW ){ |
| 1076 | fossil_print("%6d: %s %6d %s\n", |
| 1077 | db_column_int(&q, 0), |
| 1078 | db_column_text(&q, 1), |
| 1079 | db_column_int(&q, 2), |
| 1080 | db_column_text(&q, 3) |
| 1081 | ); |
| 1082 | } |
| 1083 | db_finalize(&q); |
| 1084 | break; |
| 1085 | } |
| 1086 | case 6: { assert( fossil_strncmp(zSubCmd, "all", n)==0 ); |
| 1087 | Stmt q; |
| 1088 | if( !search_index_exists() ) break; |
| 1089 | db_prepare(&q, "SELECT id, type, rid, quote(name), idxed FROM ftsdocs"); |
| 1090 | while( db_step(&q)==SQLITE_ROW ){ |
| 1091 | fossil_print("%6d: %s %6d %s%s\n", |
| 1092 | db_column_int(&q, 0), |
| 1093 | db_column_text(&q, 1), |
| 1094 | db_column_int(&q, 2), |
| 1095 | db_column_text(&q, 3), |
| 1096 | db_column_int(&q, 4) ? "" : " (NOT INDEXED)" |
| 1097 | ); |
| 1098 | } |
| 1099 | db_finalize(&q); |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
| 1103 | db_end_transaction(0); |
| 1104 | } |
| 1105 |