Hi

I'm not sure if this is a bug or working as designed. In BooleanQuery, one
can set the minimum number of SHOULD match terms. So if I send the query
"abc +def" and set it to 1, only if "abc" has matches in the index I should
get back results.
However, if I send the query "+def" and set the minimum to 1, I get back
results, even though I don't have any SHOULD terms in the query. However, if
I send the query "+abc +def" and set the minimum to 1, I get back 0 results,
as expected.
I think this is actually a bug, mostly because the inconsistencies of "+abc
+def" and "+def" with the minimum set to 1.

The reason lies in BooleanQuery.rewrite, followed by Query.scorer.
BooleanQuery.rewrite has an optimization that if the number of clauses is 1
(as is in "+def"), the query returned is clauses(0).getQuery().rewrite(),
which in this case is TermQuery. However, if the number of clauses is
greater than 1, the query returned is the BooleanQuery with all of its
clauses rewritten.
Then, the searcher calls query.scorer.
In the first case ("+def"), TermQuery.scorer is not aware of the minimum
number should match constraint.
In the second ("+abc +def"), BooleanQuery.scorer returns a BooleanScorer2,
which does handle the minimum number should match constraint.

I think that a patch is pretty straight-forward, and I'll open an issue and
provide the patch once you confirm this is indeed a bug.

Cheers,

Shai Erera

Reply via email to