| ︙ | | |
539
540
541
542
543
544
545
546
547
548
549
550
551
552
|
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
|
+
|
** Register the various SQL functions (defined above) needed to implement
** full-scan search.
*/
void search_sql_setup(sqlite3 *db){
static int once = 0;
static const int enc = SQLITE_UTF8|SQLITE_INNOCUOUS;
if( once++ ) return;
helptext_vtab_register(g.db);
sqlite3_create_function(db, "search_match", -1, enc, 0,
search_match_sqlfunc, 0, 0);
sqlite3_create_function(db, "search_score", 0, enc, 0,
search_score_sqlfunc, 0, 0);
sqlite3_create_function(db, "search_snippet", 0, enc, 0,
search_snippet_sqlfunc, 0, 0);
sqlite3_create_function(db, "search_init", -1, enc, 0,
|
| ︙ | | |
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
|
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
|
+
-
+
+
+
|
/* What to search for */
#define SRCH_CKIN 0x0001 /* Search over check-in comments */
#define SRCH_DOC 0x0002 /* Search over embedded documents */
#define SRCH_TKT 0x0004 /* Search over tickets */
#define SRCH_WIKI 0x0008 /* Search over wiki */
#define SRCH_TECHNOTE 0x0010 /* Search over tech notes */
#define SRCH_FORUM 0x0020 /* Search over forum messages */
#define SRCH_HELP 0x0040 /* Search over help pages */
#define SRCH_ALL 0x003f /* Search over everything */
#define SRCH_ALL 0x007f /* Search over everything */
#endif
/*
** Remove bits from srchFlags which are disallowed by either the
** current server configuration or by user permissions. Return
** the revised search flags mask.
*/
unsigned int search_restrict(unsigned int srchFlags){
static unsigned int knownGood = 0;
static unsigned int knownBad = 0;
static const struct { unsigned m; const char *zKey; } aSetng[] = {
{ SRCH_CKIN, "search-ci" },
{ SRCH_DOC, "search-doc" },
{ SRCH_TKT, "search-tkt" },
{ SRCH_WIKI, "search-wiki" },
{ SRCH_TECHNOTE, "search-technote" },
{ SRCH_FORUM, "search-forum" },
{ SRCH_HELP, "search-help" },
};
int i;
if( g.perm.Read==0 ) srchFlags &= ~(SRCH_CKIN|SRCH_DOC|SRCH_TECHNOTE);
if( g.perm.RdTkt==0 ) srchFlags &= ~(SRCH_TKT);
if( g.perm.RdWiki==0 ) srchFlags &= ~(SRCH_WIKI);
if( g.perm.RdForum==0) srchFlags &= ~(SRCH_FORUM);
/* No restrictions on SRCH_HELP. */
for(i=0; i<count(aSetng); i++){
unsigned int m = aSetng[i].m;
if( (srchFlags & m)==0 ) continue;
if( ((knownGood|knownBad) & m)!=0 ) continue;
if( db_get_boolean(aSetng[i].zKey,0) ){
knownGood |= m;
}else{
|
| ︙ | | |
822
823
824
825
826
827
828
829
830
831
832
833
834
835
|
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
|
+
+
+
+
+
+
+
+
+
+
+
+
+
|
" 'f'||rid,"
" datetime(event.mtime),"
" search_snippet()"
" FROM event JOIN blob on event.objid=blob.rid"
" WHERE search_match('',body('f',rid,NULL));"
);
}
if( (srchFlags & SRCH_HELP)!=0 ){
db_multi_exec(
"INSERT INTO x(label,url,score,id,date,snip)"
" SELECT name,"
" '/help?cmd='||name,"
" search_score(),"
" 'h'||rowid,"
" datetime(now()),"
" search_snippet()"
" FROM helptext"
" WHERE search_match(name,helptext);"
);
}
}
/*
** Number of significant bits in a u32
*/
static int nbits(u32 x){
int n = 0;
|
| ︙ | | |
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
|
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
|
+
-
+
|
const char *zPattern, /* The query pattern */
unsigned int srchFlags /* What to search over */
){
Blob sql;
char *zPat = mprintf("%s",zPattern);
int i;
static const char *zSnippetCall;
if( srchFlags&SRCH_HELP ) search_fullscan(zPattern, SRCH_HELP);
if( srchFlags==0 ) return;
if( (srchFlags&~(SRCH_HELP))==0 ) return;
sqlite3_create_function(g.db, "rank", 1, SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
search_rank_sqlfunc, 0, 0);
for(i=0; zPat[i]; i++){
if( (zPat[i]&0x80)==0 && !fossil_isalnum(zPat[i]) ) zPat[i] = ' ';
}
blob_init(&sql, 0, 0);
if( search_index_type(0)==4 ){
|
| ︙ | | |
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
|
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
|
+
|
switch( srchFlags ){
case SRCH_CKIN: zType = " Check-ins"; zClass = "Ckin"; break;
case SRCH_DOC: zType = " Docs"; zClass = "Doc"; break;
case SRCH_TKT: zType = " Tickets"; zClass = "Tkt"; break;
case SRCH_WIKI: zType = " Wiki"; zClass = "Wiki"; break;
case SRCH_TECHNOTE: zType = " Tech Notes"; zClass = "Note"; break;
case SRCH_FORUM: zType = " Forum"; zClass = "Frm"; break;
case SRCH_HELP: zType = " Help"; zClass = "Help"; break;
}
if( srchFlags==0 ){
if( mFlags & 0x02 ) return 0;
zDisable1 = " disabled";
zDisable2 = " disabled";
zPattern = "";
}else{
|
| ︙ | | |
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
|
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
|
+
|
{ "all", "All", SRCH_ALL },
{ "c", "Check-ins", SRCH_CKIN },
{ "d", "Docs", SRCH_DOC },
{ "t", "Tickets", SRCH_TKT },
{ "w", "Wiki", SRCH_WIKI },
{ "e", "Tech Notes", SRCH_TECHNOTE },
{ "f", "Forum", SRCH_FORUM },
{ "h", "Help", SRCH_HELP },
};
const char *zY = PD("y","all");
unsigned newFlags = srchFlags;
int i;
@ <select size='1' name='y'>
for(i=0; i<count(aY); i++){
if( (aY[i].m & srchFlags)==0 ) continue;
|
| ︙ | | |
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
|
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
|
+
+
+
+
+
+
+
+
+
+
+
+
+
|
db_bind_int(&q2, ":rid", rid);
while( db_step(&q2)==SQLITE_ROW ){
append_all_ticket_fields(pOut, &q2, -1);
}
db_reset(&q2);
}
break;
}
case 'h': { /* Help pages */
static Stmt q;
db_static_prepare(&q,
"SELECT name,helptext FROM helptext WHERE rowid=:x");
db_bind_int(&q, ":x", rid);
if( db_step(&q)==SQLITE_ROW ){
db_column_blob(&q, 0, pOut);
blob_append(pOut, "\n", 1);
db_column_blob(&q, 1, pOut);
}
db_reset(&q);
break;
}
}
}
/*
** This routine is a wrapper around search_stext().
**
|
| ︙ | | |
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
|
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
|
+
|
}
if( srchFlags & SRCH_TECHNOTE ){
search_update_technote_index();
}
if( srchFlags & SRCH_FORUM ){
search_update_forum_index();
}
/* SRCH_HELP does not use FTSDOCS. */
db_protect_pop();
}
/*
** Construct, prepopulate, and then update the full-text index.
*/
void search_rebuild_index(void){
|
| ︙ | | |
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
|
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
|
-
+
-
+
-
+
|
** of the repository. Subcommands:
**
** reindex Rebuild the search index. This is a no-op if
** index search is disabled
**
** index (on|off) Turn the search index on or off
**
** enable cdtwef Enable various kinds of search. c=Check-ins,
** enable cdtwefh Enable various kinds of search. c=Check-ins,
** d=Documents, t=Tickets, w=Wiki, e=Tech Notes,
** f=Forum.
** f=Forum, h=Help.
**
** disable cdtwef Disable various kinds of search
** disable cdtwefh Disable various kinds of search
**
** tokenizer VALUE Select a tokenizer for indexed search. VALUE
** may be one of (porter, on, off, trigram, unicode61),
** and "on" is equivalent to "porter". Unindexed
** search never uses tokenization or stemming.
**
** The current search settings are displayed after any changes are applied.
|
| ︙ | | |
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
|
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
|
+
|
} aSetng[] = {
{ "search-ci", "check-in search:", "c" },
{ "search-doc", "document search:", "d" },
{ "search-tkt", "ticket search:", "t" },
{ "search-wiki", "wiki search:", "w" },
{ "search-technote", "tech note search:", "e" },
{ "search-forum", "forum search:", "f" },
{ "search-help", "help search:", "h" },
};
char *zSubCmd = 0;
int i, j, n;
int iCmd = 0;
int iAction = 0;
db_find_and_open_repository(0, 0);
if( g.argc>2 ){
|
| ︙ | | |