alessandro trinca tornidor commited on
Commit
9074889
·
1 Parent(s): a0b0525

feat: now result search is case-insensitive

Browse files

result search works on actual words (not only stemmings)

Files changed (1) hide show
  1. static/index.js +10 -20
static/index.js CHANGED
@@ -551,27 +551,17 @@ function dynamicSort(property, order) {
551
  }
552
 
553
  /**
554
- * This function filters an array based on a property key and the value to use for filter.
 
555
  *
556
- * @description
557
- * The function iterates over each element in the array.
558
- * If the element's value for the specified key matches the search value (it's included, case-insensitive), it is added to the new array.
559
- *
560
- * @param {array} arr - The array to filter.
561
- * @param {string} key - The property key to match against.
562
- * @param {string} value - The value to search for in the array elements.
563
- * @returns {array} A new array containing only the elements that match the specified value.
564
  */
565
- function arrayFilter(arr, key, value) {
566
- const newArray = [];
567
- for(let i=0, l=arr.length; i<l; i++) {
568
- let currentElement = arr[i]
569
- let currentValue = currentElement[key]
570
- if(currentValue.toLowerCase().includes(value)) {
571
- newArray.push(arr[i]);
572
- }
573
- }
574
- return newArray;
575
  }
576
 
577
  /**
@@ -599,7 +589,7 @@ async function updateWordsFrequencyTables() {
599
  let inputFilter = document.getElementById("filter-words-frequency")
600
  let inputFilterValue = inputFilter.value
601
  if (inputFilterValue !== undefined && inputFilter.value !== "") {
602
- reduced = arrayFilter(reduced, "word_prefix", inputFilterValue)
603
  }
604
 
605
  let listOfWords = document.getElementById("id-list-of-words")
 
551
  }
552
 
553
  /**
554
+ * Filters an array of objects by checking if a specified nested value exists within any object.
555
+ * The search is case-insensitive and checks all nested properties by converting the object to a JSON string.
556
  *
557
+ * @param {Array<Object>} array - The array of objects to filter.
558
+ * @param {string} nestedValue - The value to search for within the objects.
559
+ * @returns {Array<Object>} - A new array containing objects where the nested value is found.
 
 
 
 
 
560
  */
561
+ function arrayFilterNestedValue(array, nestedValue) {
562
+ return array.filter(item => {
563
+ return JSON.stringify(item).toLowerCase().includes(nestedValue.toLowerCase());
564
+ });
 
 
 
 
 
 
565
  }
566
 
567
  /**
 
589
  let inputFilter = document.getElementById("filter-words-frequency")
590
  let inputFilterValue = inputFilter.value
591
  if (inputFilterValue !== undefined && inputFilter.value !== "") {
592
+ reduced = arrayFilterNestedValue(reduced, inputFilterValue)
593
  }
594
 
595
  let listOfWords = document.getElementById("id-list-of-words")