Fossil SCM
Search improvements: Limit the number of search results to the value in the "search-limit" setting, or 100 results if the setting is omitted. And, show the date of each article if the date is not included as part of the title.
Commit
13dfcdd9576baa4656797db889401ae4ab8457fcc67750f99678c4d577fcc1bc
Parent
cc17add2653a195…
1 file changed
+12
-2
+12
-2
| --- src/search.c | ||
| +++ src/search.c | ||
| @@ -1031,11 +1031,15 @@ | ||
| 1031 | 1031 | unsigned int srchFlags, /* What to search over */ |
| 1032 | 1032 | int fDebug /* Extra debugging output */ |
| 1033 | 1033 | ){ |
| 1034 | 1034 | Stmt q; |
| 1035 | 1035 | int nRow = 0; |
| 1036 | + int nLimit = db_get_int("search-limit", 100); | |
| 1036 | 1037 | |
| 1038 | + if( P("searchlimit")!=0 ){ | |
| 1039 | + nLimit = atoi(P("searchlimit")); | |
| 1040 | + } | |
| 1037 | 1041 | srchFlags = search_restrict(srchFlags); |
| 1038 | 1042 | if( srchFlags==0 ) return 0; |
| 1039 | 1043 | search_sql_setup(g.db); |
| 1040 | 1044 | add_content_sql_commands(g.db); |
| 1041 | 1045 | db_multi_exec( |
| @@ -1045,26 +1049,32 @@ | ||
| 1045 | 1049 | search_fullscan(zPattern, srchFlags); /* Full-scan search */ |
| 1046 | 1050 | }else{ |
| 1047 | 1051 | search_update_index(srchFlags); /* Update the index, if necessary */ |
| 1048 | 1052 | search_indexed(zPattern, srchFlags); /* Indexed search */ |
| 1049 | 1053 | } |
| 1050 | - db_prepare(&q, "SELECT url, snip, label, score, id" | |
| 1054 | + db_prepare(&q, "SELECT url, snip, label, score, id, substr(date,1,10)" | |
| 1051 | 1055 | " FROM x" |
| 1052 | 1056 | " ORDER BY score DESC, date DESC;"); |
| 1053 | 1057 | while( db_step(&q)==SQLITE_ROW ){ |
| 1054 | 1058 | const char *zUrl = db_column_text(&q, 0); |
| 1055 | 1059 | const char *zSnippet = db_column_text(&q, 1); |
| 1056 | 1060 | const char *zLabel = db_column_text(&q, 2); |
| 1061 | + const char *zDate = db_column_text(&q, 5); | |
| 1057 | 1062 | if( nRow==0 ){ |
| 1058 | 1063 | @ <ol> |
| 1059 | 1064 | } |
| 1060 | 1065 | nRow++; |
| 1061 | 1066 | @ <li><p><a href='%R%s(zUrl)'>%h(zLabel)</a> |
| 1062 | 1067 | if( fDebug ){ |
| 1063 | 1068 | @ (%e(db_column_double(&q,3)), %s(db_column_text(&q,4)) |
| 1064 | 1069 | } |
| 1065 | - @ <br /><span class='snippet'>%z(cleanSnippet(zSnippet))</span></li> | |
| 1070 | + @ <br /><span class='snippet'>%z(cleanSnippet(zSnippet)) \ | |
| 1071 | + if( zDate && zDate[0] && strstr(zLabel,zDate)==0 ){ | |
| 1072 | + @ <small>(%h(zDate))</small> | |
| 1073 | + } | |
| 1074 | + @ </span></li> | |
| 1075 | + if( nLimit && nRow>=nLimit ) break; | |
| 1066 | 1076 | } |
| 1067 | 1077 | db_finalize(&q); |
| 1068 | 1078 | if( nRow ){ |
| 1069 | 1079 | @ </ol> |
| 1070 | 1080 | } |
| 1071 | 1081 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -1031,11 +1031,15 @@ | |
| 1031 | unsigned int srchFlags, /* What to search over */ |
| 1032 | int fDebug /* Extra debugging output */ |
| 1033 | ){ |
| 1034 | Stmt q; |
| 1035 | int nRow = 0; |
| 1036 | |
| 1037 | srchFlags = search_restrict(srchFlags); |
| 1038 | if( srchFlags==0 ) return 0; |
| 1039 | search_sql_setup(g.db); |
| 1040 | add_content_sql_commands(g.db); |
| 1041 | db_multi_exec( |
| @@ -1045,26 +1049,32 @@ | |
| 1045 | search_fullscan(zPattern, srchFlags); /* Full-scan search */ |
| 1046 | }else{ |
| 1047 | search_update_index(srchFlags); /* Update the index, if necessary */ |
| 1048 | search_indexed(zPattern, srchFlags); /* Indexed search */ |
| 1049 | } |
| 1050 | db_prepare(&q, "SELECT url, snip, label, score, id" |
| 1051 | " FROM x" |
| 1052 | " ORDER BY score DESC, date DESC;"); |
| 1053 | while( db_step(&q)==SQLITE_ROW ){ |
| 1054 | const char *zUrl = db_column_text(&q, 0); |
| 1055 | const char *zSnippet = db_column_text(&q, 1); |
| 1056 | const char *zLabel = db_column_text(&q, 2); |
| 1057 | if( nRow==0 ){ |
| 1058 | @ <ol> |
| 1059 | } |
| 1060 | nRow++; |
| 1061 | @ <li><p><a href='%R%s(zUrl)'>%h(zLabel)</a> |
| 1062 | if( fDebug ){ |
| 1063 | @ (%e(db_column_double(&q,3)), %s(db_column_text(&q,4)) |
| 1064 | } |
| 1065 | @ <br /><span class='snippet'>%z(cleanSnippet(zSnippet))</span></li> |
| 1066 | } |
| 1067 | db_finalize(&q); |
| 1068 | if( nRow ){ |
| 1069 | @ </ol> |
| 1070 | } |
| 1071 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -1031,11 +1031,15 @@ | |
| 1031 | unsigned int srchFlags, /* What to search over */ |
| 1032 | int fDebug /* Extra debugging output */ |
| 1033 | ){ |
| 1034 | Stmt q; |
| 1035 | int nRow = 0; |
| 1036 | int nLimit = db_get_int("search-limit", 100); |
| 1037 | |
| 1038 | if( P("searchlimit")!=0 ){ |
| 1039 | nLimit = atoi(P("searchlimit")); |
| 1040 | } |
| 1041 | srchFlags = search_restrict(srchFlags); |
| 1042 | if( srchFlags==0 ) return 0; |
| 1043 | search_sql_setup(g.db); |
| 1044 | add_content_sql_commands(g.db); |
| 1045 | db_multi_exec( |
| @@ -1045,26 +1049,32 @@ | |
| 1049 | search_fullscan(zPattern, srchFlags); /* Full-scan search */ |
| 1050 | }else{ |
| 1051 | search_update_index(srchFlags); /* Update the index, if necessary */ |
| 1052 | search_indexed(zPattern, srchFlags); /* Indexed search */ |
| 1053 | } |
| 1054 | db_prepare(&q, "SELECT url, snip, label, score, id, substr(date,1,10)" |
| 1055 | " FROM x" |
| 1056 | " ORDER BY score DESC, date DESC;"); |
| 1057 | while( db_step(&q)==SQLITE_ROW ){ |
| 1058 | const char *zUrl = db_column_text(&q, 0); |
| 1059 | const char *zSnippet = db_column_text(&q, 1); |
| 1060 | const char *zLabel = db_column_text(&q, 2); |
| 1061 | const char *zDate = db_column_text(&q, 5); |
| 1062 | if( nRow==0 ){ |
| 1063 | @ <ol> |
| 1064 | } |
| 1065 | nRow++; |
| 1066 | @ <li><p><a href='%R%s(zUrl)'>%h(zLabel)</a> |
| 1067 | if( fDebug ){ |
| 1068 | @ (%e(db_column_double(&q,3)), %s(db_column_text(&q,4)) |
| 1069 | } |
| 1070 | @ <br /><span class='snippet'>%z(cleanSnippet(zSnippet)) \ |
| 1071 | if( zDate && zDate[0] && strstr(zLabel,zDate)==0 ){ |
| 1072 | @ <small>(%h(zDate))</small> |
| 1073 | } |
| 1074 | @ </span></li> |
| 1075 | if( nLimit && nRow>=nLimit ) break; |
| 1076 | } |
| 1077 | db_finalize(&q); |
| 1078 | if( nRow ){ |
| 1079 | @ </ol> |
| 1080 | } |
| 1081 |