amjith / fuzzyfinder

Fuzzy Finder implemented in Python
BSD 3-Clause "New" or "Revised" License
370 stars 30 forks source link

Disable alpha numeric sorting on suggestions #10

Closed thornycrackers closed 6 years ago

thornycrackers commented 6 years ago

First off, this is an amazing library! Thanks so much for this. One thing I am finding is duplicating my code a bit though is if I run the following code

suggestions = fuzzyfinder('baa', ['zbaa', 'dbaa', 'abaa'])

The list(suggestions) code comes back as ['abaa', 'dbaa', 'zbaa']. When I'm passing my original list it's already sorted so I end up having to resort it again after I'm done. Is there anyway to disable this so that it gives the order that the list was presented in?

sudormrfbin commented 6 years ago

That's easy to implement. I'll start working on it. What do you say, @amjith ?

amjith commented 6 years ago

@thornycrackers This is a bit more subtle. We will have to reorder the list based on the best match. The best match is computed by choosing the smallest contiguous match, followed by where the match is found in the full string, followed by the alphanumeric sorting.

So even if we remove the alphanumeric sorting (or make it optional) that does not guarantee that the order will be preserved.

@gokulsoumya I do see value in making the alphanumeric sorting optional, so if you're interested in implementing it, I say go for it. Make it an optional argument with the default value set to preserve the current behavior.