[
https://issues.apache.org/jira/browse/SOLR-18256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18082672#comment-18082672
]
David Smiley commented on SOLR-18256:
-------------------------------------
AI plan:
----
Summary: Fix SolrQueryParser to wrap negative queries with MatchAllDocsQuery
Description:
When the lucene query parser processes a negative query — one where all boolean
clauses are prohibited, such as {{NOT bar}} or {{foo AND (NOT bar)}} — the
resulting {{BooleanQuery}} matches no documents. The fix is to insert a
{{MatchAllDocsQuery}} as a MUST clause so the query correctly returns all
documents minus the excluded ones.
{{SolrIndexSearcher}} compensates for top-level negative queries at execution
time via {{{}QueryUtils.makeQueryable(){}}}, so top-level cases accidentally
work. However, nested sub-expressions (parenthesized groups within a larger
query, e.g. {{{}foo AND (NOT bar){}}}) are built during parsing and never pass
through that compensation path — they silently match nothing.
{{ExtendedDismaxQParser}} already avoids this by overriding
{{getBooleanQuery()}} in its inner {{ExtendedSolrQueryParser}} class.
{{{}SolrQueryParser{}}}, the base used by {{{}LuceneQParser{}}}, has no such
safeguard.
*Proposed Fix:*
Override {{getBooleanQuery(List<BooleanClause> clauses)}} in
{{SolrQueryParser}} to apply {{QueryUtils.makeQueryable()}} on every boolean
group built during parsing, fixing both top-level and nested sub-expression
negative queries:
{code:java}
@Override
protected Query getBooleanQuery(List<BooleanClause> clauses) throws SyntaxError
{
return QueryUtils.makeQueryable(super.getBooleanQuery(clauses));
}
{code}
{{makeQueryable()}} is idempotent, so calling it again at execution time in
{{SolrIndexSearcher}} is harmless.
*Files to Change:*
- {{solr/core/src/java/org/apache/solr/search/SolrQueryParser.java}} — add
override
- {{solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java}} — add
behavioral test executing negative queries as sub-expressions
Acceptance Criteria:
- Querying with {{NOT bar}} or {{(NOT bar)}} via the lucene parser returns all
documents except those matching {{{}bar{}}}, both at top-level and as a
sub-expression
- Existing {{QueryEqualityTest}} and {{TestSolrQueryParser}} tests continue to
pass
- {{ExtendedDismaxQParser}} behavior is unchanged
> Auto-fix pure negative (NOT) clauses in the "lucene" QParser
> ------------------------------------------------------------
>
> Key: SOLR-18256
> URL: https://issues.apache.org/jira/browse/SOLR-18256
> Project: Solr
> Issue Type: Improvement
> Reporter: David Smiley
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]