add fuse search utils

This commit is contained in:
jeffvli
2025-11-19 02:10:22 -08:00
parent ec135e30ed
commit 4fc346ac90
3 changed files with 158 additions and 22 deletions
-20
View File
@@ -1,20 +0,0 @@
import Fuse from 'fuse.js';
import { QueueSong } from '/@/shared/types/domain-types';
export const searchSongs = (songs: QueueSong[], searchTerm: string) => {
const fuse = new Fuse(songs, {
fieldNormWeight: 1,
ignoreLocation: true,
keys: [
'name',
'album',
{
getFn: (song) => song.artists.map((artist) => artist.name),
name: 'artist',
},
],
threshold: 0,
});
return fuse.search(searchTerm).map((item) => item.item);
};