Open csaez opened 8 years ago
https://stackoverflow.com/questions/2891514/algorithms-for-fuzzy-matching-strings
the solution seems simple enough to implement in one function
Hi, Thanks for looking into this :)
I've used python's difflib in the past to get a ratio between matches making the fuzzy search an one-liner, the problem is more about me not having the time to go and implement this in a QCompleter changing the way it matches and sort the model/proxymodel under the hood.
import difflib
ratio = lambda x, y: difflib.SequenceMatcher(None, x, y).ratio()
# usage
keyword = 'baz'
alternatives = ('foo', 'bar', 'bat', 'spam')
print(sorted(alternatives, key=lambda x: ratio(x, keyword), reverse=True))
# ['bar', 'bat', 'spam', 'foo']
If you or anyone else reading this have the time and will to contribute sending a pull request addressing this issue I would gladly accept it, otherwise we will have to wait until I find the time to deal with it.
Cheers!
It would be nice to implement better search rules... maybe start by a simple contains and then move to some sort of fuzzy search algorithm (depends on overhead and availability, I would prefer not to push 3rd party dependencies to people wanting to use this).