Skip to content

Comments

Improved filtering and matching#54

Open
ronaldburns wants to merge 1 commit intoflecs-hub:masterfrom
ronaldburns:fuzzy_search
Open

Improved filtering and matching#54
ronaldburns wants to merge 1 commit intoflecs-hub:masterfrom
ronaldburns:fuzzy_search

Conversation

@ronaldburns
Copy link

@ronaldburns ronaldburns commented Oct 22, 2025

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

  • Replaced the previous exact substring filter (matchesFilter) with a fuzzy matching algorithm using thresholded Levenshtein distance, allowing for typo-tolerant and partial matches.
  • Added a new computed property filtered that applies fuzzy matching to components, pairs, and tags, ensuring only relevant items are shown in the inspector.
  • Updated the template to use the new filtered lists for rendering, removing the old matchesFilter check and ensuring each rendered element has a unique key.

Refactoring and code simplification

  • Refactored the match counting logic to use the new filtered lists, improving performance and code readability.
  • Removed the old matchesFilter function and streamlined the filter normalization and application process.

Examples

image image image

@ronaldburns ronaldburns marked this pull request as ready for review October 22, 2025 22:06
Copilot AI review requested due to automatic review settings October 22, 2025 22:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 filtered property that pre-filters all lists
  • Simplified template rendering by moving filter logic from v-if to 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]+/)) {
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
for (const t of text.split(/[^a-z0-9]+/)) {
for (const t of text.split(/[^a-zA-Z0-9]+/)) {

Copilot uses AI. Check for mistakes.
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);
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Suggested change
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);
};

Copilot uses AI. Check for mistakes.
}
}
if (rowBest > limit) return limit + 1;
for (let j = 0; j <= m; j++) prev[j] = curr[j] ?? Infinity;
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
for (let j = 0; j <= m; j++) prev[j] = curr[j] ?? Infinity;
for (let j = lo; j <= hi; j++) prev[j] = curr[j];

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant