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 Mark D Sievers <ma...@gmail.com> on 2011/12/02 18:47:28 UTC

Simplification of boolean query failed

I've put the question nicely formatted on StackOverflow here
http://stackoverflow.com/questions/8360257/solr-lucene-why-is-this-or-query-failing-when-the-two-individual-queries-suc

Here is that question Verbatim:

I have a Solr document schema with with a solr.TrieDateField and noticed
this boolean query (not authored by me) which I thought could benefit from
some simplification;

q=-(-event_date:[2011-12-02T00:00:00.000Z TO NOW/DAY+90DAYS] OR
(event_date:[* TO *]))

which means *events within the next 90 days or non-events* (See Pure
Negative<http://wiki.apache.org/solr/SolrQuerySyntax#Differences_From_Lucene_Query_Parser>for
Solr boolean
NOT notation) . My simplification looked like

q=event_date:[2011-12-02T00:00:00.000Z TO NOW/DAY+90DAYS] OR
-event_date:[* TO *]

As stated, this didn't work (0 results). So as a test I ran the two sides
of the OR query individually and the sum of the two results (both non-zero)
equaled the sum of the original query and I can't come up with a good
explanation why. Running with debugQuery=true didn't present anything
helpful.
Thanks,

Mark

Re: Simplification of boolean query failed

Posted by Chris Hostetter <ho...@fucit.org>.
: Right, the Solr/Lucene query syntax isn't true Boolean logic, so
: applying all the neat DeMorgan's rules is sometimes surprising.

And more specificly, mixing "boolean" operators (AND/OR) with prefix 
operators (+/-) is a recipe for disaster.  In an expression like this..

	XXX OR -YYY

...the "OR" fights against the "-" to modify the "BooleanClause.Occur" on 
the YYY clause -- something that should have been apparent in the 
debugQUery toString info.

-Hoss

Re: Simplification of boolean query failed

Posted by Erick Erickson <er...@gmail.com>.
Right, the Solr/Lucene query syntax isn't true Boolean logic, so
applying all the neat DeMorgan's rules is sometimes surprising.

The first form take all records with event dates or that fall outside your range
and inverts the results.

The second selects all documents that fall in the indicated date range
and removes all documents from that set that have dates.

If your second clause were something like (*:* -event_date:[* TO *]) I think
you'd get what you expect.

Best
Erick

On Fri, Dec 2, 2011 at 12:47 PM, Mark D Sievers <ma...@gmail.com> wrote:
> I've put the question nicely formatted on StackOverflow here
> http://stackoverflow.com/questions/8360257/solr-lucene-why-is-this-or-query-failing-when-the-two-individual-queries-suc
>
> Here is that question Verbatim:
>
> I have a Solr document schema with with a solr.TrieDateField and noticed
> this boolean query (not authored by me) which I thought could benefit from
> some simplification;
>
> q=-(-event_date:[2011-12-02T00:00:00.000Z TO NOW/DAY+90DAYS] OR
> (event_date:[* TO *]))
>
> which means *events within the next 90 days or non-events* (See Pure
> Negative<http://wiki.apache.org/solr/SolrQuerySyntax#Differences_From_Lucene_Query_Parser>for
> Solr boolean
> NOT notation) . My simplification looked like
>
> q=event_date:[2011-12-02T00:00:00.000Z TO NOW/DAY+90DAYS] OR
> -event_date:[* TO *]
>
> As stated, this didn't work (0 results). So as a test I ran the two sides
> of the OR query individually and the sum of the two results (both non-zero)
> equaled the sum of the original query and I can't come up with a good
> explanation why. Running with debugQuery=true didn't present anything
> helpful.
> Thanks,
>
> Mark