timusus / Shuttle

Shuttle Music Player
Other
2.2k stars 478 forks source link

Highlight matching string in fuzzy search #166

Open timusus opened 7 years ago

timusus commented 7 years ago

Shuttle version:

v2.0.0-beta

Device, OS:

Any

Description of bug:

Currently, when performing a fuzzy search, the matching substring is only highlighted in certain situations. For example:

rfazi commented 7 years ago

Is possible to implement this library? https://github.com/xdrop/fuzzywuzzy Use the score to get an ordered fuzzy list.

timusus commented 7 years ago

A fuzzy search algorithm is already being used in the app, there's no need for a third party library.

You can see the code here: https://github.com/timusus/Shuttle/blob/dev/app/src/main/java/com/simplecity/amp_library/utils/StringUtils.java#L245

It's using the Jaro-Winkler distance algorithm to detect how similar two strings are. There are some adjustments made to ignore whitespace, and sort closer-matches to the top.

What's required here is some refactoring so the getAdjustedJaroWinklerSimilarity() method returns the score, as well as the string sequence for the match, so we can then highlight that sequence in the search results. I haven't really looked into this in depth, but it shouldn't be too difficult.