Fossil SCM

Add possibility to only search forum subject lines

Torsten 2026-05-21 21:01 UTC trunk
Commit 8798a342444632b8748b978f0b12d7afae0c5028b94e91ff7c8909d26e9b896c
1 file changed +57 -14
+57 -14
--- src/search.c
+++ src/search.c
@@ -595,10 +595,11 @@
595595
** --docs Search embedded documentation
596596
** --forum Search forum posts
597597
** -h|--bi-help Search built-in help
598598
** --highlight N Used VT100 color N for matching text. 0 means "off".
599599
** -n|--limit N Limit output to N matches
600
+** --subject Restrict --forum search to subject lines only
600601
** --technotes Search tech notes
601602
** --tickets Search tickets
602603
** -W|--width WIDTH Set display width to WIDTH columns, 0 for
603604
** unlimited. Defaults to the terminal's width.
604605
** --wiki Search wiki
@@ -660,16 +661,17 @@
660661
if( find_option("all","a",0) ){ srchFlags |= SRCH_ALL; bFts = 1; }
661662
if( find_option("bi-help","h",0) ){ srchFlags |= SRCH_HELP; bFts = 1; }
662663
if( find_option("checkins","c",0) ){ srchFlags |= SRCH_CKIN; bFts = 1; }
663664
if( find_option("docs",0,0) ){ srchFlags |= SRCH_DOC; bFts = 1; }
664665
if( find_option("forum",0,0) ){ srchFlags |= SRCH_FORUM; bFts = 1; }
666
+ if( find_option("subject",0,0) ){ srchFlags |= SRCH_FORUM_SUBJ; }
665667
if( find_option("technotes",0,0) ){ srchFlags |= SRCH_TECHNOTE; bFts = 1; }
666668
if( find_option("tickets",0,0) ){ srchFlags |= SRCH_TKT; bFts = 1; }
667669
if( find_option("wiki",0,0) ){ srchFlags |= SRCH_WIKI; bFts = 1; }
668670
669671
/* If no search objects are specified, default to "check-in comments" */
670
- if( srchFlags==0 ) srchFlags = SRCH_CKIN;
672
+ if( (srchFlags & SRCH_ALL)==0 ) srchFlags = SRCH_CKIN;
671673
672674
if( srchFlags==SRCH_HELP ) bFlags = OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE;
673675
db_find_and_open_repository(bFlags, 0);
674676
verify_all_options();
675677
if( g.argc<3 ) return;
@@ -706,11 +708,17 @@
706708
);
707709
if( !search_index_exists() ){
708710
search_fullscan(zPattern, srchFlags); /* Full-scan search */
709711
}else{
710712
search_update_index(srchFlags); /* Update the index */
711
- search_indexed(zPattern, srchFlags); /* Indexed search */
713
+ if( srchFlags & SRCH_FORUM_SUBJ ){
714
+ unsigned int idxFlags = srchFlags & ~SRCH_FORUM & ~SRCH_FORUM_SUBJ;
715
+ if( idxFlags ) search_indexed(zPattern, idxFlags);
716
+ search_fullscan(zPattern, SRCH_FORUM | SRCH_FORUM_SUBJ);
717
+ }else{
718
+ search_indexed(zPattern, srchFlags); /* Indexed search */
719
+ }
712720
if( srchFlags & SRCH_HELP ){
713721
search_fullscan(zPattern, SRCH_HELP);
714722
}
715723
}
716724
db_prepare(&q, "SELECT snip, label, score, id, date"
@@ -788,10 +796,11 @@
788796
#define SRCH_WIKI 0x0008 /* Search over wiki */
789797
#define SRCH_TECHNOTE 0x0010 /* Search over tech notes */
790798
#define SRCH_FORUM 0x0020 /* Search over forum messages */
791799
#define SRCH_HELP 0x0040 /* Search built-in help (full-scan only) */
792800
#define SRCH_ALL 0x007f /* Search over everything */
801
+#define SRCH_FORUM_SUBJ 0x0080 /* Restrict forum search to subject lines only */
793802
#endif
794803
795804
/*
796805
** Remove bits from srchFlags which are disallowed by either the
797806
** current server configuration or by user permissions. Return
@@ -961,21 +970,41 @@
961970
" FROM technote"
962971
" WHERE search_match('',body('e',rid,NULL));"
963972
);
964973
}
965974
if( (srchFlags & SRCH_FORUM)!=0 ){
966
- db_multi_exec(
967
- "INSERT INTO x(label,url,score,id,date,snip)"
968
- " SELECT 'Forum '||comment,"
969
- " '/forumpost/'||uuid,"
970
- " search_score(),"
971
- " 'f'||rid,"
972
- " datetime(event.mtime),"
973
- " search_snippet()"
974
- " FROM event JOIN blob on event.objid=blob.rid"
975
- " WHERE search_match('',body('f',rid,NULL));"
976
- );
975
+ if( srchFlags & SRCH_FORUM_SUBJ ){
976
+ /* Search only forum subject lines. The subject is extracted from
977
+ ** event.comment which is stored as "TYPE: SUBJECT" for every forum
978
+ ** post (original, reply, edit, …). */
979
+ db_multi_exec(
980
+ "INSERT INTO x(label,url,score,id,date,snip)"
981
+ " SELECT 'Forum '||comment,"
982
+ " '/forumpost/'||uuid,"
983
+ " search_score(),"
984
+ " 'f'||rid,"
985
+ " datetime(event.mtime),"
986
+ " search_snippet()"
987
+ " FROM event JOIN blob ON event.objid=blob.rid"
988
+ " WHERE event.type='f'"
989
+ " AND search_match("
990
+ " substr(event.comment,instr(event.comment,':')+2),'');"
991
+ );
992
+ }else{
993
+ db_multi_exec(
994
+ "INSERT INTO x(label,url,score,id,date,snip)"
995
+ " SELECT 'Forum '||comment,"
996
+ " '/forumpost/'||uuid,"
997
+ " search_score(),"
998
+ " 'f'||rid,"
999
+ " datetime(event.mtime),"
1000
+ " search_snippet()"
1001
+ " FROM event JOIN blob ON event.objid=blob.rid"
1002
+ " WHERE event.type='f'"
1003
+ " AND search_match('',body('f',rid,NULL));"
1004
+ );
1005
+ }
9771006
}
9781007
if( (srchFlags & SRCH_HELP)!=0 ){
9791008
const char *zPrefix;
9801009
helptext_vtab_register(g.db);
9811010
if( srchFlags==SRCH_HELP ){
@@ -1251,11 +1280,19 @@
12511280
);
12521281
if( !search_index_exists() ){
12531282
search_fullscan(zPattern, srchFlags); /* Full-scan search */
12541283
}else{
12551284
search_update_index(srchFlags); /* Update the index, if necessary */
1256
- search_indexed(zPattern, srchFlags); /* Indexed search */
1285
+ if( srchFlags & SRCH_FORUM_SUBJ ){
1286
+ /* Forum subject search: exclude forum from the indexed search and
1287
+ ** instead use fullscan restricted to forum subject lines only. */
1288
+ unsigned int idxFlags = srchFlags & ~SRCH_FORUM & ~SRCH_FORUM_SUBJ;
1289
+ if( idxFlags ) search_indexed(zPattern, idxFlags);
1290
+ search_fullscan(zPattern, SRCH_FORUM | SRCH_FORUM_SUBJ);
1291
+ }else{
1292
+ search_indexed(zPattern, srchFlags); /* Indexed search */
1293
+ }
12571294
if( srchFlags & SRCH_HELP ){
12581295
search_fullscan(zPattern, SRCH_HELP);
12591296
}
12601297
}
12611298
db_prepare(&q, "SELECT url, snip, label, score, id, substr(date,1,10)"
@@ -1385,10 +1422,16 @@
13851422
}
13861423
if( fDebug ){
13871424
@ <input type="hidden" name="debug" value="1">
13881425
}
13891426
@ <input type="submit" value="Search%s(zType)"%s(zDisable2)>
1427
+ if( (srchThisTime & SRCH_FORUM)!=0 ){
1428
+ int bSubjOnly = PB("subj");
1429
+ @ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label><input type='checkbox' name='subj' value='1'%s(bSubjOnly?" checked":"")>
1430
+ @ search subject lines only</label>
1431
+ if( bSubjOnly ) srchThisTime |= SRCH_FORUM_SUBJ;
1432
+ }
13901433
if( srchAllowed==0 && srchThisTime==0 ){
13911434
@ <p class="generalError">Search is disabled</p>
13921435
}
13931436
@ </div></form>
13941437
while( fossil_isspace(zPattern[0]) ) zPattern++;
13951438
--- src/search.c
+++ src/search.c
@@ -595,10 +595,11 @@
595 ** --docs Search embedded documentation
596 ** --forum Search forum posts
597 ** -h|--bi-help Search built-in help
598 ** --highlight N Used VT100 color N for matching text. 0 means "off".
599 ** -n|--limit N Limit output to N matches
 
600 ** --technotes Search tech notes
601 ** --tickets Search tickets
602 ** -W|--width WIDTH Set display width to WIDTH columns, 0 for
603 ** unlimited. Defaults to the terminal's width.
604 ** --wiki Search wiki
@@ -660,16 +661,17 @@
660 if( find_option("all","a",0) ){ srchFlags |= SRCH_ALL; bFts = 1; }
661 if( find_option("bi-help","h",0) ){ srchFlags |= SRCH_HELP; bFts = 1; }
662 if( find_option("checkins","c",0) ){ srchFlags |= SRCH_CKIN; bFts = 1; }
663 if( find_option("docs",0,0) ){ srchFlags |= SRCH_DOC; bFts = 1; }
664 if( find_option("forum",0,0) ){ srchFlags |= SRCH_FORUM; bFts = 1; }
 
665 if( find_option("technotes",0,0) ){ srchFlags |= SRCH_TECHNOTE; bFts = 1; }
666 if( find_option("tickets",0,0) ){ srchFlags |= SRCH_TKT; bFts = 1; }
667 if( find_option("wiki",0,0) ){ srchFlags |= SRCH_WIKI; bFts = 1; }
668
669 /* If no search objects are specified, default to "check-in comments" */
670 if( srchFlags==0 ) srchFlags = SRCH_CKIN;
671
672 if( srchFlags==SRCH_HELP ) bFlags = OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE;
673 db_find_and_open_repository(bFlags, 0);
674 verify_all_options();
675 if( g.argc<3 ) return;
@@ -706,11 +708,17 @@
706 );
707 if( !search_index_exists() ){
708 search_fullscan(zPattern, srchFlags); /* Full-scan search */
709 }else{
710 search_update_index(srchFlags); /* Update the index */
711 search_indexed(zPattern, srchFlags); /* Indexed search */
 
 
 
 
 
 
712 if( srchFlags & SRCH_HELP ){
713 search_fullscan(zPattern, SRCH_HELP);
714 }
715 }
716 db_prepare(&q, "SELECT snip, label, score, id, date"
@@ -788,10 +796,11 @@
788 #define SRCH_WIKI 0x0008 /* Search over wiki */
789 #define SRCH_TECHNOTE 0x0010 /* Search over tech notes */
790 #define SRCH_FORUM 0x0020 /* Search over forum messages */
791 #define SRCH_HELP 0x0040 /* Search built-in help (full-scan only) */
792 #define SRCH_ALL 0x007f /* Search over everything */
 
793 #endif
794
795 /*
796 ** Remove bits from srchFlags which are disallowed by either the
797 ** current server configuration or by user permissions. Return
@@ -961,21 +970,41 @@
961 " FROM technote"
962 " WHERE search_match('',body('e',rid,NULL));"
963 );
964 }
965 if( (srchFlags & SRCH_FORUM)!=0 ){
966 db_multi_exec(
967 "INSERT INTO x(label,url,score,id,date,snip)"
968 " SELECT 'Forum '||comment,"
969 " '/forumpost/'||uuid,"
970 " search_score(),"
971 " 'f'||rid,"
972 " datetime(event.mtime),"
973 " search_snippet()"
974 " FROM event JOIN blob on event.objid=blob.rid"
975 " WHERE search_match('',body('f',rid,NULL));"
976 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
977 }
978 if( (srchFlags & SRCH_HELP)!=0 ){
979 const char *zPrefix;
980 helptext_vtab_register(g.db);
981 if( srchFlags==SRCH_HELP ){
@@ -1251,11 +1280,19 @@
1251 );
1252 if( !search_index_exists() ){
1253 search_fullscan(zPattern, srchFlags); /* Full-scan search */
1254 }else{
1255 search_update_index(srchFlags); /* Update the index, if necessary */
1256 search_indexed(zPattern, srchFlags); /* Indexed search */
 
 
 
 
 
 
 
 
1257 if( srchFlags & SRCH_HELP ){
1258 search_fullscan(zPattern, SRCH_HELP);
1259 }
1260 }
1261 db_prepare(&q, "SELECT url, snip, label, score, id, substr(date,1,10)"
@@ -1385,10 +1422,16 @@
1385 }
1386 if( fDebug ){
1387 @ <input type="hidden" name="debug" value="1">
1388 }
1389 @ <input type="submit" value="Search%s(zType)"%s(zDisable2)>
 
 
 
 
 
 
1390 if( srchAllowed==0 && srchThisTime==0 ){
1391 @ <p class="generalError">Search is disabled</p>
1392 }
1393 @ </div></form>
1394 while( fossil_isspace(zPattern[0]) ) zPattern++;
1395
--- src/search.c
+++ src/search.c
@@ -595,10 +595,11 @@
595 ** --docs Search embedded documentation
596 ** --forum Search forum posts
597 ** -h|--bi-help Search built-in help
598 ** --highlight N Used VT100 color N for matching text. 0 means "off".
599 ** -n|--limit N Limit output to N matches
600 ** --subject Restrict --forum search to subject lines only
601 ** --technotes Search tech notes
602 ** --tickets Search tickets
603 ** -W|--width WIDTH Set display width to WIDTH columns, 0 for
604 ** unlimited. Defaults to the terminal's width.
605 ** --wiki Search wiki
@@ -660,16 +661,17 @@
661 if( find_option("all","a",0) ){ srchFlags |= SRCH_ALL; bFts = 1; }
662 if( find_option("bi-help","h",0) ){ srchFlags |= SRCH_HELP; bFts = 1; }
663 if( find_option("checkins","c",0) ){ srchFlags |= SRCH_CKIN; bFts = 1; }
664 if( find_option("docs",0,0) ){ srchFlags |= SRCH_DOC; bFts = 1; }
665 if( find_option("forum",0,0) ){ srchFlags |= SRCH_FORUM; bFts = 1; }
666 if( find_option("subject",0,0) ){ srchFlags |= SRCH_FORUM_SUBJ; }
667 if( find_option("technotes",0,0) ){ srchFlags |= SRCH_TECHNOTE; bFts = 1; }
668 if( find_option("tickets",0,0) ){ srchFlags |= SRCH_TKT; bFts = 1; }
669 if( find_option("wiki",0,0) ){ srchFlags |= SRCH_WIKI; bFts = 1; }
670
671 /* If no search objects are specified, default to "check-in comments" */
672 if( (srchFlags & SRCH_ALL)==0 ) srchFlags = SRCH_CKIN;
673
674 if( srchFlags==SRCH_HELP ) bFlags = OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE;
675 db_find_and_open_repository(bFlags, 0);
676 verify_all_options();
677 if( g.argc<3 ) return;
@@ -706,11 +708,17 @@
708 );
709 if( !search_index_exists() ){
710 search_fullscan(zPattern, srchFlags); /* Full-scan search */
711 }else{
712 search_update_index(srchFlags); /* Update the index */
713 if( srchFlags & SRCH_FORUM_SUBJ ){
714 unsigned int idxFlags = srchFlags & ~SRCH_FORUM & ~SRCH_FORUM_SUBJ;
715 if( idxFlags ) search_indexed(zPattern, idxFlags);
716 search_fullscan(zPattern, SRCH_FORUM | SRCH_FORUM_SUBJ);
717 }else{
718 search_indexed(zPattern, srchFlags); /* Indexed search */
719 }
720 if( srchFlags & SRCH_HELP ){
721 search_fullscan(zPattern, SRCH_HELP);
722 }
723 }
724 db_prepare(&q, "SELECT snip, label, score, id, date"
@@ -788,10 +796,11 @@
796 #define SRCH_WIKI 0x0008 /* Search over wiki */
797 #define SRCH_TECHNOTE 0x0010 /* Search over tech notes */
798 #define SRCH_FORUM 0x0020 /* Search over forum messages */
799 #define SRCH_HELP 0x0040 /* Search built-in help (full-scan only) */
800 #define SRCH_ALL 0x007f /* Search over everything */
801 #define SRCH_FORUM_SUBJ 0x0080 /* Restrict forum search to subject lines only */
802 #endif
803
804 /*
805 ** Remove bits from srchFlags which are disallowed by either the
806 ** current server configuration or by user permissions. Return
@@ -961,21 +970,41 @@
970 " FROM technote"
971 " WHERE search_match('',body('e',rid,NULL));"
972 );
973 }
974 if( (srchFlags & SRCH_FORUM)!=0 ){
975 if( srchFlags & SRCH_FORUM_SUBJ ){
976 /* Search only forum subject lines. The subject is extracted from
977 ** event.comment which is stored as "TYPE: SUBJECT" for every forum
978 ** post (original, reply, edit, …). */
979 db_multi_exec(
980 "INSERT INTO x(label,url,score,id,date,snip)"
981 " SELECT 'Forum '||comment,"
982 " '/forumpost/'||uuid,"
983 " search_score(),"
984 " 'f'||rid,"
985 " datetime(event.mtime),"
986 " search_snippet()"
987 " FROM event JOIN blob ON event.objid=blob.rid"
988 " WHERE event.type='f'"
989 " AND search_match("
990 " substr(event.comment,instr(event.comment,':')+2),'');"
991 );
992 }else{
993 db_multi_exec(
994 "INSERT INTO x(label,url,score,id,date,snip)"
995 " SELECT 'Forum '||comment,"
996 " '/forumpost/'||uuid,"
997 " search_score(),"
998 " 'f'||rid,"
999 " datetime(event.mtime),"
1000 " search_snippet()"
1001 " FROM event JOIN blob ON event.objid=blob.rid"
1002 " WHERE event.type='f'"
1003 " AND search_match('',body('f',rid,NULL));"
1004 );
1005 }
1006 }
1007 if( (srchFlags & SRCH_HELP)!=0 ){
1008 const char *zPrefix;
1009 helptext_vtab_register(g.db);
1010 if( srchFlags==SRCH_HELP ){
@@ -1251,11 +1280,19 @@
1280 );
1281 if( !search_index_exists() ){
1282 search_fullscan(zPattern, srchFlags); /* Full-scan search */
1283 }else{
1284 search_update_index(srchFlags); /* Update the index, if necessary */
1285 if( srchFlags & SRCH_FORUM_SUBJ ){
1286 /* Forum subject search: exclude forum from the indexed search and
1287 ** instead use fullscan restricted to forum subject lines only. */
1288 unsigned int idxFlags = srchFlags & ~SRCH_FORUM & ~SRCH_FORUM_SUBJ;
1289 if( idxFlags ) search_indexed(zPattern, idxFlags);
1290 search_fullscan(zPattern, SRCH_FORUM | SRCH_FORUM_SUBJ);
1291 }else{
1292 search_indexed(zPattern, srchFlags); /* Indexed search */
1293 }
1294 if( srchFlags & SRCH_HELP ){
1295 search_fullscan(zPattern, SRCH_HELP);
1296 }
1297 }
1298 db_prepare(&q, "SELECT url, snip, label, score, id, substr(date,1,10)"
@@ -1385,10 +1422,16 @@
1422 }
1423 if( fDebug ){
1424 @ <input type="hidden" name="debug" value="1">
1425 }
1426 @ <input type="submit" value="Search%s(zType)"%s(zDisable2)>
1427 if( (srchThisTime & SRCH_FORUM)!=0 ){
1428 int bSubjOnly = PB("subj");
1429 @ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label><input type='checkbox' name='subj' value='1'%s(bSubjOnly?" checked":"")>
1430 @ search subject lines only</label>
1431 if( bSubjOnly ) srchThisTime |= SRCH_FORUM_SUBJ;
1432 }
1433 if( srchAllowed==0 && srchThisTime==0 ){
1434 @ <p class="generalError">Search is disabled</p>
1435 }
1436 @ </div></form>
1437 while( fossil_isspace(zPattern[0]) ) zPattern++;
1438

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button