Skip to content

Commit

Permalink
fix: filter algorithm with less match
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel-Develops committed Jan 29, 2025
1 parent dcb1458 commit 999fdde
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/filter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export function matchCharactersWithRegex(word: string, searchTerm: string) {
const escapedSearchTerm = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

// Construct a regex pattern that enforces order but allows small gaps
const regexPattern = escapedSearchTerm
.split("")
.map((char) => `(?=.*${char})`)
.map((char, index) => (index === 0 ? char : `[^${char}]{0,2}${char}`)) // Allow at most 2 non-matching chars between each
.join("");

const regex = new RegExp(regexPattern, "i"); // 'i' flag for case-insensitive matching
Expand Down

0 comments on commit 999fdde

Please sign in to comment.