Apache Lucene open-source search software
LUCENE-2602: enable calibrateSizeByDeletes in default merge policy
Michael McCandless3f2f77c14aa8
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex e9f4158a4ce..27833b12b2b 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -100,6 +100,11 @@ Changes in backwards compatibility policy* LUCENE-2484: Removed deprecated TermAttribute. Use CharTermAttributeand TermToBytesRefAttribute instead. (Uwe Schindler)+* LUCENE-2602: The default (LogByteSizeMergePolicy) merge policy now+ takes deletions into account by default. You can disable this by+ calling setCalibrateSizeByDeletes(false) on the merge policy. (Mike+ McCandless)+API Changes* LUCENE-2302, LUCENE-1458, LUCENE-2111, LUCENE-2514: Terms are no longerdiff --git a/lucene/src/java/org/apache/lucene/index/LogMergePolicy.java b/lucene/src/java/org/apache/lucene/index/LogMergePolicy.javaindex 48651bcf018..15d911b00ef 100644--- a/lucene/src/java/org/apache/lucene/index/LogMergePolicy.java+++ b/lucene/src/java/org/apache/lucene/index/LogMergePolicy.java@@ -60,8 +60,7 @@ public abstract class LogMergePolicy extends MergePolicy {long maxMergeSize;int maxMergeDocs = DEFAULT_MAX_MERGE_DOCS;- /* TODO 3.0: change this default to true */- protected boolean calibrateSizeByDeletes = false;+ protected boolean calibrateSizeByDeletes = true;private boolean useCompoundFile = true;private boolean useCompoundDocStore = true;@@ -162,6 +161,7 @@ public abstract class LogMergePolicy extends MergePolicy {protected long sizeDocs(SegmentInfo info) throws IOException {if (calibrateSizeByDeletes) {int delCount = writer.get().numDeletedDocs(info);+ assert delCount <= info.docCount;return (info.docCount - (long)delCount);} else {return info.docCount;@@ -172,8 +172,9 @@ public abstract class LogMergePolicy extends MergePolicy {long byteSize = info.sizeInBytes();if (calibrateSizeByDeletes) {int delCount = writer.get().numDeletedDocs(info);- float delRatio = (info.docCount <= 0 ? 0.0f : ((float)delCount / (float)info.docCount));- return (info.docCount <= 0 ? byteSize : (long)(byteSize * (1.0f - delRatio)));+ double delRatio = (info.docCount <= 0 ? 0.0f : ((float)delCount / (float)info.docCount));+ assert delRatio <= 1.0;+ return (info.docCount <= 0 ? byteSize : (long)(byteSize * (1.0 - delRatio)));} else {return byteSize;}