Skip to content

Commit 61231ab

Browse files
committed
feat: 优化搜索功能,增强歌曲匹配逻辑
1 parent ae2ee0e commit 61231ab

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

publish/changeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
我们很高兴地宣布新项目 Any Listen 的桌面版已发布,目前已支持列表跟随本地文件自动更新、加载并播放WebDAV上的歌曲等功能,更多功能仍在积极开发中,桌面版与Web版将同步更新。
22
对于有播放本地音乐或播放服务器上音乐需求的人可以试试,若遇到任何问题可以发 issue 反馈。
33

4+
### 优化
5+
6+
- 优化歌单内歌曲搜索结果排序 (#2734)
7+
48
### 修复
59

610
- 修复桌面歌词的 鼠标移入歌词区域时提高透明度 设置不稳定的问题(#2679, @Little100

src/renderer/worker/main/list.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,24 @@ export const filterDuplicateMusic = async(list: LX.Music.MusicInfo[], isFilterVa
243243
}
244244

245245
export const searchListMusic = (list: LX.Music.MusicInfo[], text: string) => {
246+
const fullMathNameResults = new Set<LX.Music.MusicInfo>()
247+
const fullMathSingerResults = new Set<LX.Music.MusicInfo>()
248+
const fullMathAlbumResults = new Set<LX.Music.MusicInfo>()
249+
const textLower = text.toLowerCase()
250+
for (const mInfo of list) {
251+
if (mInfo.name?.toLowerCase().includes(textLower)) {
252+
fullMathNameResults.add(mInfo)
253+
} else if (mInfo.singer?.toLowerCase().includes(textLower)) {
254+
fullMathSingerResults.add(mInfo)
255+
} else if (mInfo.meta.albumName?.toLowerCase().includes(textLower)) {
256+
fullMathAlbumResults.add(mInfo)
257+
}
258+
}
246259
let result: LX.Music.MusicInfo[] = []
247260
let rxp = new RegExp(text.split('').map(s => s.replace(/[.*+?^${}()|[\]\\]/, '\\$&')).join('.*') + '.*', 'i')
248261
for (const mInfo of list) {
262+
if (fullMathNameResults.has(mInfo) || fullMathSingerResults.has(mInfo) || fullMathAlbumResults.has(mInfo)) continue
263+
249264
const str = `${mInfo.name}${mInfo.singer}${mInfo.meta.albumName ? mInfo.meta.albumName : ''}`
250265
if (rxp.test(str)) result.push(mInfo)
251266
}
@@ -258,7 +273,12 @@ export const searchListMusic = (list: LX.Music.MusicInfo[], text: string) => {
258273
data: mInfo,
259274
})
260275
}
261-
return sortedList.map(item => item.data).reverse()
276+
return [
277+
...fullMathNameResults.values(),
278+
...fullMathSingerResults.values(),
279+
...fullMathAlbumResults.values(),
280+
...sortedList.map(item => item.data).reverse(),
281+
]
262282
}
263283

264284
/**

0 commit comments

Comments
 (0)