SOLR-18256: Fix lucene QParser to support nested pure negative queries#4552
SOLR-18256: Fix lucene QParser to support nested pure negative queries#4552abumarjikar wants to merge 8 commits into
Conversation
dsmiley
left a comment
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.
|
Changes done as per review |
|
|
||
| // Nested pure negative query using explicit NOT syntax | ||
| assertJQ( | ||
| req("q", "v_t:pureneg AND v_t:foo AND (NOT v_t:bar)", "df", "v_t"), |
There was a problem hiding this comment.
This query still contains must clause. Could you please try assert with pure negative like {!bool must_not='{!term f=v_t v=bar}'} ?
There was a problem hiding this comment.
assertJQ(
req("q", "NOT v_t:pureneg", "df", "v_t", "fq", "type_t:negativetest"),
"/response/numFound==0");
This does check the similar i just restricted to my test documents. Please let me know if i still need to add another test.
dsmiley
left a comment
There was a problem hiding this comment.
Did you see Hoss's input in JIRA?
| @@ -0,0 +1,8 @@ | |||
| type: fixed | |||
There was a problem hiding this comment.
Your the first I've seen to put the 'type" first.
Pro-tip: don't generate this file yourself; have Gradle do it via ./gradlew writeChangelog.
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.