diff options
author | Phil Jones <philj56@gmail.com> | 2023-04-17 23:43:05 +0100 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2023-04-17 23:43:05 +0100 |
commit | 574eff0df1aff9bdc6d32939a03312cc08803de3 (patch) | |
tree | 5aeca72f70314bee3bf95db99f10d89f0a7b4032 /src/string_vec.c | |
parent | 71a4801d20d8904cfcfa5e92c96d53ee06a2c69f (diff) |
Add --matching-algorithm option.
This replaces the --fuzzy-match algorithm. Available choices are normal,
prefix and fuzzy. Levenshtein distance was investigated, but it seems
pretty rubbish for tofi's use case, where you normally want a good match when
you've only typed a small portion of the target string.
Diffstat (limited to 'src/string_vec.c')
-rw-r--r-- | src/string_vec.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/string_vec.c b/src/string_vec.c index 039d191..7a8493f 100644 --- a/src/string_vec.c +++ b/src/string_vec.c @@ -5,8 +5,8 @@ #include <stdlib.h> #include <string.h> #include <sys/mman.h> -#include "fuzzy_match.h" #include "history.h" +#include "matching.h" #include "string_vec.h" #include "unicode.h" #include "xmalloc.h" @@ -181,7 +181,7 @@ struct scored_string_ref *string_ref_vec_find_sorted(struct string_ref_vec *rest struct string_ref_vec string_ref_vec_filter( const struct string_ref_vec *restrict vec, const char *restrict substr, - bool fuzzy) + enum matching_algorithm algorithm) { if (substr[0] == '\0') { return string_ref_vec_copy(vec); @@ -189,11 +189,7 @@ struct string_ref_vec string_ref_vec_filter( struct string_ref_vec filt = string_ref_vec_create(); for (size_t i = 0; i < vec->count; i++) { int32_t search_score; - if (fuzzy) { - search_score = fuzzy_match_words(substr, vec->buf[i].string); - } else { - search_score = fuzzy_match_simple_words(substr, vec->buf[i].string); - } + search_score = match_words(algorithm, substr, vec->buf[i].string); if (search_score != INT32_MIN) { string_ref_vec_add(&filt, vec->buf[i].string); filt.buf[filt.count - 1].search_score = search_score; |