Github user dnhatn commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/527#discussion_r241504268
--- Diff: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java ---
@@ -5289,4 +5289,48 @@ final synchronized boolean
segmentCommitInfoExist(SegmentCommitInfo sci) {
final synchronized SegmentInfos cloneSegmentInfos() {
return segmentInfos.clone();
}
+
+ /**
+ * Returns accurate {@link DocStats} form this writer. This is
equivalent to calling {@link #numDocs()} and {@link #maxDoc()}
+ * but is not subject to race-conditions. The numDoc for instance can
change after maxDoc is fetched that causes numDocs to be
+ * greater than maxDoc which makes it hard to get accurate document
stats from IndexWriter.
+ */
+ public synchronized DocStats getDocStats() {
+ ensureOpen();
+ int numDocs = docWriter.getNumDocs();
+ int maxDoc = numDocs;
+ for (final SegmentCommitInfo info : segmentInfos) {
+ maxDoc = info.info.maxDoc();
--- End diff --
`=` -> `+=`.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]