Finding the number of documents in a lucene index

♀尐吖头ヾ 提交于 2019-12-22 03:54:14

问题


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


回答1:


IndexReader contains the methods you need, in particular, numDocs

http://lucene.apache.org/core/3_6_0/api/all/org/apache/lucene/index/IndexReader.html#numDocs()




回答2:


The official documentation: http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/index/IndexReader.html#numDocs()




回答3:


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.



回答4:


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();


来源:https://stackoverflow.com/questions/442463/finding-the-number-of-documents-in-a-lucene-index

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!