Explorar o código

fix: better algo for sorting geniURL results

Sv443 hai 1 ano
pai
achega
4d769bd00a
Modificáronse 1 ficheiros con 3 adicións e 5 borrados
  1. 3 5
      src/features/lyrics.ts

+ 3 - 5
src/features/lyrics.ts

@@ -426,15 +426,13 @@ export async function fetchLyricsUrls(artist: string, song: string): Promise<Omi
     fuzzyResults = (fuzzyResults as (typeof allResultsSan[0] & { score: number })[])
       .map(({ score, ...rest }) => rest as typeof allResultsSan[0]);
 
-    const hasExactMatch = exactishResults.slice(0, 3).includes(fuzzyResults[0]);
-
+    const hasExactMatch = exactishResults.slice(0, 3).find(r => exactish(r.meta.title) === exactish(fuzzyResults[0].meta.title) && exactish(r.meta.primaryArtist.name) === exactish(fuzzyResults[0].meta.primaryArtist.name));
     const finalResults = [
       ...(
         hasExactMatch
-          ? [fuzzyResults[0]]
-          : []
+          ? [fuzzyResults[0], ...allResultsSan.filter(r => r.url !== fuzzyResults[0].url)]
+          : [...allResultsSan]
       ),
-      ...fuzzyResults.slice(1),
     ].slice(0, 5);
 
     // add results to the cache with a penalty to their time to live