lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ahmet Arslan <iori...@yahoo.com>
Subject Re: Use of PrefixQuery to create multi-word queries
Date Wed, 05 Jan 2011 16:59:15 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
> 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.
> 

So order of search terms are important to you. Since you are constructing your queries programmatically,
you can use SpanQuery family.

If you substitute PrefixQuery with SpanRegexQuery, and TermQuery with SpanTermQuery. And combine
them in an ordered SpanNearQuery, I think you can achieve what you want.


      

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