Op Friday 29 February 2008 18:04:47 schreef Donna L Gresh:
> I believe something like the following will do what you want:
>
> QueryParser parserTitle = new QueryParser("title", analyzer);
> QueryParser parserAuthor = new QueryParser("author", analyzer);
>
> BooleanQuery overallquery = new BooleanQuery();
>
> BolleanQuery firstQuery = new BooleanQuery();
> Query q1= parserTitle.parse(term1);
> Query q2= parserAuthor.parse(term1);
> firstQuery.add(q1, BooleanClause.Occur.SHOULD); //should is like an
> OR firstQuery.add(q2, BooleanClause.Occur.SHOULD);
>
> BolleanQuery secondQuery = new BooleanQuery();
> Query q3= parserTitle.parse(term2);
> Query q4= parserAuthor.parse(term2);
> secondQuery.add(q3, BooleanClause.Occur.SHOULD);
> secondQuery.add(q4, BooleanClause.Occur.SHOULD);
>
> overallquery.add(firstQuery, BooleanClause.Occur.MUST); //must is
> like an AND
> overallquery.add(secondQuery, BooleanClause.Occur.MUST):

There is no need for a QueryParser in this case when using a
TermQuery instead of a Query for q1, q2, q3 and q4:

TermQuery q1 = new TermQuery(new Term("title", "term1"));

Regards,
Paul Elschot


>
> Donna  Gresh
>
> JensBurkhardt <[EMAIL PROTECTED]> wrote on 02/29/2008 10:46:51 AM:
> > Hey everybody,
> >
> > I read that it's possible to generate a query like:
> >
> > (title:term1 OR author:term1) AND (title:term2 OR author:term2)
> >
> > and so on. I also read that BooleanClause.Occur should help me
> > handle
>
> this
>
> > problem.
> > But i have to admit that i totally don't understand how to use it.
> > If someone can explain or has a link to an explanation, this would
> > be terrific
> >
> > Thanks and best regards
> >
> > Jens Burkhardt
> > --
> > View this message in context: http://www.nabble.
> > com/MultiFieldQueryParser---BooleanClause.Occur-tp15761243p15761243
> >.html Sent from the Lucene - Java Users mailing list archive at
> > Nabble.com.
> >
> >
> > -------------------------------------------------------------------
> >-- To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to