Fix addMultiTermClauses: preserve per-field SHOULD when a clause isn't a bare TermQuery (#16441) - #16442
Open
OlivierJaquemet wants to merge 3 commits into
Open
Fix addMultiTermClauses: preserve per-field SHOULD when a clause isn't a bare TermQuery (#16441)#16442OlivierJaquemet wants to merge 3 commits into
OlivierJaquemet wants to merge 3 commits into
Conversation
…t a bare TermQuery (apache#16441)
…t a bare TermQuery (apache#16441)
…t a bare TermQuery (apache#16441)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16441
Problem:
QueryParserBase#addMultiTermClausesdecides whether to pass a nestedBooleanQuery's clauses through unchanged, or flatten them under a single forcedOccur(MUSTunderAND_OPERATOR), based on whether every clause is a bareTermQuery. This check is too narrow: aBoostQuery-wrapped term (or any other non-TermQueryleaf —PrefixQuery,PhraseQuery, etc.) fails it, causingMultiFieldQueryParser's per-fieldSHOULDdisjunction to be incorrectly flattened and forced toMUSTon every field independently — turning "any field may match" into "every field must match."Example: with a per-field boost configured and
AND_OPERATOR,MultiFieldQueryParser.parse(QueryParser.escape("hello !"))produces+(field1:hello)^2.0 +field2:helloinstead of the expected(field1:hello)^2.0 field2:hello.Fix: the real distinguishing signal is not the leaf's type but whether
q's direct clauses are themselves nestedBooleanQueryinstances (= several term positions that must be joined per the default operator — flatten+force is correct there) versus any other leaf type (= field alternatives for a single term position, which must be passed through unchanged regardless of leaf type). One-line change:Testing: added/updated unit tests covering OR/AND × boosted/unboosted × single-term/multi-term combinations, plus a
PrefixQueryregression case, to confirm the fix doesn't disturb the existing multi-term AND-joining behavior (which relies on the same flatten branch and must stay intact).