We do something similar with a PrefixQuery.   But the way we do it is to use a 
Keyword field to use the PrefixQuery against.

So if we had a Book like with a title like 'The Brown Dog',  we would end up 
with fields in the document like:

Used for the normal full text searching

title : the brown dog

Used for the prefix searching

titlekeyword : the brown dog
titlekeyword : brown dog

So as the user is typing we are looking up using a PrefixQuery against the 
titlekeyword field.    We had tried things like span queries against the title 
field before settling on this approach (we also use this field for other 
things, not just for the PrefixQuery).


On Jan 5, 2011, at 11:38 AM, L Duperval wrote:

> 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-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-user-h...@lucene.apache.org
> 


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

Reply via email to