Is it possible to iterate through documents stored in Lucene Index?

Eugeniu Torica picture Eugeniu Torica · Feb 22, 2010 · Viewed 24.6k times · Source

I have some documents stored in a Lucene index with a docId field. I want to get all docIds stored in the index. There is also a problem. Number of documents is about 300 000 so I would prefer to get this docIds in chunks of size 500. Is it possible to do so?

Answer

bajafresh4life picture bajafresh4life · Feb 23, 2010
IndexReader reader = // create IndexReader
for (int i=0; i<reader.maxDoc(); i++) {
    if (reader.isDeleted(i))
        continue;

    Document doc = reader.document(i);
    String docId = doc.get("docId");

    // do something with docId here...
}