使用 Lucene 的 Java 版本,您将如何找出索引中的文档数量?
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()
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.
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(getEntityManager());
IndexReader reader = fullTextEntityManager.getSearchFactory().getIndexReaderAccessor().open(MyEntity1.class, MyEntity2.class ...);
int numDocs = reader.numDocs();
With recent Lucene version using an IndexReader the following Kotlin snippet does the job:
DirectoryReader.open(directory).use { reader ->
println(reader.numDocs())
}
where directory
is an instance of Directory containing the index.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.