Mailing List Archive

BooleanQuery: BooleanClause.Occur.MUST_NOT seems to require at least one BooleanClause.Occur.MUST
Hello Apache Lucene team members,
I have found that constructing a BooleanQuery with just a BooleanClause.Occur.MUST_NOT will return no results.  It will return results is if there is also a BooleanClause.Occur.MUST as part of the query as well though.


I don't see this limitation with a BooleanQuery with just a BooleanClause.Occur.MUST (i.e. results will return fine if they match).

Is this by design or is this an issue?

Thanks You,
Nissim Shiman
Re: BooleanQuery: BooleanClause.Occur.MUST_NOT seems to require at least one BooleanClause.Occur.MUST [ In reply to ]
Hi Nissim,

This is by design: boolean queries that don't have positive clauses like
empty boolean queries or boolean queries that only consist of negative
(MUST_NOT) clauses don't match any hits.

On Thu, Nov 5, 2020 at 9:07 PM Nissim Shiman <nshiman@yahoo.com.invalid>
wrote:

> Hello Apache Lucene team members,
> I have found that constructing a BooleanQuery with just
> a BooleanClause.Occur.MUST_NOT will return no results. It will return
> results is if there is also a BooleanClause.Occur.MUST as part of the query
> as well though.
>
>
> I don't see this limitation with a BooleanQuery with just
> a BooleanClause.Occur.MUST (i.e. results will return fine if they match).
>
> Is this by design or is this an issue?
>
> Thanks You,
> Nissim Shiman



--
Adrien
Re: BooleanQuery: BooleanClause.Occur.MUST_NOT seems to require at least one BooleanClause.Occur.MUST [ In reply to ]
Nissim:

Here’s a good explanation of why it was designed this way
if you’d like details:

https://lucidworks.com/post/why-not-and-or-and-not/

Don’t be put off by the Solr title, it’s really about
BooleanQuery and BooleanClause

Best,
Erick

> On Nov 6, 2020, at 8:17 AM, Adrien Grand <jpountz@gmail.com> wrote:
>
> Hi Nissim,
>
> This is by design: boolean queries that don't have positive clauses like
> empty boolean queries or boolean queries that only consist of negative
> (MUST_NOT) clauses don't match any hits.
>
> On Thu, Nov 5, 2020 at 9:07 PM Nissim Shiman <nshiman@yahoo.com.invalid>
> wrote:
>
>> Hello Apache Lucene team members,
>> I have found that constructing a BooleanQuery with just
>> a BooleanClause.Occur.MUST_NOT will return no results. It will return
>> results is if there is also a BooleanClause.Occur.MUST as part of the query
>> as well though.
>>
>>
>> I don't see this limitation with a BooleanQuery with just
>> a BooleanClause.Occur.MUST (i.e. results will return fine if they match).
>>
>> Is this by design or is this an issue?
>>
>> Thanks You,
>> Nissim Shiman
>
>
>
> --
> Adrien


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: BooleanQuery: BooleanClause.Occur.MUST_NOT seems to require at least one BooleanClause.Occur.MUST [ In reply to ]
Thank You Erick and Adrien!
On Friday, November 6, 2020, 08:43:59 AM EST, Erick Erickson <erickerickson@gmail.com> wrote:

Nissim:

Here’s a good explanation of why it was designed this way
if you’d like details:

https://lucidworks.com/post/why-not-and-or-and-not/

Don’t be put off by the Solr title, it’s really about
BooleanQuery and BooleanClause

Best,
Erick

> On Nov 6, 2020, at 8:17 AM, Adrien Grand <jpountz@gmail.com> wrote:
>
> Hi Nissim,
>
> This is by design: boolean queries that don't have positive clauses like
> empty boolean queries or boolean queries that only consist of negative
> (MUST_NOT) clauses don't match any hits.
>
> On Thu, Nov 5, 2020 at 9:07 PM Nissim Shiman <nshiman@yahoo.com.invalid>
> wrote:
>
>> Hello Apache Lucene team members,
>> I have found that constructing a BooleanQuery with just
>> a BooleanClause.Occur.MUST_NOT will return no results.  It will return
>> results is if there is also a BooleanClause.Occur.MUST as part of the query
>> as well though.
>>
>>
>> I don't see this limitation with a BooleanQuery with just
>> a BooleanClause.Occur.MUST (i.e. results will return fine if they match).
>>
>> Is this by design or is this an issue?
>>
>> Thanks You,
>> Nissim Shiman
>
>
>
> --
> Adrien


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: BooleanQuery: BooleanClause.Occur.MUST_NOT seems to require at least one BooleanClause.Occur.MUST [ In reply to ]
Hi,

Finally, to "fix" it so it behaves like you may want it: just add a MatchAllDocsQuery as MUST or SHOULD clause. You have full control on how it behaves!

Uwe

Am November 6, 2020 6:05:03 PM UTC schrieb Nissim Shiman <nshiman@yahoo.com.INVALID>:
> Thank You Erick and Adrien!
>On Friday, November 6, 2020, 08:43:59 AM EST, Erick Erickson
><erickerickson@gmail.com> wrote:
>
> Nissim:
>
>Here’s a good explanation of why it was designed this way
>if you’d like details:
>
>https://lucidworks.com/post/why-not-and-or-and-not/
>
>Don’t be put off by the Solr title, it’s really about
>BooleanQuery and BooleanClause
>
>Best,
>Erick
>
>> On Nov 6, 2020, at 8:17 AM, Adrien Grand <jpountz@gmail.com> wrote:
>>
>> Hi Nissim,
>>
>> This is by design: boolean queries that don't have positive clauses
>like
>> empty boolean queries or boolean queries that only consist of
>negative
>> (MUST_NOT) clauses don't match any hits.
>>
>> On Thu, Nov 5, 2020 at 9:07 PM Nissim Shiman
><nshiman@yahoo.com.invalid>
>> wrote:
>>
>>> Hello Apache Lucene team members,
>>> I have found that constructing a BooleanQuery with just
>>> a BooleanClause.Occur.MUST_NOT will return no results.  It will
>return
>>> results is if there is also a BooleanClause.Occur.MUST as part of
>the query
>>> as well though.
>>>
>>>
>>> I don't see this limitation with a BooleanQuery with just
>>> a BooleanClause.Occur.MUST (i.e. results will return fine if they
>match).
>>>
>>> Is this by design or is this an issue?
>>>
>>> Thanks You,
>>> Nissim Shiman
>>
>>
>>
>> --
>> Adrien
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>For additional commands, e-mail: java-user-help@lucene.apache.org
>

--
Uwe Schindler
Achterdiek 19, 28357 Bremen
https://www.thetaphi.de