finamp icon indicating copy to clipboard operation
finamp copied to clipboard

Prioritize exact matches in search

Open Chaphasilor opened this issue 2 years ago • 7 comments

Currently, Finamp seems to use some sort of fuzzy search that matches substrings anywhere in the song title / item name.
However, the sorting of the matches seems to depend on the some other factor, probably the way the items are ordered in the DB.

What I would like to see is the following:

Search term: "red"

Matched item names (sorted):

  1. Red
  2. Red (Extended Mix)
  3. Paint It Red
  4. Redo
  5. United (RedMoon Remix)
  6. Infrared
  7. End Credits

Essentially:

  1. Exact and full matches at the beginning of the name
  2. Exact matches at the beginning of the name
  3. Exact matches anywhere else
  4. Matches where the first word starts with the search term
  5. Matches where any word starts with the search term
  6. Matches where the end of any word matches the search term
  7. Anything else (substring in the middle of a word)

This probably sounds more complicated than it is to implement. The only prerequisite would be that the current matching is kept instead of a true fuzzy search that matches individual characters instead of just whole substrings, but that is probably a given anyway.

Thanks :)

Chaphasilor avatar Jan 08 '23 16:01 Chaphasilor

Finamp seems to use some sort of fuzzy search that matches substrings anywhere in the song title / item name

For online mode, we just let Jellyfin handle it, for offline mode it's a very basic item.name.contains(search). We could make a better search system that is used by both online and offline.

jmshrv avatar Jan 08 '23 16:01 jmshrv

But does Jellyfin provide a real "ranking"? The search results are fine, just the order could be improved. But yeah, I guess an on-device strategy might be a good idea either way

Chaphasilor avatar Jan 08 '23 21:01 Chaphasilor

I don't think it does, it's the same endpoint, just with searchTerm specified as a query parameter. An on-device strategy would in theory be the best, although I'd be concerned about performance with large libraries as we'd have to pull the whole library down at once.

jmshrv avatar Feb 19 '23 01:02 jmshrv

On the client, this could likely be done with https://pub.dev/packages/fuzzywuzzy

jmshrv avatar Feb 19 '23 01:02 jmshrv

Fuzzy search over key-value pairs shouldn't be too slow I think, if you don't pull all the meta info but just the title, artist, and ID, that might work...

Chaphasilor avatar Feb 19 '23 10:02 Chaphasilor

I encounter this often and it is a bit annoying.

seniorm0ment avatar May 27 '23 16:05 seniorm0ment

I think we can do some "post-processing" on the client (both online and offline), that updates the sorting of the returned result. The amount of items is already limited in that case.
It won't help if the search results don't contain the searched item at all, but it's a start.

Chaphasilor avatar Jan 25 '24 19:01 Chaphasilor