lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <>
Subject Re: What is the difference between these searches?
Date Tue, 09 Nov 2004 21:48:26 GMT

On Nov 9, 2004, at 2:58 PM, Luke Francl wrote:
> I recently realized that my implementation of "OR NOT" was not working
> as I would expect and I was wondering if anyone on this list could give
> me some advice.

Lucene's BooleanQuery does not really have the concept of OR NOT.  It's 
really an AND NOT.

> I am converting a query that means "foo or not bar" into the following:
> +item_type:xyz +(field_name:foo -field_name:bar)
> This returns only Documents where field_name contains foo. I would
> expect it to return all the Documents where field_name contains foo or
> field_name doesn't contain bar.

What you experienced is how Lucene operates.  It's more of a fail-safe 
mode because doing pure NOT queries is more likely to get out of 

> Fiddling around with the Lucene Index Toolbox, I think that this query
> does what I want:
> +item_type:xyz field_name:foo -field_name:bar
> Can someone explain to me why these queries return different results?

This last query has a required clause, which is what BooleanQuery 
requires when there is a NOT clause.  You're getting what you want here 
because you've got an item_type:xyz clause as required.  In your first 
example, you're requiring field_name:foo, whereas in this one it is not 


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

View raw message