Thanks Shawn! I was not thinking of it as a subtraction but it makes all the sense put like that.
On 8 May 2018 at 17:55, Shawn Heisey <apa...@elyograg.org> wrote: > On 5/8/2018 4:02 AM, Alfonso Noriega wrote: > >> I found solr 5.5.4 is doing some unexpected behavior (at least >> unexpected >> for me) when using Must and Must not operator and parenthesis for >> filtering >> and it would be great if someone can confirm if this is unexpected or not >> and why. >> > > <snip> > > Do you have any idea why is this happening? >> > > I'm surprised ANY of those examples are working. While the bug that Erick > mentioned could be a problem, I think this is happening because you've got > a multi-clause pure negative query. All query clauses have NOT attached to > them. Purely negative queries do not actually work. > > The reason negative queries don't work is that if you start with nothing > and then start subtracting things, you end up with nothing. > > To properly work, the first example would need to be written like this: > > *:* AND NOT(status:"DELETED") AND (*:* AND NOT(length:[1860000+TO+3659999]) > AND NOT(length:[3660000+TO+*])) > > I have added the all documents query as the starting point for both major > clauses, so that the subtraction (AND NOT) has something to subtract from. > Some of those parentheses are unnecessary, but I have preserved them in the > rewritten query.Without unnecessary parentheses/quotes, the query would > look like this: > > *:* AND NOT status:DELETED AND (*:* AND NOT length:[1860000+TO+3659999] > AND NOT length:[3660000+TO+*]) > > You might be wondering why something like "fq=-status:DELETED" will work > even though it's a purely negative query. This works because with a > super-simple query like that, Solr is able to detect the unworkable > situation and automatically fix it by adding the all-docs starting point > behind the scenes. The example you gave is too complicated for Solr's > detection to work, so it doesn't get fixed. > > Thanks, > Shawn > > -- -- Alfonso Noriega Software engineer Redlink GmbH e: alfonso.nori...@redlink.co <sergio.fernan...@redlink.co> w: http://redlink.co