Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Restrict indexed search according to the search flags. Fix the generation of the index for wiki pages. Fix db_multi_exec() so that it aborts with a sensible message following a syntax error. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | indexed-fts |
| Files: | files | file ages | folders |
| SHA1: |
780117d2239e21d64d2010e366864cb7 |
| User & Date: | drh 2015-02-03 04:10:10.389 |
Context
|
2015-02-03
| ||
| 04:39 | Highlight matching works on a search using <mark> rather than <b> and add appropriate CSS to make "mark" look like "b" by default. check-in: c5a2832eeb user: drh tags: indexed-fts | |
| 04:10 | Restrict indexed search according to the search flags. Fix the generation of the index for wiki pages. Fix db_multi_exec() so that it aborts with a sensible message following a syntax error. check-in: 780117d223 user: drh tags: indexed-fts | |
| 03:29 | Populate the search index with check-ins, tickets, and wiki. check-in: 786a3632a8 user: drh tags: indexed-fts | |
Changes
Changes to src/db.c.
| ︙ | ︙ | |||
545 546 547 548 549 550 551 |
va_start(ap, zSql);
blob_vappendf(&sql, zSql, ap);
va_end(ap);
z = blob_str(&sql);
while( rc==SQLITE_OK && z[0] ){
pStmt = 0;
rc = sqlite3_prepare_v2(g.db, z, -1, &pStmt, &zEnd);
| | > | | 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
va_start(ap, zSql);
blob_vappendf(&sql, zSql, ap);
va_end(ap);
z = blob_str(&sql);
while( rc==SQLITE_OK && z[0] ){
pStmt = 0;
rc = sqlite3_prepare_v2(g.db, z, -1, &pStmt, &zEnd);
if( rc ){
db_err("%s: {%s}", sqlite3_errmsg(g.db), z);
}else if( pStmt ){
db.nPrepare++;
while( sqlite3_step(pStmt)==SQLITE_ROW ){}
rc = sqlite3_finalize(pStmt);
if( rc ) db_err("%s: {%.*s}", sqlite3_errmsg(g.db), (int)(zEnd-z), z);
}
z = zEnd;
}
|
| ︙ | ︙ |
Changes to src/search.c.
| ︙ | ︙ | |||
732 733 734 735 736 737 738 739 740 |
**
** The companion full-text scan routine is search_fullscan().
*/
static void search_indexed(
const char *zPattern, /* The query pattern */
unsigned int srchFlags /* What to search over */
){
sqlite3_create_function(g.db, "rank", 1, SQLITE_UTF8, 0,
search_rank_sqlfunc, 0, 0);
| > > > | > > > > > > > > > > > > > > > > > > | 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
**
** The companion full-text scan routine is search_fullscan().
*/
static void search_indexed(
const char *zPattern, /* The query pattern */
unsigned int srchFlags /* What to search over */
){
Blob sql;
if( srchFlags==0 ) return;
sqlite3_create_function(g.db, "rank", 1, SQLITE_UTF8, 0,
search_rank_sqlfunc, 0, 0);
blob_init(&sql, 0, 0);
blob_appendf(&sql,
"INSERT INTO x(label,url,score,date,snip) "
" SELECT ftsdocs.label,"
" ftsdocs.url,"
" rank(matchinfo(ftsidx,'pcsx')),"
" datetime(ftsdocs.mtime),"
" snippet(ftsidx)"
" FROM ftsidx, ftsdocs"
" WHERE ftsidx MATCH %Q"
" AND ftsdocs.rowid=ftsidx.docid",
zPattern
);
if( srchFlags!=SRCH_ALL ){
const char *zSep = " AND (";
static const struct { unsigned m; char c; } aMask[] = {
{ SRCH_CKIN, 'c' },
{ SRCH_DOC, 'd' },
{ SRCH_TKT, 't' },
{ SRCH_WIKI, 'w' },
};
int i;
for(i=0; i<ArraySize(aMask); i++){
if( srchFlags & aMask[i].m ){
blob_appendf(&sql, "%sftsdocs.type='%c'", zSep, aMask[i].c);
zSep = " OR ";
}
}
blob_append(&sql,")",1);
}
db_multi_exec("%s",blob_str(&sql)/*safe-for-%s*/);
#if SEARCH_DEBUG_RANK
db_multi_exec("UPDATE x SET label=printf('%%s (score=%%s)',label,score)");
#endif
}
/*
|
| ︙ | ︙ | |||
776 777 778 779 780 781 782 |
add_content_sql_commands(g.db);
db_multi_exec(
"CREATE TEMP TABLE x(label,url,score,date,snip);"
);
if( !search_index_exists() ){
search_fullscan(zPattern, srchFlags);
}else{
| | | 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
add_content_sql_commands(g.db);
db_multi_exec(
"CREATE TEMP TABLE x(label,url,score,date,snip);"
);
if( !search_index_exists() ){
search_fullscan(zPattern, srchFlags);
}else{
search_update_index(srchFlags);
search_indexed(zPattern, srchFlags);
}
db_prepare(&q, "SELECT url, snip, label"
" FROM x"
" ORDER BY score DESC, date DESC;");
while( db_step(&q)==SQLITE_ROW ){
const char *zUrl = db_column_text(&q, 0);
|
| ︙ | ︙ | |||
1219 1220 1221 1222 1223 1224 1225 |
/*
** Deal with all of the unindexed 'w' terms in FTSDOCS
*/
static void search_update_wiki_index(void){
db_multi_exec(
"INSERT INTO ftsidx(docid,stext)"
" SELECT rowid, stext('w',rid,NULL) FROM ftsdocs"
| | | | | > | | > > | > > | > | 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 |
/*
** Deal with all of the unindexed 'w' terms in FTSDOCS
*/
static void search_update_wiki_index(void){
db_multi_exec(
"INSERT INTO ftsidx(docid,stext)"
" SELECT rowid, stext('w',rid,NULL) FROM ftsdocs"
" WHERE type='w' AND NOT idxed;"
);
if( db_changes()==0 ) return;
db_multi_exec(
"REPLACE INTO ftsdocs(rowid,idxed,type,rid,name,label,url,mtime)"
" SELECT ftsdocs.rowid, 1, 'w', ftsdocs.rid, ftsdocs.name,"
" 'Wiki: '||ftsdocs.name,"
" '/wiki?name='||urlencode(ftsdocs.name),"
" tagxref.mtime"
" FROM ftsdocs, tagxref"
" WHERE ftsdocs.type='w' AND NOT ftsdocs.idxed"
" AND tagxref.rid=ftsdocs.rid"
);
}
/*
** Deal with all of the unindexed entries in the FTSDOCS table - that
** is to say, all the entries with FTSDOCS.IDXED=0. Add them to the
** index.
*/
void search_update_index(unsigned int srchFlags){
if( !search_index_exists() ) return;
if( !db_exists("SELECT 1 FROM ftsdocs WHERE NOT idxed") ) return;
search_sql_setup(g.db);
if( srchFlags & (SRCH_CKIN|SRCH_DOC) ){
search_update_doc_index();
search_update_checkin_index();
}
if( srchFlags & SRCH_TKT ){
search_update_ticket_index();
}
if( srchFlags & SRCH_WIKI ){
search_update_wiki_index();
}
}
/*
** COMMAND: test-fts
*/
void test_fts_cmd(void){
char *zSubCmd;
|
| ︙ | ︙ | |||
1319 1320 1321 1322 1323 1324 1325 |
db_column_text(&q, 3)
);
}
db_finalize(&q);
break;
}
case 7: { assert( fossil_strncmp(zSubCmd, "update", n)==0 );
| | | 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 |
db_column_text(&q, 3)
);
}
db_finalize(&q);
break;
}
case 7: { assert( fossil_strncmp(zSubCmd, "update", n)==0 );
search_update_index(SRCH_ALL);
break;
}
}
db_end_transaction(0);
}
|