lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack Krupansky" <>
Subject Re: Question about BooleanQuery
Date Thu, 23 Aug 2012 12:29:36 GMT
Step 1, fully parenthesize your boolean to show your desired order of 
execution. The Lucene BooleanQuery does not do a pure Boolean evaluation. 
You have the same sub-expression in your NOT clause - that's probably what 
guarantees zero results. And you have an unmatched right parenthesis at the 

Lucene BooleanQuery uses "SHOULD" (for "OR"), "MUST" (for "AND"), and 
"MUST_NOT" ("NOT"). Very similar to a true Boolean expression except that 
the clauses at any level of expression are not evaluated in order or AND/OR 
precedence. If you need strict evaluation order, use parentheses (or 
multi-level BooleanQuery at the Lucene Query level.)

Read more detail at:

-- Jack Krupansky

-----Original Message----- 
From: heikki
Sent: Thursday, August 23, 2012 8:09 AM
Subject: Question about BooleanQuery


I'm trying to construct a boolean query, but can't get it to return the
results that I intend. Does anyone see what I'm doing wrong ?

The query is like

The idea is that it should return documents where

someField_1 = 0 OR someField_2 = 0 AND booleanField_1 = false BUT NOT (
someField_1 = 0 OR someField_2 = 0) AND booleanField_2 = true )

The problem seems to be with the BUT NOT part of the query. I get no
results, even though I would have expected so (and I've checked the index
contents with Luke).

Any ideas most welcome ..
Kind regards
Heikki Doeleman

View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail: 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message