feat: 优化搜索功能,增强歌曲匹配逻辑
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
我们很高兴地宣布新项目 Any Listen 的桌面版已发布,目前已支持列表跟随本地文件自动更新、加载并播放WebDAV上的歌曲等功能,更多功能仍在积极开发中,桌面版与Web版将同步更新。
|
||||
对于有播放本地音乐或播放服务器上音乐需求的人可以试试,若遇到任何问题可以发 issue 反馈。
|
||||
|
||||
### 优化
|
||||
|
||||
- 优化歌单内歌曲搜索结果排序 (#2734)
|
||||
|
||||
### 修复
|
||||
|
||||
- 修复桌面歌词的 鼠标移入歌词区域时提高透明度 设置不稳定的问题(#2679, @Little100)
|
||||
|
||||
@@ -243,9 +243,24 @@ export const filterDuplicateMusic = async(list: LX.Music.MusicInfo[], isFilterVa
|
||||
}
|
||||
|
||||
export const searchListMusic = (list: LX.Music.MusicInfo[], text: string) => {
|
||||
const fullMathNameResults = new Set<LX.Music.MusicInfo>()
|
||||
const fullMathSingerResults = new Set<LX.Music.MusicInfo>()
|
||||
const fullMathAlbumResults = new Set<LX.Music.MusicInfo>()
|
||||
const textLower = text.toLowerCase()
|
||||
for (const mInfo of list) {
|
||||
if (mInfo.name?.toLowerCase().includes(textLower)) {
|
||||
fullMathNameResults.add(mInfo)
|
||||
} else if (mInfo.singer?.toLowerCase().includes(textLower)) {
|
||||
fullMathSingerResults.add(mInfo)
|
||||
} else if (mInfo.meta.albumName?.toLowerCase().includes(textLower)) {
|
||||
fullMathAlbumResults.add(mInfo)
|
||||
}
|
||||
}
|
||||
let result: LX.Music.MusicInfo[] = []
|
||||
let rxp = new RegExp(text.split('').map(s => s.replace(/[.*+?^${}()|[\]\\]/, '\\$&')).join('.*') + '.*', 'i')
|
||||
for (const mInfo of list) {
|
||||
if (fullMathNameResults.has(mInfo) || fullMathSingerResults.has(mInfo) || fullMathAlbumResults.has(mInfo)) continue
|
||||
|
||||
const str = `${mInfo.name}${mInfo.singer}${mInfo.meta.albumName ? mInfo.meta.albumName : ''}`
|
||||
if (rxp.test(str)) result.push(mInfo)
|
||||
}
|
||||
@@ -258,7 +273,12 @@ export const searchListMusic = (list: LX.Music.MusicInfo[], text: string) => {
|
||||
data: mInfo,
|
||||
})
|
||||
}
|
||||
return sortedList.map(item => item.data).reverse()
|
||||
return [
|
||||
...fullMathNameResults.values(),
|
||||
...fullMathSingerResults.values(),
|
||||
...fullMathAlbumResults.values(),
|
||||
...sortedList.map(item => item.data).reverse(),
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user