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 Wojtek H <wo...@gmail.com> on 2008/04/09 18:48:50 UTC

Document ids in Lucene index

Hi all,
I am wondering if there are possible "holes" in set of index documents
ids. Being more specific - is it possible that there exist integer i
between 0 and IndexReader.maxDoc() such that
reader.document(i) == null
and
reader.isDeleted(i)==false
???

Regards,
wojtek

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Document ids in Lucene index

Posted by Chris Hostetter <ho...@fucit.org>.
: - check maxDoc()
: - iterate from 0 to maxDoc() and process doc if it is not deleted

For the record: that is exactly what MatchAllDocsQuery does ... except 
that you have an off by one error (maxDoc returns 1 more then the 
largest possible document number).

Even if you don't want the Query API, just use MatchAllDocs to handle the 
details for you and save yourself some code...

  Scorer allDocs = (new MatchAllDocs()).weight(searcher).scorer(reader);
  while (allDocs.next()) {
    int doc = allDocs.doc()
       ...do stuff..
  }



-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Document ids in Lucene index

Posted by Wojtek H <wo...@gmail.com>.
Thank you for the answer. So it means that I can without any problems
iterate over index documents using this algoritm (I don't want to use
MatchAllQuery):

- check maxDoc()
- iterate from 0 to maxDoc() and process doc if it is not deleted

Am I right?
Best,
wojtek

2008/4/12, Chris Hostetter <ho...@fucit.org>:
>
>  : I am wondering if there are possible "holes" in set of index documents
>
> : ids. Being more specific - is it possible that there exist integer i
>  : between 0 and IndexReader.maxDoc() such that
>  : reader.document(i) == null
>  : and
>  : reader.isDeleted(i)==false
>
> : ???
>
>  That should not ever happen ... if it does, I would consider it a bug
>  until someone smarter then me explained why it isn't.
>
>  (minor nit: document(i) won't ever return null, if you call it on a
>  deleted docId you'll get an IllegalArgumentException)
>
>
>  -Hoss
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>  For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Document ids in Lucene index

Posted by Chris Hostetter <ho...@fucit.org>.
: I am wondering if there are possible "holes" in set of index documents
: ids. Being more specific - is it possible that there exist integer i
: between 0 and IndexReader.maxDoc() such that
: reader.document(i) == null
: and
: reader.isDeleted(i)==false
: ???

That should not ever happen ... if it does, I would consider it a bug 
until someone smarter then me explained why it isn't.

(minor nit: document(i) won't ever return null, if you call it on a 
deleted docId you'll get an IllegalArgumentException)


-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org