Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzzy matching with levenshtein: take 2 #503

Closed
tgross35 opened this issue Dec 17, 2022 · 1 comment
Closed

Fuzzy matching with levenshtein: take 2 #503

tgross35 opened this issue Dec 17, 2022 · 1 comment

Comments

@tgross35
Copy link

#34 brought this up before, but was closed because search patterns are typically short, so there isn't much of a need. However, as some others have pointed out on the thread, it is definitely helpful when there are a small number of mistakes in a longer search

A way to do this is with a levenshtein algorithm that exits if a limit is exceeded. I maintain a small crate that provides this with try_levenshtein(a, b, limit) -> Option<u32>, which returns None if a specified limit is exceeded (crate link: https://docs.rs/stringmetrics/latest/stringmetrics/, but you could also just copy the implementation if you don't want the dependency).

Something basic like this would find the closest match within a percent difference of the query's length.

possible_matches.iter()
    .filter_map(|m| try_levenshtein(query, m, floor(0.3 * query.len())))
    .max()

I'm not sure how best this would fit into the current algorithm (or what exactly fzf currently does), but I'm happy to help & clarify anything needed

@tgross35
Copy link
Author

tgross35 commented Sep 8, 2023

Closing this in favor of my new nucleo issue

@tgross35 tgross35 closed this as completed Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant