Finding the number of documents in a lucene index

2019-04-21 20:33发布

Using Java how would you find out the number of documents in an lucene index?

标签: java lucene
4条回答
狗以群分
2楼-- · 2019-04-21 21:11
Evening l夕情丶
3楼-- · 2019-04-21 21:19

When using Hibernate Search, it is possible to obtain a Lucene IndexReader instance through the Hibernate Search API and then use reader.numDocs() as already mentioned in previous answers.

FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(get‌​EntityManager());
IndexReader reader = fullTextEntityManager.getSearchFactory().getIndexReaderAcces‌​sor().open(MyEntity1‌​.class, MyEntity2.class ...);
int numDocs = reader.numDocs();
查看更多
Evening l夕情丶
4楼-- · 2019-04-21 21:21

Using java you can find the number of documents like this :

IndexReader reader = IndexReader.open(FSDirectory.open(indexDirectory));
System.out.println(reader.maxDoc()); //this will give ya what you need.
查看更多
登录 后发表回答