Hi Chris,

The PhraseQuery class does no parsing; tokenization is expected to happen 
before you feed anything to it.  So unless you have an index-time analyzer that 
outputs terms that look like "aaa ddd" -- that is, terms with embedded spaces 
-- then attempting to use PhraseQuery or any other query type to look for these 
terms will bring you no joy.  (Of course, this only applies if you are not 
using a query parser - I believe John's point about enclosing a phrase query in 
quotes refers to the action Lucene's QueryParser takes when it sees input of 
this sort.)

The way that it worked for you - adding terms one at a time, with no quotes and 
no spaces - is the correct usage pattern.

Steve

On 07/15/2008 at 8:20 AM, Chris Bamford wrote:
> Hi John
> 
> Thanks for your continued interest in my travails!
> 
> ==I'm not sure I understand. You want a phrase query so they should be
> ==passed as a phrase in quotes.
> 
> Ok... well I must be missing something then  :-(
> This fails to return any hits for me:
> 
>         PhraseQuery pq = new  PhraseQuery();
>         pq.add(new Term("body", "aaa ddd"));
> 
> while
>        PhraseQuery pq = new  PhraseQuery();
>        pq.add(new Term("body", "aaa"));
>        pq.add(new Term("body", "ddd"));
> 
> works fine.
> I have tried with both Lucene 2.0 and 2.3 jars.
> 
> Please advise!
> 
> Thanks,
> 
> -Chris
>     BTW thanks for the tip about Luke
> 
> 
> John Griffin wrote:
> > Chris,
> > 
> > -----Original Message-----
> > From: Chris Bamford [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, July 10, 2008 9:15 AM
> > To: java-user@lucene.apache.org
> > Subject: Re: newbie question (for John Griffin) - fixed
> > 
> > Hi John,
> > 
> > Please ignore my earlier questions on this subject, as I have got to
> > the bottom of it. I was not passing each word in the phrase as a
> > separate Term to the query;
> > 
> > ==I'm not sure I understand. You want a phrase query so they should be
> > ==passed as a phrase in quotes.
> > 
> > 
> > instead I was passing the whole string (doh!).
> > 
> > Thanks.
> > 
> > - Chris
> > 
> > Chris Bamford wrote:
> > 
> > > Hi John,
> > > 
> > > Further to my question below, I did some back-to-basics investigation
> > > of PhraseQueries and found that even basic ones fail for me... I found
> > > the attached code on the Internet (see
> > > 
> http://affy.blogspot.com/2003/04/codebit-examples-for-all-of-l
> ucenes.html)
> > > 
> > 
> > 
> > > and this fails too...  Can you explain why?  I would expect the first
> > > test to deliver 2 hits.
> > > 
> > > I have tried with Lucene 2.0 and 2.3.2 jars and both fail.
> > > 
> > > Thanks again,
> > > 
> > > - Chris
> > > 
> > > 
> > > 
> > > Chris Bamford wrote:
> > > 
> > > > Hi John,
> > > > 
> > > > Just continuing from an earlier question where I asked you how to
> > > > handle strings like "from:fred flintston*" (sorry I have lost the
> > > > original email). You advised me to write my own BooleanQuery and add
> > > > to it Prefix- / Term- / Phrase- Querys as appropriate.  I have done
> > > > so, but am having trouble with the result - my PhraseQueries just do
> > > > not get any hits at all  :-( My code looks for quotes - if it finds
> > > > them, it treats the quoted phrase as a PhraseQuery and sets the slop
> > > > factor to 0. so,  an input of:
> > > > 
> > > >    subject:"Good Morning"
> > > > 
> > > > results in a PhraseQuery (which I add to my BooleanQuery and then
> > > > dump with toString()) of:
> > > > 
> > > >    +subject:"good morning"
> > > > 
> > > > ... which fails. However, if I break it into 2 TermQuerys, it works
> > > > (but that's not what I want).
> > > > 
> > > > What am I missing?
> > > > 
> > > > Thanks,
> > > > 
> > > > - Chris



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

Reply via email to