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 Tao Cheng <tc...@gmail.com> on 2007/09/01 00:43:27 UTC

Is there a Term ID for each distinctive term indexed in Lucene?

Hi all,

I found that instead of storing a term ID for a term in the index, Lucene
stores the actual term string value. I am wondering if there ever is such a
"term ID" for each distinctive term indexed in Lucne, similar as a "doc ID"
for each distinctive document indexed in Lucene.

In other words, I am looking for a method like " int termId(string term)" in
the IndexReader, such that it can return my an ID given a term's string
value.

Thanks a lot in advance.

-Tao

Re: Is there a Term ID for each distinctive term indexed in Lucene?

Posted by Samir Abdou <ab...@gmail.com>.
Hi,

You should extend the SegmentReader (or IndexReader) class to implement the
following method:

*public* *long* termID(Term t) *throws* IOException {  *return*
tis.getPosition(t);
}

which will give you a mean to get the ID of a given term.  This ID is simply
the position of that term within ".ti?" file !

Hope this will help

Regards,

Samir





2007/9/1, Tao Cheng <tc...@gmail.com>:
>
> Hi all,
>
> I found that instead of storing a term ID for a term in the index, Lucene
> stores the actual term string value. I am wondering if there ever is such
> a
> "term ID" for each distinctive term indexed in Lucne, similar as a "doc
> ID"
> for each distinctive document indexed in Lucene.
>
> In other words, I am looking for a method like " int termId(string term)"
> in
> the IndexReader, such that it can return my an ID given a term's string
> value.
>
> Thanks a lot in advance.
>
> -Tao
>