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 Cam Bazz <ca...@gmail.com> on 2008/01/08 12:13:01 UTC
PrefixQuery question
Hello,
I am having a problem qith PrefixQuery:
I have a field name item title which is indexed as:
doc.add(new Field("item_title", item_title.trim().toLowerCase(),
Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.YES));
and I am forming my query like:
PrefixQuery pq = new PrefixQuery((new Term("item_title", queryText)));
Lets say I have some documents such as
mouse cat apple
mouse cat house
cat house mouse
and when I search for prefix mou, it will return all of 3 documents. what I
like to do is for it to return "mouse cat apple" and "mouse cat house" and
not "cat house mouse"
it will only do this if the field is untokenized I believe.
is there any way to get the desired behavior?
best,
-C.B.
Re: PrefixQuery question
Posted by Shai Erera <se...@gmail.com>.
Did you try SpanFirstQuery?
I had the same need in my application, for implementing type-ahead
functionality over the titles and I found that storing them as un_tokenized
gives the best performance (of course, I don't run any query, but iterate
over the terms in my solution).
Span queries are expensive, but you can try it.
On Jan 8, 2008 1:13 PM, Cam Bazz <ca...@gmail.com> wrote:
> Hello,
>
> I am having a problem qith PrefixQuery:
>
> I have a field name item title which is indexed as:
>
> doc.add(new Field("item_title", item_title.trim().toLowerCase(),
> Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.YES));
>
> and I am forming my query like:
>
> PrefixQuery pq = new PrefixQuery((new Term("item_title", queryText)));
>
> Lets say I have some documents such as
>
> mouse cat apple
> mouse cat house
> cat house mouse
>
>
> and when I search for prefix mou, it will return all of 3 documents. what
> I
> like to do is for it to return "mouse cat apple" and "mouse cat house" and
> not "cat house mouse"
>
> it will only do this if the field is untokenized I believe.
>
> is there any way to get the desired behavior?
>
> best,
> -C.B.
>
--
Regards,
Shai Erera