skip empty BooleanQuery with Occur=SHOULD#4475
Conversation
| Query query = clause.getKey().getQuery(); | ||
| Occur occur = clause.getValue(); | ||
|
|
||
| if (occur == Occur.SHOULD && query instanceof BooleanQuery boolQ && boolQ.clauses().isEmpty()) { |
There was a problem hiding this comment.
this string of conditions looks very hacky. Reading the description... I thought there was going to be a null somewhere to check for?
There was a problem hiding this comment.
I can only work with what the LuceneQParser returns, and in this case it is a BooleanQuery with an empty List of clauses. And as I understand it, I can only safely drop a Query with an empty list of clauses if it is a SHOULD. I do not see any attribute on BooleanQuery I could check for null.
There was a problem hiding this comment.
The description says:
org.apache.solr.search.join.FiltersQParser#parseImpl can return empty-queries
If you dig deeper... this isn't a fault/problem of FiltersQParser specifically or that method, it's that broadly, any QParser parse() may return either null or return an empty BooleanQuery. It'd be great if you pursue fixing that. But I don't think FiltersQParser needs a modification.
| } | ||
|
|
||
| @Test | ||
| public void testMinShouldMatchWithEmptyClauseCausedByStopWord() throws Exception { |
There was a problem hiding this comment.
test fails: undefined field name_sw
@dsmiley
This is a follow up of #4406
I realized that the minimum match expression like mm=-1 does not work properly if one should-clause is entirely removed by the analyzer, e.g. it only contains stopwords.
The root cause is that org.apache.solr.search.join.FiltersQParser#parseImpl can return empty-queries.
Given you comment on that method added quite recently, I am not sure if this is the right approach, but this change would fix the root of the issue. Alternatively I could just filter them out in the BoolQParserPlugin.
Do you know if such the empty clauses should only be filtered out if mmAutoRelax==true? If that is the case I need to do it in BoolQParserPlugin anyway.
Thanks