You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Joe Amstadt <te...@yahoo.com> on 2006/02/10 22:04:40 UTC

Lucene PhraseQuery Problem No Hits

Problem.
I can add one or multiple TermQuery's to the BooleanQuery for searching and I am getting Hits when i preform the search on various indexes.  If i add a PhraseQuery to the BooleanQuery on a search i get zero hits.

         Some Background Information:

Indexing using standard anaylzer.
Indexing text documents into various indexes based on their year created.
Using Lucene 1.4.3.
Lucene Document fields used are Keyword and Text.
Searching using BooleanQuery and adding TermQuery and PhraseQuery to the BooleanQuery to preform a search on the various indexes.

Example 1:
PhraseQuery pq_query = new PhraseQuery();
pq_query.add( new Term( "body", "\"circus parade\"" ) );
<BooleanQuery>.add( pq_query, true, false);

I get zero Hits on the search.  In the document there is a phrase that goes "circus parade downtown"

Also i have tried this code as well and nothing.  Also i have messed with the <PhraseQuery>.setSlop() and still zero hits.

try{

     bq_query.add((PhraseQuery)QueryParser.parse( "\"circus parade\"", "body", new  StandardAnalyzer() ), true, false) ;
}catch(ParseException pe){

    pe.printStackTrace();
}

Example2: 
<BooleanQuery>.add( new TermQuery ( new Term  ( "body", "circus" ) ) , true, false );

I get Hits from the search

Example 3:
<BooleanQuery>.add( new TermQuery ( new Term  ( "body", "circus" ) ) , true, false );
<BooleanQuery>.add( new TermQuery ( new Term  ( "body", "parade" ) ) , true, false );
<BooleanQuery>.add( new TermQuery ( new Term  ( "body", "downtown" ) ) , true, false );

I get Hits from the search



Any help on this matter would be great!


		
---------------------------------
 Yahoo! Mail
 Use Photomail to share photos without annoying attachments.

Re: Lucene PhraseQuery Problem No Hits

Posted by Chris Hostetter <ho...@fucit.org>.
: PhraseQuery pq_query = new PhraseQuery();
: pq_query.add( new Term( "body", "\"circus parade\"" ) );
: <BooleanQuery>.add( pq_query, true, false);

the terms you add to a phrase query need to be exactly equal to the
individual terms that your analyzer would have generated when indexingthe
documents you now want to match.  in your case, it looks like you are
using StandardAnalyzer -- which never generates a term with a space in it.

try this....

    PhraseQuery pq_query = new PhraseQuery();
    pq_query.add(new Term("body", "circus"));
    pq_query.add(new Term("body", "parade"));


:      bq_query.add((PhraseQuery)QueryParser.parse( "\"circus parade\"", "body", new  StandardAnalyzer() ), true, false) ;

...off the top of my head, that seems like it should work.  have you
looked at the toString on the resulting query object to see what it's
structure is?  Compare it with the toString of a query built hte way i
describe above and see if anything is different.



-Hoss


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