SOLR-18256: Fix lucene QParser to support nested pure negative queries#4552
Open
abumarjikar wants to merge 1 commit into
Open
SOLR-18256: Fix lucene QParser to support nested pure negative queries#4552abumarjikar wants to merge 1 commit into
abumarjikar wants to merge 1 commit into
Conversation
dsmiley
reviewed
Jun 26, 2026
dsmiley
left a comment
Contributor
There was a problem hiding this comment.
This should enable broad improvements across tests where a silly *:* is present next to a negative clause. Maybe not that many tests to update but still. Perhaps even the ref guide has a reference. Please search for the pattern. I suggest waiting until after your #4512 to avoid merge conflicts.
Comment on lines
+31
to
+34
| @Override | ||
| protected Query getBooleanQuery(List<BooleanClause> clauses) throws SyntaxError { | ||
| return QueryUtils.makeQueryable(super.getBooleanQuery(clauses)); | ||
| } |
Contributor
There was a problem hiding this comment.
wow... boy this was simple.
| } | ||
| } | ||
|
|
||
| @Test |
Contributor
There was a problem hiding this comment.
I am not seeing here a pure negative query... you've put a MUST clause on each one.
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.
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
luceneQParser evaluate incorrectly (resulting in 0 matching documents). By overridinggetBooleanQueryinSolrQueryParser, we now safely applyQueryUtils.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
SolrQueryParserto overridegetBooleanQuery(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 generatedBooleanQuerycontains only prohibited (negative) clauses,QueryUtils.makeQueryable()automatically wraps or balances it against aMatchAllDocsQuery, restoring expected Lucene/Solr negation behavior seamlessly across nested parenthesized groups.Tests
testNestedPureNegativeQueryinsidesolr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java.AND (-field:val)andAND (NOT field:val)syntax variations against an isolated set of unique test documents.sortparameter (id asc) to circumvent score weighting conflicts during JSON response validation.Checklist
Please review the following and check all that apply:
mainbranch../gradlew check.