fix incorrect ordering of match results
acbf35a5
look for exact matches comparing the user input against the item text
1 file(s) · +3 −2
look for exact matches comparing the user input against the item text
| 208 | 208 | ||
| 209 | 209 | char buf[sizeof text], *s; |
|
| 210 | 210 | int i, tokc = 0; |
|
| 211 | - | size_t len; |
|
| 211 | + | size_t len, textsize; |
|
| 212 | 212 | struct item *item, *lprefix, *lsubstr, *prefixend, *substrend; |
|
| 213 | 213 | ||
| 214 | 214 | strcpy(buf, text); |
|
| 219 | 219 | len = tokc ? strlen(tokv[0]) : 0; |
|
| 220 | 220 | ||
| 221 | 221 | matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; |
|
| 222 | + | textsize = strlen(text) + 1; |
|
| 222 | 223 | for (item = items; item && item->text; item++) { |
|
| 223 | 224 | for (i = 0; i < tokc; i++) |
|
| 224 | 225 | if (!fstrstr(item->text, tokv[i])) |
|
| 226 | 227 | if (i != tokc) /* not all tokens match */ |
|
| 227 | 228 | continue; |
|
| 228 | 229 | /* exact matches go first, then prefixes, then substrings */ |
|
| 229 | - | if (!tokc || !fstrncmp(tokv[0], item->text, len + 1)) |
|
| 230 | + | if (!tokc || !fstrncmp(text, item->text, textsize)) |
|
| 230 | 231 | appenditem(item, &matches, &matchend); |
|
| 231 | 232 | else if (!fstrncmp(tokv[0], item->text, len)) |
|
| 232 | 233 | appenditem(item, &lprefix, &prefixend); |
|