Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR replaces exact substring filtering with fuzzy matching using thresholded Levenshtein distance, making the entity inspector more tolerant of typos and partial matches when filtering components, pairs, and tags.
Key changes:
- Introduced fuzzy matching algorithm with adaptive distance thresholds based on query length
- Refactored filtering logic into a computed
filteredproperty that pre-filters all lists - Simplified template rendering by moving filter logic from
v-ifto computed properties
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const maxLen = qLen + limit; | ||
|
|
||
| // Token heuristic | ||
| for (const t of text.split(/[^a-z0-9]+/)) { |
There was a problem hiding this comment.
The regex pattern [^a-z0-9]+ only matches lowercase letters and digits. This will cause uppercase letters to be treated as delimiters, potentially breaking token matching for camelCase or PascalCase identifiers. Consider using [^a-zA-Z0-9]+ to preserve case-insensitive matching.
| for (const t of text.split(/[^a-z0-9]+/)) { | |
| for (const t of text.split(/[^a-zA-Z0-9]+/)) { |
| const filtered = computed(() => { | ||
| const f = normalizedFilter.value; | ||
| const norm = s => (s ?? "").toLowerCase(); | ||
| const keep = e => !f || norm(e.fullName).includes(f) || fuzzy(norm(e.fullName), f); |
There was a problem hiding this comment.
The norm(e.fullName) function is called twice per element when both the includes check and fuzzy check are executed. Consider computing the normalized name once: const normName = norm(e.fullName); const keep = e => !f || normName.includes(f) || fuzzy(normName, f);
| const keep = e => !f || norm(e.fullName).includes(f) || fuzzy(norm(e.fullName), f); | |
| const keep = e => { | |
| const normName = norm(e.fullName); | |
| return !f || normName.includes(f) || fuzzy(normName, f); | |
| }; |
| } | ||
| } | ||
| if (rowBest > limit) return limit + 1; | ||
| for (let j = 0; j <= m; j++) prev[j] = curr[j] ?? Infinity; |
There was a problem hiding this comment.
Using the nullish coalescing operator with array access is unnecessary here. Array elements initialized in the loop are never null or undefined. This fallback to Infinity could mask logic errors. Since curr[j] is set for all j in range [lo, hi] but this loop copies [0, m], elements outside the band will be undefined and incorrectly set to Infinity, breaking the algorithm.
| for (let j = 0; j <= m; j++) prev[j] = curr[j] ?? Infinity; | |
| for (let j = lo; j <= hi; j++) prev[j] = curr[j]; |
This pull request enhances the entity inspector module's filtering capabilities by introducing fuzzy matching for component, pair, and tag lists. The new approach uses a thresholded Levenshtein distance algorithm to allow for approximate matches, making the filter more forgiving of typos and partial matches. The logic for filtering and counting matches has been refactored for efficiency and clarity.
Improved filtering and matching
matchesFilter) with a fuzzy matching algorithm using thresholded Levenshtein distance, allowing for typo-tolerant and partial matches.filteredthat applies fuzzy matching to components, pairs, and tags, ensuring only relevant items are shown in the inspector.filteredlists for rendering, removing the oldmatchesFiltercheck and ensuring each rendered element has a unique key.Refactoring and code simplification
matchesFilterfunction and streamlined the filter normalization and application process.Examples