zaffargachal
zaffargachal

Reputation: 810

How to get total count of document in lucene

I have very large number of documents in my index, I need to write a method that return total number of documents in the lucence index. Currently I used * wild card to fetch all the records and return the value of totalHits.

Problem is that as the query loads all object it is taking lot of time although I don't need object to be loaded just my requirement is to get total number of records without loading the documents.

Upvotes: 2

Views: 5755

Answers (1)

Omri
Omri

Reputation: 915

You can use the index reader:

IndexReader reader = IndexReader.open(FSDirectory.open(indexDirectory));
int num = reader.numDocs();

Omri

Upvotes: 17

Related Questions