I am trying to get all documents from Lucene Index (which is already not deleted ).
I heard that if I delete something from Lucene Index, Lucene will not delete immediately from file.
So I wanted to get the documents from Index file which is not deleted.
Best How To :
Lucene provides a bitset of all non-deleted documents, called
liveDocs. You can get it by iterating over all
LeafReaders (or using the
SlowCompositeReaderWrapper) and calling the
liveDocs method or by using the
Once you have this bitset, you can iterator from
IndexReader#maxDoc and consult the bitset to know whether a docid is representing a deleted document or a live one. You can access all stored fields of a deleted document just as you would from a live one.
However, once a segment gets merged, its deleted documents are permanently deleted and thus removed from the index.