Search result sort based on relevance rather than ID
Closed this issue ยท 3 comments
Found the /search
method returns results sorted based on ID. So sometimes the best match won't be at first index.
Here's a case: https://lrclib.net/api/search?q=One%20Love%20Blue . The best match with id 1787276
is at 11th position.
If I specify metadata like track_name
, artist_name
and album_name
it returns more matching lyrics.
But without album name (https://lrclib.net/api/search?track_name=One%20Love&artist_name=Blue), the best result is at 4th position.
Can it be sorted based on metadata matching?
It seems simply adding ORDER BY rank
to FTS5 query provides much better results.
When searching q=one+love+blue
:
Original query:
sqlite> SELECT * FROM tracks_fts WHERE tracks_fts MATCH 'one love blue' LIMIT 10;
one love|blue lines|massive attack
no one else could ever love you more than i do juno dreams remix|powers activate|candy apple blue feat nick bramlett
sorry seems to be the hardest word|one love|blue feat elton john
never release the one you love|inkpot attila|shocking blue
never release the one you love|attila|shocking blue
the one i love belongs to somebody else|feeling blue|paul desmond
dont set fire to the one i love|goodbye blue sky|godley creme
blue bayou|most beautiful love songs volume one|engelbert humperdinck
ballad medley my foolish heart my one and only love chelsea bridge in a sentimental mood|reflections in blue|art blakey the jazz messengers
sorry seems to be the hardest word|one love|blue
ORDER BY rank
query:
sqlite> SELECT * FROM tracks_fts WHERE tracks_fts MATCH 'one love blue' ORDER BY rank LIMIT 10;
one love|one love|blue
one love|one love|blue
one love|one love|blue
one love||blue
one love|ultimate blue|blue
one love|blue songs|blue
one love|best of blue|blue
flexin|one love|blue
invitation|one love|blue
privacy|one love|blue
When searching track_name=one+love&artist_name=blue
:
Original query:
sqlite> SELECT * FROM tracks_fts WHERE tracks_fts MATCH '(name_lower : one love) AND (artist_name_lower : blue)' LIMIT 10;
no one else could ever love you more than i do juno dreams remix|powers activate|candy apple blue feat nick bramlett
never release the one you love|inkpot attila|shocking blue
never release the one you love|attila|shocking blue
one love|one love|blue
one love|hit explosion vol 12 cd 2|blue
one love|now love now thats what i call love web|blue
one love|ultimate blue|blue
one love live a cappella|4ever blue|blue
one love live a cappella|4ever blue fans edition|blue
one love|now thats what i call music 53|blue
ORDER BY rank
query:
sqlite> SELECT * FROM tracks_fts WHERE tracks_fts MATCH '(name_lower : one love) AND (artist_name_lower : blue)' ORDER BY rank LIMIT 10;
one love||blue
one love|one love|blue
one love|one love|blue
one love|one love|blue
one love|mlm|blue
one love|bluevevo|blue
one love|ultimate blue|blue
one love|blue songs|blue
one love|the platinum collection|blue
one love|best of blue|blue
Applied the fix in commit 317986e
Now the results are sorted by relevancy, in the 2 cases below the 1787276
track is now first:
- https://lrclib.net/api/search?q=One%20Love%20Blue
- https://lrclib.net/api/search?track_name=One%20Love&artist_name=Blue
Adding ORDER BY rank
hurts the search API performance a bit though, but I think it is still acceptable.
If you can, please help me check other cases!
Yes, Now the first item in the search is more relevant to the query than before, I've searched for few more cases and this fix is really worked. Thanks for the improvement. You can close this issue as completed.