Index: src/java/org/apache/lucene/index/LogDocMergePolicy.java =================================================================== --- src/java/org/apache/lucene/index/LogDocMergePolicy.java (revision 773951) +++ src/java/org/apache/lucene/index/LogDocMergePolicy.java (working copy) @@ -1,5 +1,7 @@ package org.apache.lucene.index; +import java.io.IOException; + /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -34,8 +36,8 @@ // it to Long.MAX_VALUE to disable it maxMergeSize = Long.MAX_VALUE; } - protected long size(SegmentInfo info) { - return info.docCount; + protected long size(SegmentInfo info) throws IOException { + return info.docCount - (long)info.getDelCount(); } /** Sets the minimum size for the lowest level segments. Index: src/java/org/apache/lucene/index/LogMergePolicy.java =================================================================== --- src/java/org/apache/lucene/index/LogMergePolicy.java (revision 773951) +++ src/java/org/apache/lucene/index/LogMergePolicy.java (working copy) @@ -390,7 +390,7 @@ boolean anyTooLarge = false; for(int i=start;i= maxMergeSize || info.docCount >= maxMergeDocs); + anyTooLarge |= (size(info) >= maxMergeSize || (info.docCount - info.getDelCount()) >= maxMergeDocs); } if (!anyTooLarge) { Index: src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java =================================================================== --- src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java (revision 773951) +++ src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java (working copy) @@ -36,7 +36,9 @@ maxMergeSize = (long) (DEFAULT_MAX_MERGE_MB*1024*1024); } protected long size(SegmentInfo info) throws IOException { - return info.sizeInBytes(); + long byteSize = info.sizeInBytes(); + float delRatio = (info.docCount <= 0 ? 0.0f : ((float)info.getDelCount() / (float)info.docCount)); + return (info.docCount <= 0 ? byteSize : (long)((float)byteSize * (1.0f - delRatio))); } /**

Determines the largest segment (measured by total