lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <>
Subject Re: TermDocs and "read"
Date Mon, 20 Oct 2008 09:06:25 GMT

It seems like you are trying to use the TermDocs iterator to load the  
term freq for that particular document (doc)?

It doesn't work that way -- instead, it simply iterates over all  
documents that this term occurred in.  (Ie it will replace the doc in  
the int[] that you passed in, with the next doc in the term's postings).

If you only want to read one doc at a time, you should its next()  
method to advance, and then call doc() and freq().  When next()  
returns false, it means there are no more documents, so you should  
then break out of your loop.


Carlos Rodríguez Fernández wrote:

> Hello:
> I have a problem with TermDocs#read operation.
> the following code has an incorrect result:
>            .....
>            int termFreq=0;
>            .....
>            TermDocs termDocs = indexReader.termDocs(new
> Term(((Field)field).name(),termCons));
>            int[] freqs = new int[]{0};
>   int[]{doc}, freqs);
>            termFreq+=freqs[0];
>            ....
> the freqs array always return with a "[1]" for all terms and for all
> documents. :S
> Can you help me please?
> Thanks a lot!
> Carlos

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message