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: SpanFirstQuery and PrefixQuery combined?
Date Tue, 23 Mar 2010 10:29:33 GMT

> I¹m trying to do a search over an index with names.
> 
> This is how I currently create a document of the index
> 
> document.add(new Field("id", item.getItemId().toString(),
> Field.Store.YES,
> Field.Index.NOT_ANALYZED_NO_NORMS));
> document.add(new Field("item.name",
> item.getAutoCompleteText(),
> Field.Store.YES, Field.Index.ANALYZED));
> document.add(new Field("item.type",
> item.getAutoCompleteType().name(),
> field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
> 
> I wish to try to search by item.name, but only get results
> that start with the term.
> SpanFirstQuery would allow me to do this, however it is not
> a PrefixQuery,
> Meaning
> 
> If I have an item.name "The Best of Elvis" in the index,
> I would find a match if I search for "The" but not if I
> just search
> For "Th".
> What I would basically like to do is some term that looks
> like this:
> spanFirst(item.name:Th*,1)

I think what you are looking for is EdgeNGramTokenFilter [1] combined with KeywordTokenizer
[2]. This combination is common for auto-complete/suggest stuff.

[1]http://lucene.apache.org/java/2_9_0/api/all/org/apache/lucene/analysis/ngram/EdgeNGramTokenFilter.html


[2]http://lucene.apache.org/java/2_9_0/api/all/org/apache/lucene/analysis/KeywordTokenizer.html


      

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