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 Bram Van Dam <br...@intix.eu> on 2017/07/04 13:04:36 UTC

Strange boolean query behaviour on 5.5.4

Hey folks,

I'm experiencing some strange query behaviour, and it isn't immediately
clear to me why this wouldn happen. The definition of the query syntax
on the wiki is a bit fuzzy, so my interpretation of the syntax might be off.

This query does work (no results, when results are expected).

(-someField:Foo) AND (otherField: (Bar OR Baz))

With debug enabled, Solr interprets the query as

+(-someField:Foo) +(otherField:Bar otherField:Baz)

This query DOES work, results are returned.

-someField:Foo +(otherField:Bar otherField:Baz)

With debug enabled:

-someField:Foo +(otherField:Bar otherField:Baz)


The only difference between these queries is the presence of parantheses
around the field with a single NOT condition. From a boolean point of
view, they are equivalent.

To make matters stranger, if I add a *:* clause to the NOT field,
everything works again.

(-someField:Foo AND *:*) AND (otherField: (Bar OR Baz))
and
-someField:Foo AND *:* AND (otherField: (Bar OR Baz))
both work.

Is this is query parser bug? Or are parenthesized groups with a single
negated expression not supported? :-/

I've only tested this on 5.5.4 using the default query parser, I don't
have access to any other versions at the moment.

Thanks for any insights,

 - Bram

Re: Strange boolean query behaviour on 5.5.4

Posted by Bram Van Dam <br...@intix.eu>.
On 04/07/17 18:10, Erick Erickson wrote:
> I think you'll get what you expect by something like:
> (*:* -someField:Foo) AND (otherField: (Bar OR Baz))

Yeah that's what I figured. It's not a big deal since we generate Solr
syntax using a parser/generator on top of our own query syntax. Still a
little strange!

Thanks for the heads up,

 - Bram

Re: Strange boolean query behaviour on 5.5.4

Posted by Erick Erickson <er...@gmail.com>.
First of all, Solr doesn't implement strict boolean logic, see Hoss'
explanation here:
https://lucidworks.com/2011/12/28/why-not-and-or-and-not/

And bare "not" operators are a pain. There's actually _some_ trickery
_some_ places
to help you out (fq clauses come to mind) and prepend *:* for you.

I think you'll get what you expect by something like:
(*:* -someField:Foo) AND (otherField: (Bar OR Baz))

Best,
Erick

On Tue, Jul 4, 2017 at 6:04 AM, Bram Van Dam <br...@intix.eu> wrote:
> Hey folks,
>
> I'm experiencing some strange query behaviour, and it isn't immediately
> clear to me why this wouldn happen. The definition of the query syntax
> on the wiki is a bit fuzzy, so my interpretation of the syntax might be off.
>
> This query does work (no results, when results are expected).
>
> (-someField:Foo) AND (otherField: (Bar OR Baz))
>
> With debug enabled, Solr interprets the query as
>
> +(-someField:Foo) +(otherField:Bar otherField:Baz)
>
> This query DOES work, results are returned.
>
> -someField:Foo +(otherField:Bar otherField:Baz)
>
> With debug enabled:
>
> -someField:Foo +(otherField:Bar otherField:Baz)
>
>
> The only difference between these queries is the presence of parantheses
> around the field with a single NOT condition. From a boolean point of
> view, they are equivalent.
>
> To make matters stranger, if I add a *:* clause to the NOT field,
> everything works again.
>
> (-someField:Foo AND *:*) AND (otherField: (Bar OR Baz))
> and
> -someField:Foo AND *:* AND (otherField: (Bar OR Baz))
> both work.
>
> Is this is query parser bug? Or are parenthesized groups with a single
> negated expression not supported? :-/
>
> I've only tested this on 5.5.4 using the default query parser, I don't
> have access to any other versions at the moment.
>
> Thanks for any insights,
>
>  - Bram