Optimized Algo

This commit is contained in:
Simon Martens
2023-02-03 11:54:00 +01:00
parent f4000cdd13
commit 87bf64345e
2 changed files with 17 additions and 8 deletions

View File

@@ -86,6 +86,7 @@
// Scripts for filtering lists // Scripts for filtering lists
let dictionary = []; let dictionary = [];
function createIndex(id){ function createIndex(id){
$("#" + id + " .searchable").each( (ind, el) => { $("#" + id + " .searchable").each( (ind, el) => {
dictionary.push({ dictionary.push({
category: $(el).parents(".category"), category: $(el).parents(".category"),
@@ -107,7 +108,7 @@
} }
$(document).ready(function( $ ) { $(document).ready(function() {
// Scroll button // Scroll button
if (document.getElementById("scrollbutton") !== null) { if (document.getElementById("scrollbutton") !== null) {
scrollFunction(); scrollFunction();
@@ -130,21 +131,29 @@
$(".hideifsearching").each( (ind, el) => { $(".hideifsearching").each( (ind, el) => {
$(el).hide(); $(el).hide();
}); });
for (let item of found) { if (sw.length > 1) {
$(item.element).unmark().hide(); for (let item of found) {
$(item.category).hide(); $(item.element).unmark();
}
} }
if (term.length > swl && term.startsWith(sw)) { if (term.length > swl && term.startsWith(sw)) {
found = findWord( term, found ); found = findWord( term, found );
} else { } else {
found = findWord( term, dictionary ); found = findWord( term, dictionary );
} }
for (let item of found) { for (let item of dictionary) {
$(item.category).hide();
if (found.indexOf(item) !== -1) {
$(item.category).addClass("search-expanded").show(); $(item.category).addClass("search-expanded").show();
$(item.element).show(); $(item.element).show();
if (term.length >= 3) { if (term.length >= 3) {
$(item.element).mark(term); $(item.element).mark(term, {
} "separateWordSearch": false
});
}
} else {
$(item.element).unmark().hide();
}
} }
sw = term; sw = term;
swl = term.length; swl = term.length;

File diff suppressed because one or more lines are too long