lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Swainston <>
Subject Grouping Clauses to Preserve Order of Boolean Precedence
Date Wed, 03 Aug 2011 13:26:20 GMT

I'm having trouble thinking of a way to effectively group clauses to form
sub queries. For example, I need to handle the following query:

Marketing AND Smith OR Davies.

Lucene is currently parsing this as  +Marketing +Smith Davies meaning that
results where only the term Davies is found are not returned. I want to be
able to apply the order of Boolean precedence so that this query is treated

(Marketing AND Smith) OR Davies.

The QueryParser will correctly parse the above query as (+Marketing +Smith)
Davies meaning that results where only Davies is found will be returned.

Is there a way within Lucene to apply this order of precedence? Currently
the only way I can think of is to manually add the brackets in the correct
place. However, this would become more difficult as the number of clauses
increases so I'm not sure how scalable this method would be.

How would I work out where to place the brackets if the query was something

Marketing AND Smith OR Davies OR Management OR Business AND

Can any suggest an effective way to group clauses so that the order of
Boolean precedence is preserved?

Thanks very much.


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message