abumarjikar opened a new pull request, #4552: URL: https://github.com/apache/solr/pull/4552
https://issues.apache.org/jira/browse/SOLR-18256 # Description This pull request addresses a long-standing limitation where nested pure negative (NOT) queries wrapped in parentheses or sub-expressions inside the `lucene` QParser evaluate incorrectly (resulting in 0 matching documents). By overriding `getBooleanQuery` in `SolrQueryParser`, we now safely apply `QueryUtils.makeQueryable()` on every boolean group built during the parsing cycle. This correctly transforms and executes both top-level and nested pure negative sub-expressions as expected. # Solution Modified `SolrQueryParser` to override `getBooleanQuery(List<BooleanClause> clauses)`. Instead of relying purely on top-level query transformations to fix pure negative clauses, the parser now intercepts every boolean group built during syntax processing. If a generated `BooleanQuery` contains only prohibited (negative) clauses, `QueryUtils.makeQueryable()` automatically wraps or balances it against a `MatchAllDocsQuery`, restoring expected Lucene/Solr negation behavior seamlessly across nested parenthesized groups. # Tests * Integrated a dedicated behavioral test case `testNestedPureNegativeQuery` inside `solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java`. * Verified top-level and nested pure negative behavior under standard parenthesized groups using explicit `AND (-field:val)` and `AND (NOT field:val)` syntax variations against an isolated set of unique test documents. * Ensured reliable query assertions by introducing an explicit `sort` parameter (`id asc`) to circumvent score weighting conflicts during JSON response validation. # Checklist Please review the following and check all that apply: - [X] I have reviewed the guidelines for [How to Contribute](https://github.com/apache/solr/blob/main/CONTRIBUTING.md) and my code conforms to the standards described there to the best of my ability. - [X] I have created a Jira issue and added the issue ID to my pull request title. - [X] I have given Solr maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation) - [X] I have developed this patch against the `main` branch. - [X] I have run `./gradlew check`. - [X] I have added tests for my changes. - [ ] I have added documentation for the [Reference Guide](https://github.com/apache/solr/tree/main/solr/solr-ref-guide) - [X] I have added a [changelog entry](https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc) for my change -- 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]
