lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vishal Bathija" <vishalbath...@gmail.com>
Subject Re: using boolean operators with the PhraseQuery
Date Wed, 19 Apr 2006 03:44:13 GMT
I am not sure if I understand you.  Do I add the terms for the second
phrase immediately after I add the terms for the first phrase. When do
i wrap the PhraseQuery I construct into a BooleanQuery.

For instance
String newTerm1= "avoids deadlock";
String newTerm2= "reduces cost";
PhraseQuery query =new PhraseQuery();	

String[] phraseTerms1 = newTerm1.split( " ");
Term[] phrTerm1=new Term[phraseTerms1.length];

for(int u=0; u<phraseTerms1.length;u++)
{
							phrTerm1[u]=new Term("contents",phraseTerms1[u]);
	query.add(phrTerm1[u]);
}

String[] phraseTerms2 = newTerm2.split( " ");			
Term[] phrTerm2=new Term[phraseTerms2.length];

for(int u=0; u<phraseTerms2.length;u++)
{
							phrTerm2[u]=new Term("contents",phraseTerms2[u]);
	query.add(phrTerm2[u]);
						
}
Hits hits = searcher.search(query);		
									The code above just adds the terms of phrase2 following the
terms  for phrase1.
Can you give me an example building a BooleanQuery OR  for the
newTerm1 and newTerm2.

Thanks again
Vishal



On 4/18/06, Erik Hatcher <erik@ehatchersolutions.com> wrote:
> Wrap the PhraseQuery's inside a BooleanQuery to achieve AND/OR.
>
>        Erik
>
>
> On Apr 18, 2006, at 10:00 PM, Vishal Bathija wrote:
>
> > Hi,
> > I am trying to find the number of hits for a phrase using the
> > PhraseQuery. I would like to know how I could seach for 2 phrases at
> > the same time using the boolean operators OR, AND. The code snippet
> > that I use to seach for one phrase is
> >
> > String test ="avoids deadlock"
> > String[] phraseTerms = test.split( " ");
> > PhraseQuery query =new PhraseQuery();
> > searcher = new IndexSearcher(rd);
> > Term[] phrTerm=new Term[phraseTerms.length];
> > for(int u=0; u<phraseTerms.length;u++)
> > {
> > phrTerm[u]=new Term("contents",phraseTerms[u]);
> > query.add(phrTerm[u]);
> > }
> >
> > Hits hits = searcher.search(query);
> >
> > How can I extend this to search for multiple phrases?
> >
> > Regards
> > Vishal
> > --
> > Vishal Bathija
> > Graduate Student
> > Department of Computer Science & Systems Analysis
> > Miami University
> > Oxford,Ohio
> > Phone: (513)-461-9239
> >
> > ---------------------------------------------------------------------
> > 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
>
>


--
Vishal Bathija
Graduate Student
Department of Computer Science & Systems Analysis
Miami University
Oxford,Ohio
Phone: (513)-461-9239

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message