lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <>
Subject RE: Boolean OR does not work as described
Date Tue, 03 Jan 2012 16:31:08 GMT
Hi Mike,

if you want to mix and/or in one query, always use parenthesis. The operator precedence is
strange with the default query parser. In contrib there is another one (called PrecedenceQueryParser)
that can handle this but is incompatible with existing queries. The parser in contrib on the
other hand also has other problems, which are all caused by the way how Lucene handles BooleanQuery

If you print the parsed query using Query.toString() you can see the "normalized" query in
standard Lucene syntax. Lucene does not know AND/OR, it only knows query clauses that are
SHOULD (=optional), MUST or MUST_NOT. The query "vorgklasse:au AND schluessel:13????? OR schluessel:23?????"
will be parsed like:

MUST: vorgklasse:au
MUST: schluessel:13?????
SHOULD: schluessel:23?????

Which would be in standard syntax: "+vorgklasse:au +schluessel:13????? schluessel:23?????"
(first two are MUST clauses, third is should). If you read this query using MUST/SHOULD you
will understand what happens: This means the first 2 terms MUST be in the result, the third
MIGHT be in the result. So it's not an union, it's something more complex :-)

Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen

> -----Original Message-----
> From: []
> Sent: Tuesday, January 03, 2012 4:41 PM
> To:
> Subject: Boolean OR does not work as described
> Hi folks,
> I have a query result problem I do not understand. The documentation for
> Lucene 3.2 query syntax says the following about boolean OR queries: "The OR
> operator links two terms and finds a matching document if either of the terms
> exist in a document. This is equivalent to a union using sets."
> I have performed several queries on my index and the output does not reflect
> the description. I always get the first-wins-set instead of a united set.
> These are my separate test results:
> 1. schluessel:23????? => 286 documents
> 2. vorgklasse:au AND schluessel:13????? => 2532 documents
> If I do:
> vorgklasse:au AND schluessel:13????? OR schluessel:23?????
> It should unite both sets and output them. I still get 2532 documents back.
> Exactly those from the second query.
> Am I not supposed to get 2532 + 286 = 2818? This is what I expect as result set.
> Am I missing something here? If I group the query like this (vorgklasse:au AND
> sch
> luessel:13?????) OR schluessel:23????? I do get the expected result. But both
> queries should be equivalent.
> Thanks,
> Mike
> PS: search output is avaible as CSV at request
> --
> NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
> Jetzt informieren:
> --
> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie
> mit bis zu 50,- Euro!
> --
> NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
> Jetzt informieren:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message