From f4f0081e3d460c0abe82703b7d27842567f0ddf3 Mon Sep 17 00:00:00 2001 From: Bui Date: Tue, 22 Mar 2022 00:44:28 +0000 Subject: [PATCH] fix for search.js split --- public/src/js/search.js | 14 +++++++++++++- public/src/js/songselect.js | 7 ++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/public/src/js/search.js b/public/src/js/search.js index 6a04eaa..30c52ba 100644 --- a/public/src/js/search.js +++ b/public/src/js/search.js @@ -32,6 +32,18 @@ class Search{ this.style.appendChild(document.createTextNode(css.join("\n"))) loader.screen.appendChild(this.style) } + + normalizeString(string){ + string = string + .replace('’', '\'').replace('“', '"').replace('”', '"') + .replace('。', '.').replace(',', ',').replace('、', ',') + + kanaPairs.forEach(pair => { + string = string.replace(pair[1], pair[0]) + }) + + return string.normalize("NFKD").replace(/[\u0300-\u036f]/g, "") + } perform(query){ var results = [] @@ -79,7 +91,7 @@ class Search{ } }) - query = editedSplit.join(" ").trim().normalize("NFD").replace(/[\u0300-\u036f]/g, "") + query = this.normalizeString(editedSplit.join(" ").trim()) var totalFilters = Object.keys(filters).length var random = false diff --git a/public/src/js/songselect.js b/public/src/js/songselect.js index cd7a5db..cbfb968 100644 --- a/public/src/js/songselect.js +++ b/public/src/js/songselect.js @@ -94,12 +94,14 @@ class SongSelect{ this.font = strings.font + this.search = new Search(this) + this.songs = [] for(let song of assets.songs){ var title = this.getLocalTitle(song.title, song.title_lang) - song.titlePrepared = title ? fuzzysort.prepare(this.normalizeSearch(title)) : null + song.titlePrepared = title ? fuzzysort.prepare(this.search.normalizeString(title)) : null var subtitle = this.getLocalTitle(title === song.title ? song.subtitle : "", song.subtitle_lang) - song.subtitlePrepared = subtitle ? fuzzysort.prepare(this.normalizeSearch(subtitle)) : null + song.subtitlePrepared = subtitle ? fuzzysort.prepare(this.search.normalizeString(subtitle)) : null this.songs.push(this.addSong(song)) } this.songs.sort((a, b) => { @@ -228,7 +230,6 @@ class SongSelect{ this.currentSongCache = new CanvasCache(noSmoothing) this.nameplateCache = new CanvasCache(noSmoothing) - this.search = new Search(this) this.difficulty = [strings.easy, strings.normal, strings.hard, strings.oni] this.difficultyId = ["easy", "normal", "hard", "oni", "ura"]