From 574eff0df1aff9bdc6d32939a03312cc08803de3 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Mon, 17 Apr 2023 23:43:05 +0100 Subject: 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. --- src/string_vec.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/string_vec.c') 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 #include #include -#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; -- cgit v1.2.3