From 5c5c42cc37887236bf76b9e5f1cceaa25ee66886 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 14 Dec 2018 17:33:20 +0100 Subject: [PATCH] LUCENE-8609: Remove deprecated IW#numDocs() and IW#maxDoc() methdos --- lucene/CHANGES.txt | 3 ++ lucene/MIGRATE.txt | 6 ++++ .../org/apache/lucene/index/IndexWriter.java | 35 ++----------------- 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index b4dd696b4e4..bed537b9dc5 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -102,6 +102,9 @@ API Changes number of gaps between its component sub-intervals. This can be used in a new filter available via Intervals.maxgaps(). (Alan Woodward) +* LUCENE-8609: Remove IndexWriter#numDocs() and IndexWriter#maxDoc() in favor + of IndexWriter#getDocStats(). (Simon Willnauer) + Changes in Runtime Behavior * LUCENE-8333: Switch MoreLikeThis.setMaxDocFreqPct to use maxDoc instead of diff --git a/lucene/MIGRATE.txt b/lucene/MIGRATE.txt index 0b78d3c345a..045f00db627 100644 --- a/lucene/MIGRATE.txt +++ b/lucene/MIGRATE.txt @@ -158,3 +158,9 @@ constant factor was removed from the numerator of the scoring formula. Ordering of results is preserved unless scores are computed from multiple fields using different similarities. The previous behaviour is now exposed by the LegacyBM25Similarity class which can be found in the lucene-misc jar. + +## IndexWriter#maxDoc()/#numDocs() removed in favor of IndexWriter#getDocStats() ## + +IndexWriter#getDocStats() should be used instead of #maxDoc() / #numDocs() which offers a consistent +view on document stats. Previously calling two methods in order ot get point in time stats was subject +to concurrent changes. diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java index 4771f3df681..f9aaf346853 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -1131,18 +1131,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable, return analyzer; } - /** Returns total number of docs in this index, including - * docs not yet flushed (still in the RAM buffer), - * not counting deletions. - * @see #numDocs - * @deprecated use {@link #getDocStats()} instead - * */ - @Deprecated - public synchronized int maxDoc() { - ensureOpen(); - return docWriter.getNumDocs() + segmentInfos.totalMaxDoc(); - } - /** If {@link SegmentInfos#getVersion} is below {@code newVersion} then update it to this value. * * @lucene.internal */ @@ -1154,24 +1142,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable, changed(); } - /** Returns total number of docs in this index, including - * docs not yet flushed (still in the RAM buffer), and - * including deletions. NOTE: buffered deletions - * are not counted. If you really need these to be - * counted you should call {@link #commit()} first. - * @see #maxDoc - * @deprecated use {@link #getDocStats()} instead - * */ - @Deprecated - public synchronized int numDocs() { - ensureOpen(); - int count = docWriter.getNumDocs(); - for (final SegmentCommitInfo info : segmentInfos) { - count += info.info.maxDoc() - numDeletedDocs(info); - } - return count; - } - /** * Returns true if this index has deletions (including * buffered deletions). Note that this will return true @@ -5297,9 +5267,8 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable, } /** - * 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. + * Returns accurate {@link DocStats} form this writer. 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();