lucene-java-user mailing list archives

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

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

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

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?



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message