MultiFieldQueryParser: default operator is not honored between term positions (#16443) - #16446
Open
OlivierJaquemet wants to merge 1 commit into
Open
MultiFieldQueryParser: default operator is not honored between term positions (#16443)#16446OlivierJaquemet wants to merge 1 commit into
OlivierJaquemet wants to merge 1 commit into
Conversation
…alyzer-split term positions (apache#16443)
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 #16443
Problem:
MultiFieldQueryParser's javadoc promises that underAND_OPERATOR, "all the query's terms must appear, but it doesn't matter in what fields they appear." This only holds when each term reaches the parser as a separate grammar-level token (real whitespace, handled byQueryParser.jj's ownClause()/addClause()machinery). It doesn't hold when several terms are produced by the analyzer alone from a single piece of query text passed to onegetFieldQuery(null, text, quoted)call — e.g. an escaped separator with no real whitespace, word decompounding, CJK segmentation, or synonym expansion. In that case,getMultiFieldQuery()always combines the per-position groups withOccur.SHOULD, ignoring the configured default operator entirely.Example: with
AND_OPERATORand an analyzer that splits"colonBefore:colonAfter"(one escaped grammar token, no real whitespace) into two terms,MultiFieldQueryParserproduces(field1:colonbefore field2:colonbefore) (field1:colonafter field2:colonafter)— no+at all, i.e. effectively OR — instead of the documented+(...) +(...).Fix:
getMultiFieldQueryis reused for two different things: combining fields for a single term (alwaysSHOULD, correct) and combining term positions whenmaxTerms > 1(should honor the default operator). This adds a dedicatedgetMultiTermPositionQuerystep for the latter case, leavinggetMultiFieldQueryitself untouched for its existing field-combination role:Testing: added tests to
TestMultiFieldQueryParserreproducing the analyzer-split-single-token case (OR and AND, with and without a per-field boost), usingMockAnalyzer/MockTokenizer.SIMPLEso that specific input needs an analyzer that actually emits more than one token to exercise this path.