lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From L Duperval <duper...@videotron.com>
Subject Use of PrefixQuery to create multi-word queries
Date Wed, 05 Jan 2011 16:38:37 GMT
Hi,

I am trying to implement a "progressive search" with Lucene. What I mean is that
something like what Google does: you type a few letters and google searches for
matches as you type. The more letters you enter, the more precise your search
becomes.

I decided to use a prefix query because otherwise, I need to have complete words
in order for multiword queries to work. 

I am using Compass as my Lucene frontend.

My query looks like this:

BooleanQuery bq = new BooleanQuery();
// The last word is a prefix
PrefixQuery pq = 
   new PrefixQuery(new Term("searchField", words[words.length - 1]));
   bq.add(pq, BooleanClause.Occur.MUST);

   // All others are normal terms
   for (int i = 0; i <= (words.length - 2); i++) {
   TermQuery tq = new TermQuery(new Term("searchField", words[i])); 
     bq.add(tq, BooleanClause.Occur.MUST);
   }

The problem I have is that if I specify "little fa" as search terms, Lucene will
match

The little fairy

but also 

Farris little
The little pig farmer
Chicken Little: looking far ahead

(each line is the content of a separate document)

I only want the first type of matches.

What should I be doing instead?

Thanks,

L


---------------------------------------------------------------------
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