Repository navigation
fix(query): match and multi_match honour fuzziness (#3172) - #3179
Conversation
|
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 Once it is merged, comment |
|
Thanks @Varshith-Kali, I reviewed this and it looks correct: fuzzy |
|
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
left a comment
There was a problem hiding this comment.
Reviewed engine/crates/xerj-query/src/parser.rs and engine/crates/xerj-engine/tests/match_fuzziness.rs (f84e21c3):
fuzzinessandprefix_lengthwiring onmatchandmulti_match(parser.rs): Readingfuzzinessandprefix_lengthinparse_matchand field/term-centricmulti_matchso fuzzy tokens buildQueryNode::Fuzzyleaves restores parity with standalonefuzzyqueries across both buffered memtable and flushed segment searches (#3172).
f84e21c to
3f24633
Compare
|
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 Once it is merged, comment |
`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>
3f24633 to
1de1b75
Compare
|
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 Once it is merged, comment |
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_matchnever readfuzziness(orprefix_length) and always built a plainQueryNode::Match, so a typo-tolerant search returned nothing while the standalonefuzzyquery returned the expected hits. Plainmulti_matchhad the same gap. Onlymatch_bool_prefixand bool_prefixmulti_matchbuiltFuzzyleaves per token.Fix
Lower a
match-family query carryingfuzzinessto per-tokenQueryNode::Fuzzyleaves, the shape thebool_prefixpaths already build:matchcombines the leaves per operator (AND to must, otherwise should withminimum_should_match), keeping boost and_name.multi_matchlowers each field the same way, then combines per type the way the engine combines per-field matches: best_fields to dis_max (withtie_breaker, default 0.0), most_fields and cross_fields to a bool should. Field^boostsuffixes and the outer boost are kept.phraseandphrase_prefixrejectfuzzinesswith a 400, as in ES.bool_prefixfuzziness reads are consolidated onto one sharedparse_fuzzinesshelper with identical semantics. No behavior change there.Verified (commands run, output observed)
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.xerj-queryparser 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 onlytoo_many_argumentshit is covered by the repo-standard allow on the helper; axerj-commonclippy failure under-D warningsis in code this PR does not touch).Assumed (untested)
[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.fuzzy_transpositionsis not threaded through: the engine fuzzy is Damerau-Levenshtein (transpositions cost 1), which is the ES default of true, andQueryNode::Fuzzycarries no such flag anywhere in the codebase, including the standalonefuzzyquery. An explicitfuzzy_transpositions: falseis therefore still accepted and ignored, as before.*,title*) in a fuzzymulti_matchfall through to the plain node, so fuzziness stays ignored there rather than silently zeroing the query.lenienthas noFuzzyequivalent and is dropped on the fuzzy path, as in thebool_prefixfuzzy arm. A fuzzymatchon a numeric field with a non-numeric string therefore answers 0 hits instead of the 400 the plainMatchpath gives; the standalonefuzzyquery behaves the same way today.match_bool_prefix), not the full standard analyzer, so a hyphenated query tokenizes differently than a plainmatchdoes.