| | @@ -106,10 +106,11 @@ |
| 106 | 106 | int iBonus = 0; |
| 107 | 107 | int i, j; |
| 108 | 108 | unsigned char seen[8]; |
| 109 | 109 | |
| 110 | 110 | memset(seen, 0, sizeof(seen)); |
| 111 | + if( zDoc==0 ) return score; |
| 111 | 112 | for(i=0; zDoc[i]; i++){ |
| 112 | 113 | char c = zDoc[i]; |
| 113 | 114 | if( isBoundary[c&0xff] ) continue; |
| 114 | 115 | for(j=0; j<p->nTerm; j++){ |
| 115 | 116 | int n = p->a[j].n; |
| | @@ -166,21 +167,23 @@ |
| 166 | 167 | |
| 167 | 168 | /* |
| 168 | 169 | ** Testing the search function. |
| 169 | 170 | ** |
| 170 | 171 | ** COMMAND: search* |
| 171 | | -** %fossil search [-all|-a] [-limit|-n #] pattern... |
| 172 | +** %fossil search [-all|-a] [-limit|-n #] [-width|-W #] pattern... |
| 172 | 173 | ** |
| 173 | 174 | ** Search for timeline entries matching all words |
| 174 | 175 | ** provided on the command line. Whole-word matches |
| 175 | 176 | ** scope more highly than partial matches. |
| 176 | 177 | ** |
| 177 | 178 | ** Outputs, by default, some top-N fraction of the |
| 178 | 179 | ** results. The -all option can be used to output |
| 179 | 180 | ** all matches, regardless of their search score. |
| 180 | | -** -limit can be used to limit the number of entries |
| 181 | | -** returned. |
| 181 | +** The -limit option can be used to limit the number |
| 182 | +** of entries returned. The -width option can be |
| 183 | +** used to set the output width used when printing |
| 184 | +** matches. |
| 182 | 185 | */ |
| 183 | 186 | void search_cmd(void){ |
| 184 | 187 | Search *p; |
| 185 | 188 | Blob pattern; |
| 186 | 189 | int i; |
| | @@ -189,12 +192,22 @@ |
| 189 | 192 | int iBest; |
| 190 | 193 | char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop |
| 191 | 194 | off the end of the |
| 192 | 195 | results. */ |
| 193 | 196 | char const * zLimit = find_option("limit","n",1); |
| 197 | + const char *zWidth = find_option("width","W",1); |
| 194 | 198 | int nLimit = zLimit ? atoi(zLimit) : -1000; /* Max number of matching |
| 195 | 199 | lines/entries to list */ |
| 200 | + int width; |
| 201 | + if( zWidth ){ |
| 202 | + width = atoi(zWidth); |
| 203 | + if( (width!=0) && (width<=20) ){ |
| 204 | + fossil_fatal("--width|-W value must be >20 or 0"); |
| 205 | + } |
| 206 | + }else{ |
| 207 | + width = 79; |
| 208 | + } |
| 196 | 209 | |
| 197 | 210 | db_must_be_within_tree(); |
| 198 | 211 | if( g.argc<2 ) return; |
| 199 | 212 | blob_init(&pattern, g.argv[2], -1); |
| 200 | 213 | for(i=3; i<g.argc; i++){ |
| | @@ -223,8 +236,8 @@ |
| 223 | 236 | blob_appendf(&sql,"AND x>%d ", iBest/3); |
| 224 | 237 | } |
| 225 | 238 | blob_append(&sql, "ORDER BY x DESC, date DESC ", -1); |
| 226 | 239 | db_prepare(&q, blob_str(&sql)); |
| 227 | 240 | blob_reset(&sql); |
| 228 | | - print_timeline(&q, nLimit, 79, 0); |
| 241 | + print_timeline(&q, nLimit, width, 0); |
| 229 | 242 | db_finalize(&q); |
| 230 | 243 | } |
| 231 | 244 | |