My Apologies Hoss, perhaps I should have been clearer. I'm trying to programatically build a BooleanQuery from text input. I want the BooleanQuery that is built to have the correct structure based on the precedence rules of Boolean Logic.
So if the Text input is: Marketing AND Smith OR Davies I want my program to work out that this should be grouped as the following (as AND has higher precedence than OR): (Marketing AND Smith) OR Davies. I'm effectively looking for an algorithm that will properly group any number of terms...... Thanks Jim On 4 August 2011 16:47, Chris Hostetter <hossman_luc...@fucit.org> wrote: > > : But the query parser doesn't seem to do that for me with the input > Marketing > : AND Smith OR Davies. The query parser gives me 3 clauses. 1 must clause > for > > i didn't say the QueryParser would do that with *that* input > > You asked... > > : > : 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 > > ...and i said... > > : > The same way the query parser does: that's a BooleanQuery (A) with two > : > "SHOULD" clauses, the first of which is a nested BooleanQuery (B) (with > : > two "MUST" clauses (X child of B) Marketing, and (Y child of B) Smith), > : > and the 2nd of which (C, child of A) is a query for Davies. > > ...which is exactly what the QueryParser would do given *that* input (with > parens) > > If you want to programaticlly build up a query with the structure you are > describing, nested BooleanQuery objects is how you do it. > > > -Hoss > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org > >