Fossil SCM
Expanded "search" command flags: (-limit|-n #) limits the number of results and (-all|-a) disables the "lopping off" of the bottom fraction of the results.
Commit
1064dfac1221b19d1c0e29a1ad3615f7c75e153a
Parent
8adf0db1c8aa3ac…
1 file changed
+29
-7
+29
-7
| --- src/search.c | ||
| +++ src/search.c | ||
| @@ -166,20 +166,35 @@ | ||
| 166 | 166 | |
| 167 | 167 | /* |
| 168 | 168 | ** Testing the search function. |
| 169 | 169 | ** |
| 170 | 170 | ** COMMAND: search* |
| 171 | -** %fossil search pattern... | |
| 171 | +** %fossil search [-all|-a] [-limit|-n #] pattern... | |
| 172 | +** | |
| 173 | +** Search for timeline entries matching all words | |
| 174 | +** provided on the command line. Whole-word matches | |
| 175 | +** scope more highly than partial matches. | |
| 172 | 176 | ** |
| 173 | -** Search for timeline entries matching the pattern. | |
| 177 | +** Outputs, by default, some top-N fraction of the | |
| 178 | +** results. The -all option can be used to output | |
| 179 | +** all matches, regardless of their search score. | |
| 180 | +** -limit can be used to limit the number of entries | |
| 181 | +** returned. | |
| 174 | 182 | */ |
| 175 | 183 | void search_cmd(void){ |
| 176 | 184 | Search *p; |
| 177 | 185 | Blob pattern; |
| 178 | 186 | int i; |
| 187 | + Blob sql = empty_blob; | |
| 179 | 188 | Stmt q; |
| 180 | 189 | int iBest; |
| 190 | + char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop | |
| 191 | + off the end of the | |
| 192 | + results. */ | |
| 193 | + char const * zLimit = find_option("limit","n",1); | |
| 194 | + int const nLimit = zLimit ? atoi(zLimit) : -1; /* Max number of entries | |
| 195 | + to list */ | |
| 181 | 196 | |
| 182 | 197 | db_must_be_within_tree(); |
| 183 | 198 | if( g.argc<2 ) return; |
| 184 | 199 | blob_init(&pattern, g.argv[2], -1); |
| 185 | 200 | for(i=3; i<g.argc; i++){ |
| @@ -198,13 +213,20 @@ | ||
| 198 | 213 | " score(coalesce(ecomment,comment)) AS y" |
| 199 | 214 | " FROM event, blob" |
| 200 | 215 | " WHERE blob.rid=event.objid AND y>0;" |
| 201 | 216 | ); |
| 202 | 217 | iBest = db_int(0, "SELECT max(x) FROM srch"); |
| 203 | - db_prepare(&q, | |
| 204 | - "SELECT rid, uuid, date, comment, 0, 0 FROM srch" | |
| 205 | - " WHERE x>%d ORDER BY x DESC, date DESC", | |
| 206 | - iBest/3 | |
| 207 | - ); | |
| 218 | + blob_append(&sql, | |
| 219 | + "SELECT rid, uuid, date, comment, 0, 0 FROM srch " | |
| 220 | + "WHERE 1 ", -1); | |
| 221 | + if(!fAll){ | |
| 222 | + blob_appendf(&sql,"AND x>%d ", iBest/3); | |
| 223 | + } | |
| 224 | + blob_append(&sql, "ORDER BY x DESC, date DESC ", -1); | |
| 225 | + if(nLimit>0){ | |
| 226 | + blob_appendf(&sql, "LIMIT %d", nLimit); | |
| 227 | + } | |
| 228 | + db_prepare(&q, blob_str(&sql)); | |
| 229 | + blob_reset(&sql); | |
| 208 | 230 | print_timeline(&q, 1000, 0); |
| 209 | 231 | db_finalize(&q); |
| 210 | 232 | } |
| 211 | 233 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -166,20 +166,35 @@ | |
| 166 | |
| 167 | /* |
| 168 | ** Testing the search function. |
| 169 | ** |
| 170 | ** COMMAND: search* |
| 171 | ** %fossil search pattern... |
| 172 | ** |
| 173 | ** Search for timeline entries matching the pattern. |
| 174 | */ |
| 175 | void search_cmd(void){ |
| 176 | Search *p; |
| 177 | Blob pattern; |
| 178 | int i; |
| 179 | Stmt q; |
| 180 | int iBest; |
| 181 | |
| 182 | db_must_be_within_tree(); |
| 183 | if( g.argc<2 ) return; |
| 184 | blob_init(&pattern, g.argv[2], -1); |
| 185 | for(i=3; i<g.argc; i++){ |
| @@ -198,13 +213,20 @@ | |
| 198 | " score(coalesce(ecomment,comment)) AS y" |
| 199 | " FROM event, blob" |
| 200 | " WHERE blob.rid=event.objid AND y>0;" |
| 201 | ); |
| 202 | iBest = db_int(0, "SELECT max(x) FROM srch"); |
| 203 | db_prepare(&q, |
| 204 | "SELECT rid, uuid, date, comment, 0, 0 FROM srch" |
| 205 | " WHERE x>%d ORDER BY x DESC, date DESC", |
| 206 | iBest/3 |
| 207 | ); |
| 208 | print_timeline(&q, 1000, 0); |
| 209 | db_finalize(&q); |
| 210 | } |
| 211 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -166,20 +166,35 @@ | |
| 166 | |
| 167 | /* |
| 168 | ** Testing the search function. |
| 169 | ** |
| 170 | ** COMMAND: search* |
| 171 | ** %fossil search [-all|-a] [-limit|-n #] pattern... |
| 172 | ** |
| 173 | ** Search for timeline entries matching all words |
| 174 | ** provided on the command line. Whole-word matches |
| 175 | ** scope more highly than partial matches. |
| 176 | ** |
| 177 | ** Outputs, by default, some top-N fraction of the |
| 178 | ** results. The -all option can be used to output |
| 179 | ** all matches, regardless of their search score. |
| 180 | ** -limit can be used to limit the number of entries |
| 181 | ** returned. |
| 182 | */ |
| 183 | void search_cmd(void){ |
| 184 | Search *p; |
| 185 | Blob pattern; |
| 186 | int i; |
| 187 | Blob sql = empty_blob; |
| 188 | Stmt q; |
| 189 | int iBest; |
| 190 | char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop |
| 191 | off the end of the |
| 192 | results. */ |
| 193 | char const * zLimit = find_option("limit","n",1); |
| 194 | int const nLimit = zLimit ? atoi(zLimit) : -1; /* Max number of entries |
| 195 | to list */ |
| 196 | |
| 197 | db_must_be_within_tree(); |
| 198 | if( g.argc<2 ) return; |
| 199 | blob_init(&pattern, g.argv[2], -1); |
| 200 | for(i=3; i<g.argc; i++){ |
| @@ -198,13 +213,20 @@ | |
| 213 | " score(coalesce(ecomment,comment)) AS y" |
| 214 | " FROM event, blob" |
| 215 | " WHERE blob.rid=event.objid AND y>0;" |
| 216 | ); |
| 217 | iBest = db_int(0, "SELECT max(x) FROM srch"); |
| 218 | blob_append(&sql, |
| 219 | "SELECT rid, uuid, date, comment, 0, 0 FROM srch " |
| 220 | "WHERE 1 ", -1); |
| 221 | if(!fAll){ |
| 222 | blob_appendf(&sql,"AND x>%d ", iBest/3); |
| 223 | } |
| 224 | blob_append(&sql, "ORDER BY x DESC, date DESC ", -1); |
| 225 | if(nLimit>0){ |
| 226 | blob_appendf(&sql, "LIMIT %d", nLimit); |
| 227 | } |
| 228 | db_prepare(&q, blob_str(&sql)); |
| 229 | blob_reset(&sql); |
| 230 | print_timeline(&q, 1000, 0); |
| 231 | db_finalize(&q); |
| 232 | } |
| 233 |