Well, first you never test anything that will break the loop. TermDocs.next
()
does not set termdocs == null, but returns false....


I've always found it a bit confusing that calling next() doesn't skiph the
first term, but you want something like this....

       Term term = new Term(field, value);
       TermDocs termDocs = reader.termDocs(term);

       while (termDocs.next()) {
           System.out.println("Document num:" + termDocs.doc());
       }


Best
Erick

On 7/9/07, Vikas <[EMAIL PROTECTED]> wrote:

Hi Friends,

Before indexing somthing I want to check whether this term is already
exist in index / NOT.[i.e. primary key kind of thing].

When I am trying to get docs with indexReader.termDocs(term); it is not
returning expected results.
I put "TermDocs" object in while loop to print document number where I
found this term; but it is always printing "0" and going in infinite loop.
Where the term, I am searching is exists in index and can get it though "
indexReader.terms(term);"

Here is the code -->

Term term = new Term( SomeDocument.KEY, value);
TermDocs termDocs = indexReader.termDocs(term);
while(termDocs !=null)
{
   System.out.println("Document num:"+termDocs.doc());
   termDocs.next();
}

This is going in infinite loop and printing "Document num:0" always.
Can some one will give me information on this?

With best regards

From
Vikas R. Khengare

Reply via email to