From 9e86ae78c4a556541b262a412722b06f4c56ccdb Mon Sep 17 00:00:00 2001 From: jackdavidweber Date: Fri, 19 Jun 2020 23:31:09 +0000 Subject: [PATCH 1/2] made my search feature incoorporate the edit distance work that I had done --- .../src/main/webapp/assets/js/testimonials.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/portfolio/src/main/webapp/assets/js/testimonials.js b/portfolio/src/main/webapp/assets/js/testimonials.js index 33d82d5..992383a 100644 --- a/portfolio/src/main/webapp/assets/js/testimonials.js +++ b/portfolio/src/main/webapp/assets/js/testimonials.js @@ -53,15 +53,22 @@ function filterFunction() { filter = input.value.toUpperCase(); ul = document.getElementById("testimonialUl"); li = ul.getElementsByTagName("li"); + const stringArray = []; for (i = 0; i < li.length; i++) { blockQuote = li[i].getElementsByTagName("blockquote")[0]; p = blockQuote.getElementsByTagName("p")[0]; txtValue = p.textContent || p.innerText; - if (txtValue.toUpperCase().indexOf(filter) > -1) { - li[i].style.display = ""; - } else { - li[i].style.display = "none"; - } + stringArray.push(txtValue.toUpperCase()); // FIXME: touppercase might not work + + //set all of the list items to disapear so that they can be made to reapear later + li[i].style.display = "none"; + } + + const matches = distanceOfArr(stringArray, filter, 2) + + // make matches re-appear + for (i=0; i < matches.length; i++){ + li[matches[i].arrIndex].style.display = ""; } } @@ -171,11 +178,13 @@ function findEditDistance(w1,w2){ */ function distanceOfArr(arrSentences, term, maxED){ + let tracker = 0 let retArray = [] for (const sentence of arrSentences){ let ed = minEditDistanceWord(sentence, term) if(ed < maxED){ - retArray.push({"sentence": sentence, "editDistance": ed}); + retArray.push({"sentence": sentence, "editDistance": ed, "arrIndex": tracker}); + tracker += 1; } } return retArray; From 5c208e36fc5fdc6fd6a87ec9360c982b800f8067 Mon Sep 17 00:00:00 2001 From: jackdavidweber Date: Thu, 25 Jun 2020 19:10:26 +0000 Subject: [PATCH 2/2] implemented host comments --- portfolio/src/main/webapp/assets/js/testimonials.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/portfolio/src/main/webapp/assets/js/testimonials.js b/portfolio/src/main/webapp/assets/js/testimonials.js index 992383a..2af8cf4 100644 --- a/portfolio/src/main/webapp/assets/js/testimonials.js +++ b/portfolio/src/main/webapp/assets/js/testimonials.js @@ -58,16 +58,17 @@ function filterFunction() { blockQuote = li[i].getElementsByTagName("blockquote")[0]; p = blockQuote.getElementsByTagName("p")[0]; txtValue = p.textContent || p.innerText; - stringArray.push(txtValue.toUpperCase()); // FIXME: touppercase might not work + stringArray.push(txtValue.toUpperCase()); - //set all of the list items to disapear so that they can be made to reapear later + // set all of the list items to disapear so that they can be made to reapear later li[i].style.display = "none"; } + // TODO: give user feedback that only one term is supported https://github.com/jackdavidweber/step-portfolio/pull/26#discussion_r443534422 const matches = distanceOfArr(stringArray, filter, 2) // make matches re-appear - for (i=0; i < matches.length; i++){ + for (let i=0; i < matches.length; i++){ li[matches[i].arrIndex].style.display = ""; } } @@ -184,7 +185,7 @@ function distanceOfArr(arrSentences, term, maxED){ let ed = minEditDistanceWord(sentence, term) if(ed < maxED){ retArray.push({"sentence": sentence, "editDistance": ed, "arrIndex": tracker}); - tracker += 1; + tracker++; } } return retArray;