971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
|
971
972
973
974
975
976
977
978
979
980
981
982
983
984
|
-
|
int search_run_and_output(
const char *zPattern, /* The query pattern */
unsigned int srchFlags, /* What to search over */
int fDebug /* Extra debugging output */
){
Stmt q;
int nRow = 0;
const char *zDocBr = 0; /* The branch of documentation to search */
srchFlags = search_restrict(srchFlags);
if( srchFlags==0 ) return 0;
search_sql_setup(g.db);
add_content_sql_commands(g.db);
db_multi_exec(
"CREATE TEMP TABLE x(label,url,score,id,date,snip);"
|
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
|
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
|
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
|
db_prepare(&q, "SELECT url, snip, label, score, id"
" FROM x"
" ORDER BY score DESC, date DESC;");
while( db_step(&q)==SQLITE_ROW ){
const char *zUrl = db_column_text(&q, 0);
const char *zSnippet = db_column_text(&q, 1);
const char *zLabel = db_column_text(&q, 2);
const char *zId = db_column_text(&q,4);
if( nRow==0 ){
@ <ol>
}
nRow++;
if( strncmp(zUrl,"/doc/",5)==0 ){
/* Change the BRANCH in URLs like "/doc/BRANCH/path" into the
** branch name specified by the doc-branch setting. */
int i;
if( zDocBr==0 ) zDocBr = db_get("doc-branch","trunk");
for(i=5; zUrl[i]; i++) if( zUrl[i]=='/' ){ i++; break; }
@ <li><p><a href='%R/doc/%T(zDocBr)/%T(zUrl+i)'>%h(zLabel)</a>
}else{
/* Non-"/doc/" URLs are delivered as is */
@ <li><p><a href='%R%T(zUrl)'>%h(zLabel)</a>
@ <li><p><a href='%R%T(zUrl)'>%h(zLabel)</a>
}
if( fDebug ){
@ (%e(db_column_double(&q,3)), %s(zId))
@ (%e(db_column_double(&q,3)), %s(db_column_text(&q,4))
}
@ <br /><span class='snippet'>%z(cleanSnippet(zSnippet))</span></li>
}
db_finalize(&q);
if( nRow ){
@ </ol>
}
|
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
|
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
|
-
-
|
** check-ins, then update all 'd' entries in FTSDOCS that have
** changed.
*/
static void search_update_doc_index(void){
const char *zDocBr = db_get("doc-branch","trunk");
int ckid = zDocBr ? symbolic_name_to_rid(zDocBr,"ci") : 0;
double rTime;
char *zBrUuid;
if( ckid==0 ) return;
if( !db_exists("SELECT 1 FROM ftsdocs WHERE type='c' AND rid=%d"
" AND NOT idxed", ckid) ) return;
/* If we get this far, it means that changes to 'd' entries are
** required. */
rTime = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", ckid);
zBrUuid = db_text("","SELECT substr(uuid,1,20) FROM blob WHERE rid=%d",ckid);
db_multi_exec(
"CREATE TEMP TABLE current_docs(rid INTEGER PRIMARY KEY, name);"
"CREATE VIRTUAL TABLE IF NOT EXISTS temp.foci USING files_of_checkin;"
"INSERT OR IGNORE INTO current_docs(rid, name)"
" SELECT blob.rid, foci.filename FROM foci, blob"
" WHERE foci.checkinID=%d AND blob.uuid=foci.uuid"
" AND %z",
|
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
|
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
|
-
+
-
+
|
" AND rid NOT IN (SELECT rid FROM current_docs)"
);
db_multi_exec(
"INSERT OR IGNORE INTO ftsdocs(type,rid,name,idxed,label,bx,url,mtime)"
" SELECT 'd', rid, name, 0,"
" title('d',rid,name),"
" body('d',rid,name),"
" printf('/doc/%q/%%s',urlencode(name)),"
" printf('/doc/%T/%%s',urlencode(name)),"
" %.17g"
" FROM current_docs",
zBrUuid, rTime
zDocBr, rTime
);
db_multi_exec(
"INSERT INTO ftsidx(docid,title,body)"
" SELECT rowid, label, bx FROM ftsdocs WHERE type='d' AND NOT idxed"
);
db_multi_exec(
"UPDATE ftsdocs SET"
|