Using Java how would you find out the number of documents in an lucene index?
使用Java如何在lucene索引中找到文档的数量?
4 个解决方案
#1
14
IndexReader contains the methods you need, in particular, numDocs
IndexReader包含了您需要的方法,特别是numDocs。
http://lucene.apache.org/core/3_6_0/api/all/org/apache/lucene/index/IndexReader.html#numDocs()
http://lucene.apache.org/core/3_6_0/api/all/org/apache/lucene/index/IndexReader.html numDocs()
#2
3
The official documentation: http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/index/IndexReader.html#numDocs()
官方文档:http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/index/IndexReader.html numDocs()
#3
3
Using java you can find the number of documents like this :
使用java您可以找到这样的文档数量:
IndexReader reader = IndexReader.open(FSDirectory.open(indexDirectory));
System.out.println(reader.maxDoc()); //this will give ya what you need.
#4
0
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.
在使用Hibernate搜索时,可以通过Hibernate搜索API获取Lucene IndexReader实例,然后使用reader.numDocs()。
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(getEntityManager());
IndexReader reader = fullTextEntityManager.getSearchFactory().getIndexReaderAccessor().open(MyEntity1.class, MyEntity2.class ...);
int numDocs = reader.numDocs();
#1
14
IndexReader contains the methods you need, in particular, numDocs
IndexReader包含了您需要的方法,特别是numDocs。
http://lucene.apache.org/core/3_6_0/api/all/org/apache/lucene/index/IndexReader.html#numDocs()
http://lucene.apache.org/core/3_6_0/api/all/org/apache/lucene/index/IndexReader.html numDocs()
#2
3
The official documentation: http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/index/IndexReader.html#numDocs()
官方文档:http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/index/IndexReader.html numDocs()
#3
3
Using java you can find the number of documents like this :
使用java您可以找到这样的文档数量:
IndexReader reader = IndexReader.open(FSDirectory.open(indexDirectory));
System.out.println(reader.maxDoc()); //this will give ya what you need.
#4
0
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.
在使用Hibernate搜索时,可以通过Hibernate搜索API获取Lucene IndexReader实例,然后使用reader.numDocs()。
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(getEntityManager());
IndexReader reader = fullTextEntityManager.getSearchFactory().getIndexReaderAccessor().open(MyEntity1.class, MyEntity2.class ...);
int numDocs = reader.numDocs();