1
0

improve: search ranking

This commit is contained in:
alikia2x (寒寒) 2025-11-09 15:57:27 +08:00
parent bf159dcbd3
commit 371041ec45
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 56209E0CCD8420C6
2 changed files with 5 additions and 3 deletions

View File

@ -35,12 +35,14 @@ const getSongSearchResult = async (searchQuery: string) => {
.map((song) => {
if (!song.songs.name) return null;
const occurrences = (song.songs.name.match(new RegExp(searchQuery, "gi")) || []).length;
const lengthRatio = searchQuery.length / song.songs.name.length;
const viewsLog = Math.log10(song.latest_video_snapshot.views + 1);
return {
type: "song" as "song",
data: song,
occurrences,
viewsLog
viewsLog,
lengthRatio
};
})
.filter((d) => d !== null);
@ -61,7 +63,7 @@ const getSongSearchResult = async (searchQuery: string) => {
const normalizedViewsLog = (result.viewsLog - minViewsLog) / viewsLogRange;
// Weighted combination
const rank = normalizedOccurrences * 0.6 + normalizedViewsLog * 0.4;
const rank = normalizedOccurrences * 0.3 + result.lengthRatio * 0.5 + normalizedViewsLog * 0.2;
return {
type: result.type,

View File

@ -167,7 +167,7 @@ export default function SongInfo({ loaderData }: Route.ComponentProps) {
if (error || !data) {
toast.error(`无法更新:${error.value.message || "未知错误"}`);
}
setData(data?.updated);
getInfo();
};
return (