Index: lucene/CHANGES.txt =================================================================== --- lucene/CHANGES.txt (revision 1098529) +++ lucene/CHANGES.txt (working copy) @@ -9,6 +9,11 @@ a method getHeapArray() was added to retrieve the internal heap array as a non-generic Object[]. (Uwe Schindler, Yonik Seeley) +API Changes + +* LUCENE-3061: IndexWriter's getNextMerge() and merge(OneMerge) are now public, + allowing for custom MergeScheduler implementations. (Shai Erera) + Optimizations * LUCENE-2990: ArrayUtil/CollectionUtil.*Sort() methods now exit early Index: lucene/src/test/org/apache/lucene/index/publicapi/TestCustomMergeScheduler.java =================================================================== --- lucene/src/test/org/apache/lucene/index/publicapi/TestCustomMergeScheduler.java (revision 0) +++ lucene/src/test/org/apache/lucene/index/publicapi/TestCustomMergeScheduler.java (revision 0) @@ -0,0 +1,75 @@ +package org.apache.lucene.index.publicapi; + +/** + * 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; + +import org.apache.lucene.document.Document; +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.MergePolicy; +import org.apache.lucene.index.MergeScheduler; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.util.LuceneTestCase; + +/** + * Verifies that we expose the necessary API for someone to implement his own + * MergeScheduler. + */ +public class TestCustomMergeScheduler extends LuceneTestCase { + + private static class ReportingMergeScheduler extends MergeScheduler { + + @Override + public void merge(IndexWriter writer) throws CorruptIndexException, IOException { + while(true) { + MergePolicy.OneMerge merge = writer.getNextMerge(); + if (merge == null) + break; + if (VERBOSE) { + System.out.println("executing merge " + merge.segString(writer.getDirectory())); + } + writer.merge(merge); + } + } + + @Override + public void close() throws CorruptIndexException, IOException {} + + } + + public void testCustomMergeScheduler() throws Exception { + // we don't really need to execute anything, just to make sure the custom MS + // compiles. But ensure that it can be used as well, e.g., no other hidden + // dependencies or something. Therefore, don't use any random API ! + Directory dir = new RAMDirectory(); + IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null); + conf.setMergeScheduler(new ReportingMergeScheduler()); + IndexWriter writer = new IndexWriter(dir, conf); + writer.addDocument(new Document()); + writer.commit(); // trigger flush + writer.addDocument(new Document()); + writer.commit(); // trigger flush + writer.optimize(); + writer.close(); + dir.close(); + } + +} Property changes on: lucene/src/test/org/apache/lucene/index/publicapi/TestCustomMergeScheduler.java ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Index: lucene/src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/IndexWriter.java (revision 1098529) +++ lucene/src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -2621,7 +2621,7 @@ /** Expert: the {@link MergeScheduler} calls this method * to retrieve the next merge requested by the * MergePolicy */ - synchronized MergePolicy.OneMerge getNextMerge() { + public synchronized MergePolicy.OneMerge getNextMerge() { if (pendingMerges.size() == 0) return null; else { @@ -3599,8 +3599,7 @@ * Merges the indicated segments, replacing them in the stack with a * single segment. */ - - final void merge(MergePolicy.OneMerge merge) + public final void merge(MergePolicy.OneMerge merge) throws CorruptIndexException, IOException { boolean success = false;