Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 682
zaffargachal Avatar asked Jan 17 '26 07:01

zaffargachal


1 Answers

You can use the index reader:

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

Omri

like image 125
Omri Avatar answered Jan 19 '26 20:01

Omri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!