Diff
Not logged in

Differences From Artifact [7506dc1f59]:

To Artifact [7d5382df31]:


966
967
968
969
970
971
972





























973
974
975
976
977
978
979
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







** Return true if the full-text search index exists
*/
int search_index_exists(void){
  static int fExists = -1;
  if( fExists<0 ) fExists = db_table_exists("repository","ftsdocs");
  return fExists;
}

/*
** Fill the FTSDOCS table with unindexed entries for everything
** in the repository.  This uses INSERT OR IGNORE so entries already
** in FTSDOCS are unchanged.
*/
void search_fill_index(void){
  if( !search_index_exists() ) return;
  search_sql_setup(g.db);
  db_multi_exec(
    "INSERT OR IGNORE INTO ftsdocs(type,rid,idxed)"
    "  SELECT 'c', objid, 0 FROM event WHERE type='ci';"
  );
  db_multi_exec(
    "WITH latest_wiki(rid,name,mtime) AS ("
    "  SELECT tagxref.rid, substr(tag.tagname,6), max(tagxref.mtime)"
    "    FROM tag, tagxref"
    "   WHERE tag.tagname GLOB 'wiki-*'"
    "     AND tagxref.tagid=tag.tagid"
    "     AND tagxref.value>0"
    "   GROUP BY 2"
    ") INSERT OR IGNORE INTO ftsdocs(type,rid,name,idxed)"
    "     SELECT 'w', rid, name, 0 FROM latest_wiki;"
  );
  db_multi_exec(
    "INSERT OR IGNORE INTO ftsdocs(type,rid,idxed)"
    "  SELECT 't', tkt_id, 0 FROM ticket;"
  );
}

/*
** The document described by cType,rid,zName is about to be added or
** updated.  If the document has already been indexed, then unindex it
** now while we still have access to the old content.  Add the document
** to the queue of documents that need to be indexed or reindexed.
*/
993
994
995
996
997
998
999
1000









1001
1002
1003
1004










1005

1006
1007
1008
1009
1010
1011
1012
1013
1014

















































1015
1016
1022
1023
1024
1025
1026
1027
1028

1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053









1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104







-
+
+
+
+
+
+
+
+
+




+
+
+
+
+
+
+
+
+
+

+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


}

/*
** COMMAND: test-fts
*/
void test_fts_cmd(void){
  char *zSubCmd;
  int n;
  int i, n;
  static const struct { int iCmd; const char *z; } aCmd[] = {
     { 1,  "create"    },
     { 2,  "drop"      },
     { 3,  "exists"    },
     { 4,  "fill"      },
     { 5,  "pending"   },
     { 6,  "all"       },
  };
  db_find_and_open_repository(0, 0);
  if( g.argc<3 ) usage("SUBCMD ...");
  zSubCmd = g.argv[2];
  n = (int)strlen(zSubCmd);
  for(i=0; i<ArraySize(aCmd); i++){
    if( fossil_strncmp(aCmd[i].z, zSubCmd, n)==0 ) break;
  }
  if( i>=ArraySize(aCmd) ){
    Blob all;
    blob_init(&all,0,0);
    for(i=0; i<ArraySize(aCmd); i++) blob_appendf(&all, " %s", aCmd[i].z);
    fossil_fatal("unknown \"%s\" - should be:%s", zSubCmd, blob_str(&all));
    return;
  }
  db_begin_transaction();
  switch( aCmd[i].iCmd ){
  if( fossil_strncmp(zSubCmd, "create", n)==0 ){
    search_create_index();
  }else if( fossil_strncmp(zSubCmd, "drop",n)==0 ){
    search_drop_index();
  }else if( fossil_strncmp(zSubCmd, "exists",n)==0 ){
    fossil_print("search_index_exists() = %d\n", search_index_exists());
  }else{
    fossil_fatal("unknown subcommand \"%s\"", zSubCmd);
  }
    case 1: {  assert( fossil_strncmp(zSubCmd, "create", n)==0 );
      search_create_index();
      break;
    }
    case 2: {  assert( fossil_strncmp(zSubCmd, "drop", n)==0 );
      search_drop_index();
      break;
    }
    case 3: {  assert( fossil_strncmp(zSubCmd, "exist", n)==0 );
      fossil_print("search_index_exists() = %d\n", search_index_exists());
      break;
    }
    case 4: {  assert( fossil_strncmp(zSubCmd, "fill", n)==0 );
      search_fill_index();
      break;
    }
    case 5: {  assert( fossil_strncmp(zSubCmd, "pending", n)==0 );
      Stmt q;
      if( !search_index_exists() ) break;
      db_prepare(&q, "SELECT id, type, rid, quote(name) FROM ftsdocs"
                     " WHERE NOT idxed");
      while( db_step(&q)==SQLITE_ROW ){
        fossil_print("%6d: %s %6d %s\n",
           db_column_int(&q, 0),
           db_column_text(&q, 1),
           db_column_int(&q, 2),
           db_column_text(&q, 3)
        );
      }
      db_finalize(&q);
      break;
    }
    case 6: {  assert( fossil_strncmp(zSubCmd, "all", n)==0 );
      Stmt q;
      if( !search_index_exists() ) break;
      db_prepare(&q, "SELECT id, type, rid, quote(name), idxed FROM ftsdocs");
      while( db_step(&q)==SQLITE_ROW ){
        fossil_print("%6d: %s %6d %s%s\n",
           db_column_int(&q, 0),
           db_column_text(&q, 1),
           db_column_int(&q, 2),
           db_column_text(&q, 3),
           db_column_int(&q, 4) ? "" : " (NOT INDEXED)"
        );
      }
      db_finalize(&q);
      break;
    }
  }
  db_end_transaction(0);
}