Skip to content

fix(query): match and multi_match honour fuzziness (#3172) - #3179

Merged
xerj-team merged 1 commit into
xerj-org:mainfrom
Varshith-Kali:fix-3172-match-fuzziness
Nov 25, 2026
Merged

xerj-team merged 1 commit into
xerj-org:mainfrom
Varshith-Kali:fix-3172-match-fuzziness

Conversation

@Varshith-Kali

Copy link
Copy Markdown
Contributor

Fixes #3172.

An agent wrote this PR. What follows splits what I verified (commands run, output observed) from what I assumed (untested).

What was wrong

parse_match never read fuzziness (or prefix_length) and always built a plain QueryNode::Match, so a typo-tolerant search returned nothing while the standalone fuzzy query returned the expected hits. Plain multi_match had the same gap. Only match_bool_prefix and bool_prefix multi_match built Fuzzy leaves per token.

Fix

Lower a match-family query carrying fuzziness to per-token QueryNode::Fuzzy leaves, the shape the bool_prefix paths already build:

  • match combines the leaves per operator (AND to must, otherwise should with minimum_should_match), keeping boost and _name.
  • Plain multi_match lowers each field the same way, then combines per type the way the engine combines per-field matches: best_fields to dis_max (with tie_breaker, default 0.0), most_fields and cross_fields to a bool should. Field ^boost suffixes and the outer boost are kept.
  • phrase and phrase_prefix reject fuzziness with a 400, as in ES.
  • The two inline bool_prefix fuzziness reads are consolidated onto one shared parse_fuzziness helper with identical semantics. No behavior change there.

Verified (commands run, output observed)

  • New engine test engine/crates/xerj-engine/tests/match_fuzziness.rs: 13 cases on a text field (exact match, AUTO and fixed fuzziness, multi-token OR and AND, prefix_length allow/block, best_fields/most_fields/cross_fields, no-fuzziness controls), each answered buffered and after _flush. It failed pre-fix on the first fuzzy case (0 hits, expected 1) and passes post-fix.
  • 7 new xerj-query parser tests: single-token collapse, operator AND/OR, minimum_should_match, prefix_length plus boost, no-fuzziness unchanged, DisMax/Bool per type, phrase rejection, unknown-type error.
  • cargo test -p xerj-query: 221 passed, 1 ignored, 0 failed. cargo test -p xerj-engine --lib: 944 passed, 0 failed. cargo test -p xerj-engine --test match_fuzziness: 1 passed.
  • cargo fmt -p xerj-query -p xerj-engine: clean. Clippy on the touched crates shows no warning from this change (the only too_many_arguments hit is covered by the repo-standard allow on the helper; a xerj-common clippy failure under -D warnings is in code this PR does not touch).

Assumed (untested)

  • The [fuzziness] not allowed for type [phrase] rejection wording follows ES behavior as I recall it; I could not run ES here to confirm the exact message.
  • A scoped release build and the full ES-YAML conformance run were not finished locally (the ci-test server build was still compiling when this PR opened); CI covers both.
  • fuzzy_transpositions is not threaded through: the engine fuzzy is Damerau-Levenshtein (transpositions cost 1), which is the ES default of true, and QueryNode::Fuzzy carries no such flag anywhere in the codebase, including the standalone fuzzy query. An explicit fuzzy_transpositions: false is therefore still accepted and ignored, as before.
  • Field patterns (*, title*) in a fuzzy multi_match fall through to the plain node, so fuzziness stays ignored there rather than silently zeroing the query.
  • lenient has no Fuzzy equivalent and is dropped on the fuzzy path, as in the bool_prefix fuzzy arm. A fuzzy match on a numeric field with a non-numeric string therefore answers 0 hits instead of the 400 the plain Match path gives; the standalone fuzzy query behaves the same way today.
  • Tokenisation is the parser usual whitespace split (as in match_bool_prefix), not the full standard analyzer, so a hyphenated query tokenizes differently than a plain match does.

@cla-bot

cla-bot Bot commented Nov 14, 2026

Copy link
Copy Markdown

Thanks for this contribution — we'd like to merge it.

Before we can, we need a signed Contributor License Agreement from: @Varshith-Kali

It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to .contributors — that pull request is your signature, since it is made from your own account.

Once it is merged, comment @cla-bot check here and this check will go green. If you believe you are already covered, comment @cla-bot check and it will re-verify.

@xerj-team

Copy link
Copy Markdown
Collaborator

Thanks @Varshith-Kali, I reviewed this and it looks correct: fuzzy match and plain multi_match now lower to per-token Fuzzy leaves, which bool_prefix already uses, and the end-to-end test checks each case buffered and flushed. Non-blocking note: query tokens are split on whitespace, not run through the field analyzer, the same approximation bool_prefix already makes. Two things are still needed before merge: your CLA line (steps in the comment on #3159), and a green CI run. CI is approved, but the runners are not picking up jobs right now, so it has not run yet. Once both are done, this merges as is.

@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Thanks, glad the fuzzy match and multi_match lowering reads right. Noted on the whitespace token split matching what bool_prefix already does. The CLA line and a green CI run are still the open items, with CI approved but still queued.

@drk-ram drk-ram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed engine/crates/xerj-query/src/parser.rs and engine/crates/xerj-engine/tests/match_fuzziness.rs (f84e21c3):

  • fuzziness and prefix_length wiring on match and multi_match (parser.rs): Reading fuzziness and prefix_length in parse_match and field/term-centric multi_match so fuzzy tokens build QueryNode::Fuzzy leaves restores parity with standalone fuzzy queries across both buffered memtable and flushed segment searches (#3172).

@Varshith-Kali
Varshith-Kali force-pushed the fix-3172-match-fuzziness branch from f84e21c to 3f24633 Compare November 21, 2026 01:07
@cla-bot

cla-bot Bot commented Nov 21, 2026

Copy link
Copy Markdown

Thanks for this contribution — we'd like to merge it.

Before we can, we need a signed Contributor License Agreement from: @Varshith-Kali

It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to .contributors — that pull request is your signature, since it is made from your own account.

Once it is merged, comment @cla-bot check here and this check will go green. If you believe you are already covered, comment @cla-bot check and it will re-verify.

`parse_match` never read `fuzziness` (or `prefix_length`) and always built a plain `QueryNode::Match`, so a typo-tolerant search returned nothing while the standalone `fuzzy` query returned the expected hits. Plain `multi_match` had the same gap; only `match_bool_prefix` and bool_prefix `multi_match` built `Fuzzy` leaves per token.

Lower a `match`-family query carrying `fuzziness` to per-token `QueryNode::Fuzzy` leaves, the shape the `bool_prefix` paths already build. `match` combines the leaves per operator (AND to must, otherwise should with `minimum_should_match`); plain `multi_match` combines per-field clauses per type (best_fields to dis_max, most_fields and cross_fields to bool should). `phrase` and `phrase_prefix` reject fuzziness, as in ES. The two inline `bool_prefix` fuzziness reads are consolidated onto one shared `parse_fuzziness` helper with identical semantics.

Evidence: new engine test `match_fuzziness.rs` (13 cases, buffered and flushed) failed pre-fix on the first fuzzy case (0 hits, expected 1) and passes post-fix; 7 new `xerj-query` parser tests pass; `cargo test -p xerj-query` 212 passed, `cargo test -p xerj-engine --lib` 944 passed; `cargo fmt` clean; clippy on the touched crates shows no warning from this change.

Known limits (see PR body): `fuzzy_transpositions` is not threaded through (engine fuzzy is Damerau, the ES default); field patterns (`*`, `title*`) fall through to the plain node; `lenient` has no `Fuzzy` equivalent and is dropped on the fuzzy path.

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@Varshith-Kali
Varshith-Kali force-pushed the fix-3172-match-fuzziness branch from 3f24633 to 1de1b75 Compare November 21, 2026 10:09
@cla-bot

cla-bot Bot commented Nov 21, 2026

Copy link
Copy Markdown

Thanks for this contribution — we'd like to merge it.

Before we can, we need a signed Contributor License Agreement from: @Varshith-Kali

It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to .contributors — that pull request is your signature, since it is made from your own account.

Once it is merged, comment @cla-bot check here and this check will go green. If you believe you are already covered, comment @cla-bot check and it will re-verify.

@xerj-team
xerj-team merged commit 820802e into xerj-org:main Nov 25, 2026
0 of 2 checks passed
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.

match and multi_match ignore fuzziness

3 participants