Skip to content

Commit

Permalink
chore: change search algorithm to be a word-based fuzzy search
Browse files Browse the repository at this point in the history
  • Loading branch information
trobonox committed Mar 9, 2025
1 parent 1fc7b5b commit 51d9856
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions components/kanban/Column.vue
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,35 @@ const columnSizeClass = computed(() => {
}
});

const escRegXp = (str: string) => {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
};

const fuzzyMatch = (input: string, str: string) => {
input =
".*" +
input
.toLowerCase()
.split("")
.map((x) => `${escRegXp(x)}.*`)
.join("");

const regexp = new RegExp(input, "i");
return regexp.test(str);
const inputWords = input.toLowerCase().split(/\s+/);
const strWords = str.toLowerCase().split(/\s+/);

let matches = 0;

inputWords.forEach((inputWord) => {
strWords.forEach((strWord) => {
let inputIndex = 0;
let strIndex = 0;
let wordMatches = 0;

while (inputIndex < inputWord.length && strIndex < strWord.length) {
if (inputWord[inputIndex] === strWord[strIndex]) {
wordMatches++;
inputIndex++;
}
strIndex++;
}

const matchRatio = wordMatches / inputWord.length;
if (matchRatio >= 0.6) {
// Adjust the threshold as needed
matches++;
}
});
});

return matches === inputWords.length;
};

const filteredCards = computed(() => {
Expand Down

0 comments on commit 51d9856

Please sign in to comment.