OlivierJaquemet opened a new pull request, #16442:
URL: https://github.com/apache/lucene/pull/16442

   Fixes #16441
   
   **Problem:** `QueryParserBase#addMultiTermClauses` decides whether to pass a 
nested `BooleanQuery`'s clauses through unchanged, or flatten them under a 
single forced `Occur` (`MUST` under `AND_OPERATOR`), based on whether every 
clause is a bare `TermQuery`. This check is too narrow: a `BoostQuery`-wrapped 
term (or any other non-`TermQuery` leaf — `PrefixQuery`, `PhraseQuery`, etc.) 
fails it, causing `MultiFieldQueryParser`'s per-field `SHOULD` disjunction to 
be incorrectly flattened and forced to `MUST` on 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:hello` instead 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 nested `BooleanQuery` instances (= 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:
   
   ```diff
   - if (!(clause.getQuery() instanceof TermQuery)) {
   + if (clause.getQuery() instanceof BooleanQuery) {
   ```
   
   **Testing:** added/updated unit tests covering OR/AND × boosted/unboosted × 
single-term/multi-term combinations, plus a `PrefixQuery` regression 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).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to