-
Notifications
You must be signed in to change notification settings - Fork 341
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
Add fuzzy match filter #92
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -109,3 +138,27 @@ func TestFilter(t *testing.T) { | |||
} | |||
} | |||
} | |||
|
|||
func TestFuzzy(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestFuzzyMatch is better to avoid conflict
} | ||
|
||
// FilterContains checks whether the completion.Text contains sub. | ||
func FilterContains(completions []Suggest, sub string, ignoreCase bool) []Suggest { | ||
func filterCommon(completions []Suggest, sub string, ignoreCase bool, test func(string, string) bool) []Suggest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think function
is better than test
, because filter
function in python3 also uses function
as the argument name.
https://docs.python.org/3.6/library/functions.html#filter
Suggested algorithm is quite simple. So it may replace with another algorithm in the future (refs #105) but I wanna merge this because it's better than nothing. |
I will merge this branch into master after fixing the name of variable and function that I commented. |
Merged into master branch. Thanks 👍 |
This completion filter is similar to fuzzy-finder search tools, which match as long as all search characters are present and in order. I find it a very effective method for rapidly searching.
I also factored out some repeated code that would otherwise appear in four functions. If you don't like that I can undo that part.