Skip to content

skip empty BooleanQuery with Occur=SHOULD#4475

Open
renatoh wants to merge 2 commits into
apache:mainfrom
renatoh:handling_empty_queries_in_FiltersQParser
Open

skip empty BooleanQuery with Occur=SHOULD#4475
renatoh wants to merge 2 commits into
apache:mainfrom
renatoh:handling_empty_queries_in_FiltersQParser

Conversation

@renatoh
Copy link
Copy Markdown
Contributor

@renatoh renatoh commented May 29, 2026

@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

Query query = clause.getKey().getQuery();
Occur occur = clause.getValue();

if (occur == Occur.SHOULD && query instanceof BooleanQuery boolQ && boolQ.clauses().isEmpty()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this string of conditions looks very hacky. Reading the description... I thought there was going to be a null somewhere to check for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test fails: undefined field name_sw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants