csaez / quicklauncher

A minimal Qt based menu to quickly find and execute Maya commands and user scripts.
72 stars 20 forks source link

Better match rules, fuzzy search? #12

Open csaez opened 8 years ago

csaez commented 8 years ago

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).

dshlai commented 8 years ago

https://stackoverflow.com/questions/2891514/algorithms-for-fuzzy-matching-strings

the solution seems simple enough to implement in one function

csaez commented 8 years ago

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!