From d31547c4cc8f0800ec4540cdbba681a588c619f0 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sun, 7 Apr 2024 15:51:53 +0200 Subject: [PATCH] added levenshtein distance to search input --- .../ResearcherProfile.vue | 77 ++++++++++--------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/frontend/src/Apps/ScientificPublications/ResearcherProfile.vue b/frontend/src/Apps/ScientificPublications/ResearcherProfile.vue index dca20a4..e369027 100644 --- a/frontend/src/Apps/ScientificPublications/ResearcherProfile.vue +++ b/frontend/src/Apps/ScientificPublications/ResearcherProfile.vue @@ -12,6 +12,14 @@ const statsOf = ref(""); const statsBy = ref(""); let chart; +const articleList = [ + "First Article", + "The composition of the light", + "The composition of the sand", + "Fluctuation in universe beavers", + "The Potato War" +] + const jsonMockViewsByYears= [ {label: "2004", y:4}, {label: "2005", y:99}, @@ -20,26 +28,39 @@ const jsonMockViewsByYears= [ {label: "2011", y:1666}, ] -function inputKeyUp() { - let filter, ul, li, a, txtValue; - filter = input.value.toUpperCase(); - if (document.getElementById("myUL") != null) { - ul = document.getElementById("myUL"); - li = ul.getElementsByTagName("li"); - - // Loop through all list items, and hide those who don't match the search query - for (let i = 0; i < li.length; i++) { - a = li[i].getElementsByTagName("a")[0]; - txtValue = a.textContent || a.innerText; - if (txtValue.toUpperCase().indexOf(filter) > -1) { - li[i].style.display = ""; - } else { - li[i].style.display = "none"; - } +function searchInList(list, searchInput){ + if (searchInput === "") + return list + let retList =[] + for (let i = 0; i < list.length; i++) { + console.log(list[i] + " et " + searchInput + " vaut " + lDistance(list[i], searchInput) ) + if (lDistance(list[i], searchInput) < 6){ + retList.push(list[i]) } } + return retList } +function lDistance(s,t){ + if (!s.length) return t.length; + if (!t.length) return s.length; + const arr = []; + for (let i = 0; i <= t.length; i++) { + arr[i] = [i]; + for (let j = 1; j <= s.length; j++) { + arr[i][j] = + i === 0 + ? j + : Math.min( + arr[i - 1][j] + 1, + arr[i][j - 1] + 1, + arr[i - 1][j - 1] + (s[j - 1] === t[i - 1] ? 0 : 1) + ); + } + } + return arr[t.length][s.length]; +}; + const options = reactive({ backgroundColor:null, theme: "light2", @@ -113,23 +134,9 @@ function update(){
@@ -189,7 +196,6 @@ function update(){ } #articles { - background-color: orange; } #search-input { @@ -200,8 +206,9 @@ function update(){ margin-bottom: 12px; } -#myUL { +#articlesUL { list-style-type: none; + color: white; padding: 0; margin: 0; }