lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Bayly <>
Subject Translating Lucene Query Syntax to Traditional Boolean Syntax
Date Tue, 25 Sep 2007 01:05:11 GMT

We have an application that performs searches against a Lucene based index
and also against a Windows Desktop Search based index.

For simple queries we'd like to offer our users a consistent interface that
allows them to build basic Lucene style queries using the 'MUST HAVE' (+),
'MUST NOT HAVE' (-) and 'SHOULD HAVE' style of operators as this is probably
more intuitive for non 'Boolean Logic' literate users.  We would not allow
them to use any grouping (parenthesis).

Clearly we can pass this directly to Lucene, but for the Windows Desktop
Search we need to translate the Lucene style query into a more traditional
Boolean query.  So this is the opposite of the much discussed Boolean Query
to Lucene Query conversion.

I'm wondering if anyone has ever done this or whether there is a concept
mismatch in there somewhere that will make it difficult to do?

My thought was that you could take the standard Lucene operators and simply
group them together as follows:

e.g. (assuming the Lucene default OR operator)

Lucene: +a +b -c -d e f

would translate to:

(a AND b NOT c NOT d) OR (a AND b NOT c NOT d AND (e OR f))

If I put this back into Lucene (actually Lucene.NET but hopefully its the
same) I get back:

(+a +b -c -d)(+a +b -c -d +(e f))

which I think is equivalent but not as concise!  But I have not tested this
against a big index to see if it's equivalent and I have a suspicion that
Lucene might score the two versions of the Lucene representation
differently.  But that's probably not an issue provided the Boolean
representation is semantically equivalent to the first Lucene

Anyone ever tried this before or have any comments on whether my 'logic' is

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

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

View raw message