lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: UnExpected result for: indexReader.termDocs()
Date Mon, 09 Jul 2007 13:43:26 GMT
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 <vikas.khengare@unnat-e.com> 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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message