From c57dcfe787a6cd73040e9b9a97f6701ebdbe1e3a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 12 Mar 2021 19:01:59 +0100 Subject: [PATCH] MINOR: cli: apply the fuzzy matching on the whole command instead of words Now instead of comparing words at an exact position, we build a fingerprint made of all of them, so that we can check for them in any position. For example, "show conn serv" finds "show servers conn" and that "set servers maxconn" proposes both "set server" and "set maxconn servers". --- src/cli.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cli.c b/src/cli.c index 8a6f827f7..6791ff2ae 100644 --- a/src/cli.c +++ b/src/cli.c @@ -168,13 +168,16 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args) /* this one matches, let's compute the distance between the two * on the remaining words */ + memset(word_sig, 0, sizeof(word_sig)); + memset(list_sig, 0, sizeof(list_sig)); + while (idx < CLI_PREFIX_KW_NB && kw->str_kw[idx] && args[idx] && *args[idx]) { - make_word_fingerprint(word_sig, args[idx]); - make_word_fingerprint(list_sig, kw->str_kw[idx]); + update_word_fingerprint(word_sig, args[idx]); + update_word_fingerprint(list_sig, kw->str_kw[idx]); totlen += strlen(args[idx]) + strlen(kw->str_kw[idx]); - dist += word_fingerprint_distance(word_sig, list_sig); idx++; } + dist = word_fingerprint_distance(word_sig, list_sig); /* insert this one at its place if relevant, in order to keep only * the best matches.