Thanks Ian. How would you achieve the logic of the below query using BooleanQuery and BooleanClause.occur? How would you achieve the grouping effect?
(Marketing AND Smith) OR Davies Thanks a lot. Jim On 3 August 2011 14:54, Ian Lea <ian....@gmail.com> wrote: > I don't think there is an easy way. Brackets are the official way to > do it with the query parser: > http://lucene.apache.org/java/3_3_0/queryparsersyntax.html#Grouping > > For anything non-trivial I prefer to build up queries in code using > BooleanQuery. That way it is comparatively easy to build in whatever > logic you need with BooleanClause.Occur. > > > There are alternative parsers in contrib. They might have more > support for grouping clauses. > > > > -- > Ian. > > > On Wed, Aug 3, 2011 at 2:26 PM, Jim Swainston > <jimswains...@googlemail.com> wrote: > > Hi, > > > > 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 > > as: > > > > (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 > > like: > > > > Marketing AND Smith OR Davies OR Management OR Business AND > > Science.........? > > > > Can any suggest an effective way to group clauses so that the order of > > Boolean precedence is preserved? > > > > Thanks very much. > > > > Jim > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org > >