You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Lukas Österreicher <lu...@austria.real.com> on 2010/03/23 11:03:18 UTC
SpanFirstQuery and PrefixQuery combined?
Hi.
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)
But so far It seemes this is not possible.
Am I correct?
Is there another way to do this?
I cannot just do I normal PrefixQuery since it will find me a result
If I search for ³Best² in the above scenario, but I only want matches
for: ³T², ³Th² and ³The², and if possible also for ³The Bes², ³The Best² and
³The Best o²,
But not for ³Best² or ³Elvis².
Can you help me?
Thanx, Lukas
Re: SpanFirstQuery and PrefixQuery combined?
Posted by Ahmet Arslan <io...@yahoo.com>.
> 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