Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 795386) +++ CHANGES.txt (working copy) @@ -314,6 +314,10 @@ StopAnalzyer and replace it with an immutable implementation of CharArraySet. (Simon Willnauer via Mark Miller) +31. LUCENE-1742: SegmentInfos, SegmentInfo and SegmentReader have been + made public as expert, experimental APIs. These APIs may suddenly + change from release to release (Jason Rutherglen via Mike + McCandless). Bug fixes Index: src/java/org/apache/lucene/index/SegmentInfo.java =================================================================== --- src/java/org/apache/lucene/index/SegmentInfo.java (revision 795386) +++ src/java/org/apache/lucene/index/SegmentInfo.java (working copy) @@ -28,7 +28,14 @@ import java.util.ArrayList; import java.util.Collections; -final class SegmentInfo { +/** + * Information about a segment such as it's name, directory, and files related + * to the segment. + * + * *
NOTE: This API is new and still experimental + * (subject to change suddenly in the next release)
+ */ +public final class SegmentInfo { static final int NO = -1; // e.g. no norms; no deletes; static final int YES = 1; // e.g. have norms; have deletes; @@ -150,7 +157,7 @@ } // returns MapNOTE: This API is new and still experimental + * (subject to change suddenly in the next release)
+ */ +public class SegmentReader extends IndexReader implements Cloneable { protected boolean readOnly; private SegmentInfo si; @@ -676,7 +680,7 @@ /** * Clones the norm bytes. May be overridden by subclasses. New and experimental. - * @param bv Byte array to clone + * @param bytes Byte array to clone * @return New BitVector */ protected byte[] cloneNormBytes(byte[] bytes) { Index: src/java/org/apache/lucene/index/LogMergePolicy.java =================================================================== --- src/java/org/apache/lucene/index/LogMergePolicy.java (revision 795386) +++ src/java/org/apache/lucene/index/LogMergePolicy.java (working copy) @@ -65,7 +65,7 @@ private boolean useCompoundFile = true; private boolean useCompoundDocStore = true; - private IndexWriter writer; + protected IndexWriter writer; protected boolean verbose() { return writer != null && writer.verbose(); @@ -154,7 +154,8 @@ protected long sizeDocs(SegmentInfo info) throws IOException { if (calibrateSizeByDeletes) { - return (info.docCount - (long)info.getDelCount()); + int delCount = writer.numDeletedDocs(info); + return (info.docCount - (long)delCount); } else { return info.docCount; } @@ -163,7 +164,8 @@ protected long sizeBytes(SegmentInfo info) throws IOException { long byteSize = info.sizeInBytes(); if (calibrateSizeByDeletes) { - float delRatio = (info.docCount <= 0 ? 0.0f : ((float)info.getDelCount() / (float)info.docCount)); + int delCount = writer.numDeletedDocs(info); + float delRatio = (info.docCount <= 0 ? 0.0f : ((float)delCount / (float)info.docCount)); return (info.docCount <= 0 ? byteSize : (long)((float)byteSize * (1.0f - delRatio))); } else { return byteSize; @@ -186,12 +188,13 @@ (numToOptimize != 1 || isOptimized(writer, optimizeInfo)); } - /** Returns true if this single nfo is optimized (has no + /** Returns true if this single info is optimized (has no * pending norms or deletes, is in the same dir as the * writer, and matches the current compound file setting */ private boolean isOptimized(IndexWriter writer, SegmentInfo info) throws IOException { - return !info.hasDeletions() && + boolean hasDeletions = writer.numDeletedDocs(info) > 0; + return !hasDeletions && !info.hasSeparateNorms() && info.dir == writer.getDirectory() && info.getUseCompoundFile() == useCompoundFile; @@ -303,16 +306,8 @@ int firstSegmentWithDeletions = -1; for(int i=0;iNOTE: This API is new and still experimental + * (subject to change suddenly in the next release)
+ */ +public final class SegmentInfos extends Vector { /** The file format version, a negative number. */ /* Works since counter, the old 1st entry, is always >= 0 */ @@ -767,7 +774,7 @@ version = other.version; } - public final void rollbackCommit(Directory dir) throws IOException { + final void rollbackCommit(Directory dir) throws IOException { if (pendingSegnOutput != null) { try { pendingSegnOutput.close(); @@ -796,7 +803,7 @@ * end, so that it is not visible to readers. Once this * is called you must call {@link #finishCommit} to complete * the commit or {@link #rollbackCommit} to abort it. */ - public final void prepareCommit(Directory dir) throws IOException { + final void prepareCommit(Directory dir) throws IOException { if (pendingSegnOutput != null) throw new IllegalStateException("prepareCommit was already called"); write(dir); @@ -822,7 +829,7 @@ return files; } - public final void finishCommit(Directory dir) throws IOException { + final void finishCommit(Directory dir) throws IOException { if (pendingSegnOutput == null) throw new IllegalStateException("prepareCommit was not called"); boolean success = false; @@ -882,12 +889,12 @@ /** Writes & syncs to the Directory dir, taking care to * remove the segments file on exception */ - public final void commit(Directory dir) throws IOException { + final void commit(Directory dir) throws IOException { prepareCommit(dir); finishCommit(dir); } - synchronized String segString(Directory directory) { + public synchronized String segString(Directory directory) { StringBuffer buffer = new StringBuffer(); final int count = size(); for(int i = 0; i < count; i++) { @@ -906,7 +913,7 @@ return userData; } - public void setUserData(Map data) { + void setUserData(Map data) { if (data == null) { userData = Collections.EMPTY_MAP; } else { @@ -925,7 +932,7 @@ } // Used only for testing - boolean hasExternalSegments(Directory dir) { + public boolean hasExternalSegments(Directory dir) { final int numSegments = size(); for(int i=0;i