lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <>
Subject Re: Suspected problem in the QueryParser
Date Fri, 03 Nov 2006 19:50:19 GMT

: When I enter the query: "Table AND NOT Chair"  I get one hit, doc3
: When I enter the query: "Table AND (NOT Chair)" I get 0 hits.
: I had thought that both queries would return the same results.  Is this a
: bug, or, am I not understanding the query language correctly?

it's a confusing eccentricity of the QueryParser syntax ... as a general
rule, thing in parens need to be self contained, effective, queries ... if
you have something in parens which would not make sense as a query by
itself, then it won't make any more sense as part of a larger query.

In your case, the query "  NOT Chair " is the problem ... you can't have
a negative clause in isolation by itself -- it doesn't make sense because
there isn't anything positively selecting results for you to then exclude
results from.

As a side not: i strongly encourage you to train yourself to think in
terms of MUST, MUST_NOT and SHOULD (which are represented in the query
parser as the prefixes "+", "-" and the default) instead of in terms of
AND, OR, and NOT ... Lucene's BooleanQuery (and thus Lucene's QueryParser)
is not a strict Boolean Logic system, so it's best not to try and think
of it like one.


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

View raw message