Skip to content

[#82] fix(discover): use substring matching for plain keyword filters#83

Merged
jerryshao merged 1 commit into
mainfrom
fix/keyword-filter-substring-matching
Mar 26, 2026
Merged

[#82] fix(discover): use substring matching for plain keyword filters#83
jerryshao merged 1 commit into
mainfrom
fix/keyword-filter-substring-matching

Conversation

@mchades

@mchades mchades commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Improve the keyword matching algorithm in the discover handler to use substring matching for plain keywords (without glob characters), while retaining fnmatch glob matching for patterns with wildcards.

Changes:

  • Add _has_glob_chars() helper to detect glob special characters (*, ?, [)
  • Modify _ci_glob_match() to use substring matching when no glob chars are present
  • Add logger.debug() in _matches_keyword() when a resource is filtered out
  • Add 7 new test cases covering substring matching, case insensitivity, partial matching, backward-compatible glob matching, and no-match scenarios

Why are the changes needed?

The current glob-only matching with fnmatch requires explicit wildcards (e.g., *user*) for fuzzy matching. Plain keywords like user only match if the entire field value equals "user", which is unintuitive for AI agents. Agents typically pass plain keywords without wildcards, causing the discover keyword filter to return empty results unexpectedly.

Closes #82

Does this PR introduce any user-facing change?

Yes. Plain keyword searches in adp.discover now perform substring matching instead of exact glob matching. For example, keyword="user" will now match resources with IDs like user_profiles or descriptions containing "user". Keywords with glob wildcards (*, ?, [) continue to use fnmatch as before.

How was this patch tested?

  • 7 new unit tests added to TestDiscoverHandlerKeywordFilter
  • All 45 existing tests pass

Previously keyword filtering used fnmatch glob matching exclusively,
requiring wildcards (e.g. *user*) for fuzzy matching. Plain keywords
like "user" would only match exact field values, making the filter
unintuitive for agents.

Now plain keywords without glob characters (*, ?, [) use
case-insensitive substring matching, while keywords with glob
characters retain fnmatch behavior for backward compatibility.

Also adds debug logging when a resource is filtered out by keyword.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mchades
mchades requested a review from jerryshao March 23, 2026 10:02
@jerryshao
jerryshao merged commit 79c92e6 into main Mar 26, 2026
6 checks passed
@jerryshao
jerryshao deleted the fix/keyword-filter-substring-matching branch March 26, 2026 08:41
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.

Keyword filter in discover uses glob-only matching, failing for plain keywords

2 participants