You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Jochen Barth <ba...@ub.uni-heidelberg.de> on 2020/05/21 18:25:21 UTC

+(-...) vs +(*:* -...) vs -(+...)

Dear reader,

why does +(-x_ss:y) finds 0 docs,

while -(+x_ss:y) finds many docs?

Ok... +(*:* -x_ss:y) works, too, but I'm a bit surprised.

Kind regards, J. Barth


Re: +(-...) vs +(*:* -...) vs -(+...)

Posted by Bram Van Dam <br...@intix.eu>.
Additional reading: https://lucidworks.com/post/why-not-and-or-and-not/

Assuming implicit AND, we perform the following rewrite on strictly
negative queries:

-f:a -> -f:a *:*

Isn't search fun? :-)

 - Bram


On 21/05/2020 20:51, Houston Putman wrote:
> Jochen,
> 
> For the standard query parser, pure negative queries (no positive query in
> front of it, such as "*:*") are only allowed as a top level clause, so not
> nested within parenthesis.
> 
> Check the second bullet point of the this section of the Ref Guide page for
> the Standard Query Parser.
> <https://lucene.apache.org/solr/guide/8_5/the-standard-query-parser.html#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser>
> 
> For the edismax query parser, pure negative queries are allowed to be
> nested within parenthesis. Docs can be found in the Ref Guide page for the
> eDismax Query Parser.
> <https://lucene.apache.org/solr/guide/8_5/the-extended-dismax-query-parser.html>
> 
> - Houston
> 
> On Thu, May 21, 2020 at 2:25 PM Jochen Barth <ba...@ub.uni-heidelberg.de>
> wrote:
> 
>> Dear reader,
>>
>> why does +(-x_ss:y) finds 0 docs,
>>
>> while -(+x_ss:y) finds many docs?
>>
>> Ok... +(*:* -x_ss:y) works, too, but I'm a bit surprised.
>>
>> Kind regards, J. Barth
>>
>>
> 


Re: +(-...) vs +(*:* -...) vs -(+...)

Posted by Houston Putman <ho...@gmail.com>.
Jochen,

For the standard query parser, pure negative queries (no positive query in
front of it, such as "*:*") are only allowed as a top level clause, so not
nested within parenthesis.

Check the second bullet point of the this section of the Ref Guide page for
the Standard Query Parser.
<https://lucene.apache.org/solr/guide/8_5/the-standard-query-parser.html#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser>

For the edismax query parser, pure negative queries are allowed to be
nested within parenthesis. Docs can be found in the Ref Guide page for the
eDismax Query Parser.
<https://lucene.apache.org/solr/guide/8_5/the-extended-dismax-query-parser.html>

- Houston

On Thu, May 21, 2020 at 2:25 PM Jochen Barth <ba...@ub.uni-heidelberg.de>
wrote:

> Dear reader,
>
> why does +(-x_ss:y) finds 0 docs,
>
> while -(+x_ss:y) finds many docs?
>
> Ok... +(*:* -x_ss:y) works, too, but I'm a bit surprised.
>
> Kind regards, J. Barth
>
>

Re: +(-...) vs +(*:* -...) vs -(+...)

Posted by Shawn Heisey <ap...@elyograg.org>.
On 5/21/2020 12:25 PM, Jochen Barth wrote:
> why does +(-x_ss:y) finds 0 docs,
> 
> while -(+x_ss:y) finds many docs?
> 
> Ok... +(*:* -x_ss:y) works, too, but I'm a bit surprised.

Purely negative queries, if that is what ultimately makes it to Lucene, 
do not work.

The basic problem is that if you start with nothing and then subtract 
something, you get nothing.

When a purely negative query that's VERY simple is provided, Solr is 
able to detect the situation and implicitly add a starting point of all 
docs.  You'll probably find that the following query (which is missing 
the parentheses compared to your first example) will work because Solr 
is capable of detecting and fixing the problem itself:

-x_ss:y

With parentheses the query is too complex for the detection I described 
to work, and the constructed Lucene query remains purely negative.

Your third example is the correct way to construct a purely negative 
query so that it is guaranteed to work.

We have created a wiki page about this:

https://cwiki.apache.org/confluence/display/SOLR/NegativeQueryProblems

Thanks,
Shawn