sakshichitnis27 opened a new pull request, #16987: URL: https://github.com/apache/lucene/pull/16987
### Description Fixes #16950 Since #16446, the classic `QueryParser` adds a run of plain words (for example `apple banana`) as one grouped clause. If the analyzer drops the word right before `AND`/`OR` (a stopword, say), the operator is applied to the whole group instead of to the last word. With the stopword `the` and the default `OR` operator: | query | parsed as | |---|---| | `apple banana AND cherry` | `body:apple +body:banana +body:cherry` | | `apple banana the AND cherry` | `+(body:apple body:banana) +body:cherry` | so the two queries return different documents. The code before #16446, and `setSplitOnWhitespace(true)`, give the first parse for both. This adds the clauses of such a run one by one again, through a new package-private `QueryParserBase#addMultiTermRunClauses` that `MultiTerm` in `QueryParser.jj` now calls (`QueryParser.java` and the checksum file are regenerated). It only does that when the analyzed query is a `BooleanQuery` whose clauses all have the default operator's occur and all cover the same fields; anything else is still added as one clause, as it is today. The occur check keeps the per-field boost case from #16441 working, and the same-fields check keeps the fields of one term position together in `MultiFieldQueryParser` (otherwise `AND` would only apply to the last field). Because the classic parser prints the flat clauses again, this also puts back the test expectations that #16446 changed in `TestQueryParser` and `QueryParserTestBase` (including the `multiTermGroup` hooks). The matches of those queries are not affected. If you would rather keep the grouped output and only split the group when `AND`/`OR` reaches it, I'm happy to rework it that way. Known limitation: `MultiFieldQueryParser` with per-field analyzers that drop different words in different fields is not covered. The clauses of the run then cover different fields, so they stay grouped. ### Testing - New `testStopwordBeforeOperator` in `TestQueryParser` and `TestMultiFieldQueryParser`. The test from the issue fails without the change and passes with it. - `./gradlew :lucene:queryparser:check` and `./gradlew check -x test` pass locally (JDK 25). - I also compared `setSplitOnWhitespace(false)` against `setSplitOnWhitespace(true)` for every query up to 6 symbols over `a b the AND OR NOT` (about 56k queries), for `QueryParser` and `MultiFieldQueryParser`. The number of queries that matched different documents went from 48 (default operator OR) and 66 (default operator AND) to 0. AI disclosure: this change and this description were prepared with the help of an AI coding assistant (Claude Code), in line with `AI_POLICY.md`. -- 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]
