Skip to content

perf(search): remove wildcard matching and use match phrase prefix only#2273

Merged
synoet merged 1 commit intomainfrom
gab/feat/remove-wildcard-expansion-search
Mar 30, 2026
Merged

perf(search): remove wildcard matching and use match phrase prefix only#2273
synoet merged 1 commit intomainfrom
gab/feat/remove-wildcard-expansion-search

Conversation

@gbirman
Copy link
Copy Markdown
Contributor

@gbirman gbirman commented Mar 30, 2026

https://github.com/macro-inc/macro-api/pull/2491/changes was merged to account for match phrase prefix not really working with short words at the end of the last term. however, this combo query results in very slow search results, as demonstrated by all our slow search logs. technically this combo query wasn't really a match phrase prefix, but i think match phrase prefix is acceptable for what we want anyways. bumping max expansions will increase the number of possibly matching phrases but it might miss the prefix. in the future we can use an index prefixes mapping to get everything we need

@gbirman gbirman requested a review from a team as a code owner March 30, 2026 19:19
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved search query processing by simplifying query construction logic and removing complex short-term handling.
    • Added expansion limit (256) to partial-match queries to enhance search performance and stability.

Walkthrough

OpenSearch query building was simplified by removing Unicode grapheme-length validation and conditional logic that previously created composite bool queries for short terms. Match phrase prefix queries now consistently include a max_expansions limit of 256. Tests were updated to reflect the simplified behavior.

Changes

Cohort / File(s) Summary
Query Building Implementation
rust/cloud-storage/opensearch_client/src/search/query.rs
Removed grapheme-length validation and short-word special handling. Added max_expansions(256) to match phrase prefix queries. Introduced new constant MATCH_PHRASE_PREFIX_MAX_EXPANSIONS. Simplified to always return single queries instead of composite bool queries.
Query Building Tests
rust/cloud-storage/opensearch_client/src/search/.../test.rs
Updated test expectations to include max_expansions: 256 in match phrase prefix clauses. Renamed and modified tests to verify single-query output instead of composite bool queries with wildcard fallback behavior.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commits format (perf:) and is under 72 characters (71 chars), clearly summarizing the main change of removing wildcard matching in favor of match phrase prefix queries.
Description check ✅ Passed The description is directly related to the changeset, explaining the rationale for removing the combo query approach and adopting match phrase prefix with increased max_expansions due to performance issues.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@rust/cloud-storage/opensearch_client/src/search/query.rs`:
- Line 28: Add a short doc comment above the constant
MATCH_PHRASE_PREFIX_MAX_EXPANSIONS explaining why it is set to 256 (noting
OpenSearch's default is 50), that the higher value compensates for removed
wildcard matching, and mention the tradeoff (e.g., increased index memory and
term expansion cost) so future maintainers understand the rationale and
potential impact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b2484559-65e9-46fc-8aeb-0c19c76498d1

📥 Commits

Reviewing files that changed from the base of the PR and between 47ac9fd and b611636.

📒 Files selected for processing (3)
  • rust/cloud-storage/opensearch_client/src/search/builder/test.rs
  • rust/cloud-storage/opensearch_client/src/search/query.rs
  • rust/cloud-storage/opensearch_client/src/search/query/test.rs

@synoet synoet merged commit 5400449 into main Mar 30, 2026
37 of 38 checks passed
@synoet synoet deleted the gab/feat/remove-wildcard-expansion-search branch March 30, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants