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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Jochen Barth
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

Reply | Threaded
Open this post in threaded view
|

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

Shawn Heisey-2
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
Reply | Threaded
Open this post in threaded view
|

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

Houston Putman
In reply to this post by Jochen Barth
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 <[hidden email]>
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
>
>
Reply | Threaded
Open this post in threaded view
|

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

Bram Van Dam
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 <[hidden email]>
> 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
>>
>>
>