lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donna L Gresh <gr...@us.ibm.com>
Subject Re: MultiFieldQueryParser - BooleanClause.Occur
Date Fri, 29 Feb 2008 18:56:51 GMT
Paul-
Thanks (that was one of my ulterior motives for answering the question; I 
figured if there was something inefficient or unnecessary about my 
approach, I'd hear about it :) )

Donna Gresh


Paul Elschot <paul.elschot@xs4all.nl> wrote on 02/29/2008 01:42:57 PM:

> 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 <jensburkhardt@web.de> 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: java-user-unsubscribe@lucene.apache.org
> > > For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 

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