Index: src/java/org/apache/lucene/index/LogDocMergePolicy.java =================================================================== --- src/java/org/apache/lucene/index/LogDocMergePolicy.java (revision 0) +++ src/java/org/apache/lucene/index/LogDocMergePolicy.java (revision 0) @@ -0,0 +1,25 @@ +package org.apache.lucene.index; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class LogDocMergePolicy extends LogMergePolicy { + protected long size(SegmentInfo info) { + return info.docCount; + } +} + Property changes on: src/java/org/apache/lucene/index/LogDocMergePolicy.java ___________________________________________________________________ Name: svn:eol-style + native Index: src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java =================================================================== --- src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java (revision 0) +++ src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java (revision 0) @@ -0,0 +1,27 @@ +package org.apache.lucene.index; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.IOException; + +public class LogByteSizeMergePolicy extends LogMergePolicy { + protected long size(SegmentInfo info) throws IOException { + return info.sizeInBytes(); + } +} + Property changes on: src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java ___________________________________________________________________ Name: svn:eol-style + native Index: src/java/org/apache/lucene/index/SegmentInfo.java =================================================================== --- src/java/org/apache/lucene/index/SegmentInfo.java (revision 566393) +++ src/java/org/apache/lucene/index/SegmentInfo.java (working copy) @@ -65,6 +65,8 @@ private List files; // cached list of files that this segment uses // in the Directory + long sizeInBytes = -1; // total byte size of all of our files (computed on demand) + private int docStoreOffset; // if this segment shares stored fields & vectors, this // offset is where in that file this segment's docs begin private String docStoreSegment; // name used to derive fields/vectors file we share with @@ -104,7 +106,7 @@ * Copy everything from src SegmentInfo into our instance. */ void reset(SegmentInfo src) { - files = null; + clearFiles(); name = src.name; docCount = src.docCount; dir = src.dir; @@ -199,6 +201,19 @@ } } + /** Returns total size in bytes of all of files used by + * this segment. */ + long sizeInBytes() throws IOException { + if (sizeInBytes == -1) { + List files = files(); + final int size = files.size(); + sizeInBytes = 0; + for(int i=0;i 0) { + + while ((segmentInfos.size() > 1) || + SegmentReader.hasDeletions(segmentInfos.info(0)) || + SegmentReader.hasSeparateNorms(segmentInfos.info(0)) || + (segmentInfos.info(0).dir != merger.getDirectory()) || + (useCompoundFile && (!SegmentReader.usesCompoundFile(segmentInfos.info(0))))) { + + MergeSpecification spec = new MergeSpecification(); + + int first = segmentInfos.size() - mergeFactor; + first = first < 0 ? 0 : first; + int last = segmentInfos.size(); + + spec.segments = segmentInfos(segmentInfos, first, last); + spec.useCompoundFile = useCompoundFile; + + merger.merge(spec); + } + } + } + + private boolean mergeOnlyAdjacent = true; + private IndexWriter writer; + + void copy(SegmentInfos segmentInfos, + IndexMerger merger, + int first, + int last) + throws CorruptIndexException, IOException { + + MergeSpecification spec = new MergeSpecification(); + spec.segments = segmentInfos(segmentInfos, first, last); + spec.useCompoundFile = useCompoundFile; + + merger.merge(spec); + } + + abstract protected long size(SegmentInfo info) throws IOException; + + public void merge(SegmentInfos infos, IndexMerger merger) throws CorruptIndexException, IOException { + mergeInternal(infos, merger); + // Now copy any segments whose dir doesn't match + copyDirSegments(infos, merger); + } + + private void mergeInternal(SegmentInfos infos, IndexMerger merger) throws CorruptIndexException, IOException { + + // Compute levels, which is just log (base mergeFactor) + // of the size of each segment + final int numSegments = infos.size(); + float[] levels = new float[numSegments]; + final float norm = (float) Math.log(mergeFactor); + for(int i=0;i maxLevel) + maxLevel = level; + } + + // Now search backwards for the rightmost segment that + // falls into this level: + int upto = numSegments-1; + final float levelBottom = (float) (maxLevel - LEVEL_LOG_SPAN); + while(upto >= start) { + if (levels[upto] > levelBottom) + break; + upto--; + } + + // Finally, we now have N segments from start to upto + // that are at the same quantized level. If this is + // more than mergeFactor segments, we merge them. + if (1+upto-start >= mergeFactor) { + boolean anyTooLarge = false; + final int limit = start+mergeFactor; + for(int i=start;i= maxMergeDocs; + + if (!anyTooLarge) { + MergeSpecification spec = new MergeSpecification(); + spec.useCompoundFile = useCompoundFile; + spec.segments = segmentInfos(infos, start, start+mergeFactor); + merger.merge(spec); + // Recurse to cacscade + mergeInternal(infos, merger); + break; + } + } + start = 1+upto; + } + + } + + private void copyDirSegments(SegmentInfos infos, IndexMerger merger) throws CorruptIndexException, IOException { + final int numSegments = infos.size(); + for(int i=0;i= maxMergeDocs) + throw new IllegalArgumentException("Cannot add index that contains segments > maxMergeDocs"); + copy(infos, merger, i, 1+i); + } + } + } +} Property changes on: src/java/org/apache/lucene/index/LogMergePolicy.java ___________________________________________________________________ Name: svn:eol-style + native