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.
You can use the index reader:
IndexReader reader = IndexReader.open(FSDirectory.open(indexDirectory));
int num = reader.numDocs();
Omri
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With