lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r925462 [1/2] - in /lucene/java/trunk: ./ backwards/src/java/org/apache/lucene/index/ backwards/src/test/org/apache/lucene/index/ contrib/ant/src/java/org/apache/lucene/ant/ contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/task...
Date Fri, 19 Mar 2010 22:25:58 GMT
Author: mikemccand
Date: Fri Mar 19 22:25:56 2010
New Revision: 925462

URL: http://svn.apache.org/viewvc?rev=925462&view=rev
Log:
LUCENE-2320: move configuration of MergePolicy to IndexWriterConfig

Added:
    lucene/java/trunk/src/java/org/apache/lucene/util/SetOnce.java   (with props)
    lucene/java/trunk/src/test/org/apache/lucene/util/TestSetOnce.java   (with props)
Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/backwards/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java
    lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogDocMergePolicy.java
    lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogMergePolicy.java
    lucene/java/trunk/backwards/src/java/org/apache/lucene/index/MergePolicy.java
    lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java
    lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java
    lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
    lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
    lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java
    lucene/java/trunk/contrib/ant/src/java/org/apache/lucene/ant/IndexTask.java
    lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java
    lucene/java/trunk/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
    lucene/java/trunk/contrib/misc/src/java/org/apache/lucene/index/BalancedSegmentMergePolicy.java
    lucene/java/trunk/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java
    lucene/java/trunk/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
    lucene/java/trunk/contrib/wordnet/src/java/org/apache/lucene/wordnet/Syns2Index.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriterConfig.java
    lucene/java/trunk/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java
    lucene/java/trunk/src/java/org/apache/lucene/index/LogDocMergePolicy.java
    lucene/java/trunk/src/java/org/apache/lucene/index/LogMergePolicy.java
    lucene/java/trunk/src/java/org/apache/lucene/index/MergePolicy.java
    lucene/java/trunk/src/java/org/apache/lucene/index/MergeScheduler.java
    lucene/java/trunk/src/test/org/apache/lucene/TestSearch.java
    lucene/java/trunk/src/test/org/apache/lucene/TestSearchForDuplicates.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestAtomicUpdate.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexFileDeleter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderClone.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterConfig.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterDelete.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterMerging.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriterReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestLazyBug.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestLazyProxSkipping.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestNRTReaderWithThreads.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestNorms.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestOmitTf.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestThreadedOptimize.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestTransactions.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestElevationComparator.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
    lucene/java/trunk/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
    lucene/java/trunk/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Mar 19 22:25:56 2010
@@ -27,6 +27,15 @@ Changes in backwards compatibility polic
   This means that terms with a position increment gap of zero do not
   affect the norms calculation by default.  (Robert Muir)
 
+* LUCENE-2320: MergePolicy.writer is now of type SetOnce, which allows setting
+  the IndexWriter for a MergePolicy exactly once. You can change references to
+  'writer' from <code>writer.doXYZ()</code> to <code>writer.get().doXYZ()</code>
+  (it is also advisable to add an <code>assert writer != null;</code> before you
+  access the wrapped IndexWriter.
+  In addition, MergePolicy only exposes a default constructor, and the one that
+  took IndexWriter as argument has been removed from all MergePolicy extensions.
+  (Shai Erera via Mike McCandless)
+
 Changes in runtime behavior
 
 * LUCENE-1923: Made IndexReader.toString() produce something
@@ -94,6 +103,10 @@ API Changes
   Additionally, the setter/getter related to MergePolicy were deprecated as 
   well. One should interact with the MergePolicy directly.
   (Shai Erera via Mike McCandless)
+  
+* LUCENE-2320: IndexWriter's MergePolicy configuration was moved to 
+  IndexWriterConfig and the respective methods on IndexWriter were deprecated.
+  (Shai Erera via Mike McCandless) 
 
 Bug fixes
 
@@ -166,6 +179,9 @@ New features
 
 * LUCENE-2247: Added a CharArrayMap<V> for performance improvements
   in some stemmers and synonym filters. (Uwe Schindler)
+  
+* LUCENE-2320: Added SetOnce which wraps an object and allows it to be set 
+  exactly once. (Shai Erera via Mike McCandless)
 
 * LUCENE-2314: Added AttributeSource.copyTo(AttributeSource) that
   allows to use cloneAttributes() and this method as a replacement

Modified: lucene/java/trunk/backwards/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/java/org/apache/lucene/index/IndexWriter.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/backwards/src/java/org/apache/lucene/index/IndexWriter.java Fri Mar 19 22:25:56 2010
@@ -279,7 +279,7 @@ public class IndexWriter implements Clos
   // merges
   private HashSet<SegmentInfo> mergingSegments = new HashSet<SegmentInfo>();
 
-  private MergePolicy mergePolicy = new LogByteSizeMergePolicy(this);
+  private MergePolicy mergePolicy = new LogByteSizeMergePolicy();
   private MergeScheduler mergeScheduler = new ConcurrentMergeScheduler();
   private LinkedList<MergePolicy.OneMerge> pendingMerges = new LinkedList<MergePolicy.OneMerge>();
   private Set<MergePolicy.OneMerge> runningMerges = new HashSet<MergePolicy.OneMerge>();

Modified: lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java (original)
+++ lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java Fri Mar 19 22:25:56 2010
@@ -30,8 +30,7 @@ public class LogByteSizeMergePolicy exte
    *  or larger will never be merged.  @see setMaxMergeMB */
   public static final double DEFAULT_MAX_MERGE_MB = Long.MAX_VALUE;
 
-  public LogByteSizeMergePolicy(IndexWriter writer) {
-    super(writer);
+  public LogByteSizeMergePolicy() {
     minMergeSize = (long) (DEFAULT_MIN_MERGE_MB*1024*1024);
     maxMergeSize = (long) (DEFAULT_MAX_MERGE_MB*1024*1024);
   }

Modified: lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogDocMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogDocMergePolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogDocMergePolicy.java (original)
+++ lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogDocMergePolicy.java Fri Mar 19 22:25:56 2010
@@ -28,8 +28,7 @@ public class LogDocMergePolicy extends L
   /** Default minimum segment size.  @see setMinMergeDocs */
   public static final int DEFAULT_MIN_MERGE_DOCS = 1000;
 
-  public LogDocMergePolicy(IndexWriter writer) {
-    super(writer);
+  public LogDocMergePolicy() {
     minMergeSize = DEFAULT_MIN_MERGE_DOCS;
 
     // maxMergeSize is never used by LogDocMergePolicy; set

Modified: lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogMergePolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogMergePolicy.java (original)
+++ lucene/java/trunk/backwards/src/java/org/apache/lucene/index/LogMergePolicy.java Fri Mar 19 22:25:56 2010
@@ -66,10 +66,6 @@ public abstract class LogMergePolicy ext
   private boolean useCompoundFile = true;
   private boolean useCompoundDocStore = true;
 
-  public LogMergePolicy(IndexWriter writer) {
-    super(writer);
-  }
-  
   protected boolean verbose() {
     return writer != null && writer.verbose();
   }

Modified: lucene/java/trunk/backwards/src/java/org/apache/lucene/index/MergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/java/org/apache/lucene/index/MergePolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/java/org/apache/lucene/index/MergePolicy.java (original)
+++ lucene/java/trunk/backwards/src/java/org/apache/lucene/index/MergePolicy.java Fri Mar 19 22:25:56 2010
@@ -200,8 +200,8 @@ public abstract class MergePolicy implem
 
   final protected IndexWriter writer;
   
-  public MergePolicy(IndexWriter writer) {
-    this.writer = writer;
+  public MergePolicy() {
+    this.writer = null;
   }
 
   /**

Modified: lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java (original)
+++ lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java Fri Mar 19 22:25:56 2010
@@ -429,7 +429,7 @@ public class TestAddIndexesNoOptimize ex
   private IndexWriter newWriter(Directory dir, boolean create)
       throws IOException {
     final IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), create, IndexWriter.MaxFieldLength.UNLIMITED);
-    writer.setMergePolicy(new LogDocMergePolicy(writer));
+    writer.setMergePolicy(new LogDocMergePolicy());
     return writer;
   }
 
@@ -503,7 +503,7 @@ public class TestAddIndexesNoOptimize ex
 
     Directory dir = new MockRAMDirectory();
     IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
-    writer.setMergePolicy(new LogByteSizeMergePolicy(writer));
+    writer.setMergePolicy(new LogByteSizeMergePolicy());
     writer.setMaxBufferedDocs(5);
     writer.setUseCompoundFile(false);
     writer.setMergeFactor(100);
@@ -529,7 +529,7 @@ public class TestAddIndexesNoOptimize ex
 
     Directory dir2 = new MockRAMDirectory();
     writer = new IndexWriter(dir2, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
-    LogByteSizeMergePolicy lmp = new LogByteSizeMergePolicy(writer);
+    LogByteSizeMergePolicy lmp = new LogByteSizeMergePolicy();
     lmp.setMinMergeMB(0.0001);
     writer.setMergePolicy(lmp);
     writer.setMergeFactor(4);

Modified: lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java (original)
+++ lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java Fri Mar 19 22:25:56 2010
@@ -120,7 +120,7 @@ public class TestConcurrentMergeSchedule
     ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler();
     writer.setMergeScheduler(cms);
 
-    LogDocMergePolicy mp = new LogDocMergePolicy(writer);
+    LogDocMergePolicy mp = new LogDocMergePolicy();
     writer.setMergePolicy(mp);
 
     // Force degenerate merging so we can get a mix of

Modified: lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexReaderReopen.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexReaderReopen.java (original)
+++ lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexReaderReopen.java Fri Mar 19 22:25:56 2010
@@ -949,7 +949,7 @@ public class TestIndexReaderReopen exten
     IndexWriter.unlock(dir);
     IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
 
-    w.setMergePolicy(new LogDocMergePolicy(w));
+    w.setMergePolicy(new LogDocMergePolicy());
     
     for (int i = 0; i < 100; i++) {
       w.addDocument(createDocument(i, 4));

Modified: lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriter.java Fri Mar 19 22:25:56 2010
@@ -608,7 +608,7 @@ public class TestIndexWriter extends Luc
 
       for(int numDocs=38;numDocs<500;numDocs += 38) {
         IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
-        LogDocMergePolicy ldmp = new LogDocMergePolicy(writer);
+        LogDocMergePolicy ldmp = new LogDocMergePolicy();
         ldmp.setMinMergeDocs(1);
         writer.setMergePolicy(ldmp);
         writer.setMergeFactor(5);
@@ -622,6 +622,8 @@ public class TestIndexWriter extends Luc
         final int segCount = sis.size();
 
         writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
+        ldmp = new LogDocMergePolicy();
+        ldmp.setMinMergeDocs(1);
         writer.setMergePolicy(ldmp);
         writer.setMergeFactor(5);
         writer.optimize(3);
@@ -645,7 +647,7 @@ public class TestIndexWriter extends Luc
       doc.add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED));
 
       IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
-      LogDocMergePolicy ldmp = new LogDocMergePolicy(writer);
+      LogDocMergePolicy ldmp = new LogDocMergePolicy();
       ldmp.setMinMergeDocs(1);
       writer.setMergePolicy(ldmp);
       writer.setMergeFactor(4);
@@ -2757,7 +2759,7 @@ public class TestIndexWriter extends Luc
       writer.setMaxBufferedDocs(2);
       writer.setRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
       writer.setMergeScheduler(new SerialMergeScheduler());
-      writer.setMergePolicy(new LogDocMergePolicy(writer));
+      writer.setMergePolicy(new LogDocMergePolicy());
 
       Document document = new Document();
 
@@ -2790,7 +2792,7 @@ public class TestIndexWriter extends Luc
       writer.setMaxBufferedDocs(2);
       writer.setRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
       writer.setMergeScheduler(new SerialMergeScheduler());
-      writer.setMergePolicy(new LogDocMergePolicy(writer));
+      writer.setMergePolicy(new LogDocMergePolicy());
 
       Directory[] indexDirs = {new MockRAMDirectory(dir)};
       writer.addIndexesNoOptimize(indexDirs);
@@ -2809,7 +2811,7 @@ public class TestIndexWriter extends Luc
       writer.setMaxBufferedDocs(2);
       writer.setRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
       writer.setMergeScheduler(new SerialMergeScheduler());
-      writer.setMergePolicy(new LogDocMergePolicy(writer));
+      writer.setMergePolicy(new LogDocMergePolicy());
 
       Document document = new Document();
 
@@ -2847,7 +2849,7 @@ public class TestIndexWriter extends Luc
     writer.setMaxBufferedDocs(2);
     writer.setRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
     writer.setMergeScheduler(new SerialMergeScheduler());
-    writer.setMergePolicy(new LogDocMergePolicy(writer));
+    writer.setMergePolicy(new LogDocMergePolicy());
 
     Document document = new Document();
 
@@ -2869,7 +2871,7 @@ public class TestIndexWriter extends Luc
     writer.setMaxBufferedDocs(2);
     writer.setRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
     writer.setMergeScheduler(new SerialMergeScheduler());
-    writer.setMergePolicy(new LogDocMergePolicy(writer));
+    writer.setMergePolicy(new LogDocMergePolicy());
     for(int i=0;i<6;i++)
       writer.addDocument(document);
 

Modified: lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java (original)
+++ lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java Fri Mar 19 22:25:56 2010
@@ -37,7 +37,7 @@ public class TestIndexWriterMergePolicy 
     IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
     writer.setMaxBufferedDocs(10);
     writer.setMergeFactor(10);
-    writer.setMergePolicy(new LogDocMergePolicy(writer));
+    writer.setMergePolicy(new LogDocMergePolicy());
 
     for (int i = 0; i < 100; i++) {
       addDoc(writer);
@@ -54,7 +54,7 @@ public class TestIndexWriterMergePolicy 
     IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
     writer.setMaxBufferedDocs(10);
     writer.setMergeFactor(10);
-    writer.setMergePolicy(new LogDocMergePolicy(writer));
+    writer.setMergePolicy(new LogDocMergePolicy());
 
     boolean noOverMerge = false;
     for (int i = 0; i < 100; i++) {
@@ -76,7 +76,7 @@ public class TestIndexWriterMergePolicy 
     IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
     writer.setMaxBufferedDocs(10);
     writer.setMergeFactor(10);
-    LogDocMergePolicy mp = new LogDocMergePolicy(writer);
+    LogDocMergePolicy mp = new LogDocMergePolicy();
     mp.setMinMergeDocs(100);
     writer.setMergePolicy(mp);
 
@@ -86,6 +86,7 @@ public class TestIndexWriterMergePolicy 
 
       writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
       writer.setMaxBufferedDocs(10);
+      mp = new LogDocMergePolicy();
       writer.setMergePolicy(mp);
       mp.setMinMergeDocs(100);
       writer.setMergeFactor(10);
@@ -102,7 +103,7 @@ public class TestIndexWriterMergePolicy 
     IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
     writer.setMaxBufferedDocs(10);
     writer.setMergeFactor(100);
-    writer.setMergePolicy(new LogDocMergePolicy(writer));
+    writer.setMergePolicy(new LogDocMergePolicy());
 
     for (int i = 0; i < 250; i++) {
       addDoc(writer);
@@ -128,7 +129,7 @@ public class TestIndexWriterMergePolicy 
     IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
     writer.setMaxBufferedDocs(101);
     writer.setMergeFactor(101);
-    writer.setMergePolicy(new LogDocMergePolicy(writer));
+    writer.setMergePolicy(new LogDocMergePolicy());
 
     // leftmost* segment has 1 doc
     // rightmost* segment has 100 docs
@@ -142,7 +143,7 @@ public class TestIndexWriterMergePolicy 
       writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);
       writer.setMaxBufferedDocs(101);
       writer.setMergeFactor(101);
-      writer.setMergePolicy(new LogDocMergePolicy(writer));
+      writer.setMergePolicy(new LogDocMergePolicy());
     }
 
     writer.setMaxBufferedDocs(10);
@@ -171,7 +172,7 @@ public class TestIndexWriterMergePolicy 
     Directory dir = new RAMDirectory();
 
     IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
-    writer.setMergePolicy(new LogDocMergePolicy(writer));
+    writer.setMergePolicy(new LogDocMergePolicy());
     writer.setMaxBufferedDocs(10);
     writer.setMergeFactor(100);
 
@@ -186,7 +187,7 @@ public class TestIndexWriterMergePolicy 
     reader.close();
 
     writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);
-    writer.setMergePolicy(new LogDocMergePolicy(writer));
+    writer.setMergePolicy(new LogDocMergePolicy());
     writer.setMaxBufferedDocs(10);
     writer.setMergeFactor(5);
 

Modified: lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java (original)
+++ lucene/java/trunk/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java Fri Mar 19 22:25:56 2010
@@ -572,7 +572,7 @@ public class TestIndexWriterReader exten
       boolean multiSegment) throws IOException {
     IndexWriter w = new IndexWriter(dir1, new WhitespaceAnalyzer(),
         IndexWriter.MaxFieldLength.LIMITED);
-    w.setMergePolicy(new LogDocMergePolicy(w));
+    w.setMergePolicy(new LogDocMergePolicy());
     for (int i = 0; i < 100; i++) {
       w.addDocument(createDocument(i, indexName, 4));
       if (multiSegment && (i % 10) == 0) {

Modified: lucene/java/trunk/contrib/ant/src/java/org/apache/lucene/ant/IndexTask.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/ant/src/java/org/apache/lucene/ant/IndexTask.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/contrib/ant/src/java/org/apache/lucene/ant/IndexTask.java (original)
+++ lucene/java/trunk/contrib/ant/src/java/org/apache/lucene/ant/IndexTask.java Fri Mar 19 22:25:56 2010
@@ -283,13 +283,14 @@ public class IndexTask extends Task {
 
       log("checkLastModified = " + checkLastModified, Project.MSG_VERBOSE);
 
-      IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+      IndexWriterConfig conf = new IndexWriterConfig(
           Version.LUCENE_CURRENT, analyzer).setOpenMode(
-          create ? OpenMode.CREATE : OpenMode.APPEND));
-      LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+          create ? OpenMode.CREATE : OpenMode.APPEND);
+      LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundIndex);
       lmp.setUseCompoundDocStore(useCompoundIndex);
       lmp.setMergeFactor(mergeFactor);
+      IndexWriter writer = new IndexWriter(dir, conf);
       int totalFiles = 0;
       int totalIndexed = 0;
       int totalIgnored = 0;

Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java Fri Mar 19 22:25:56 2010
@@ -91,7 +91,7 @@ public class CreateIndexTask extends Per
     final String mergePolicy = config.get("merge.policy",
                                           "org.apache.lucene.index.LogByteSizeMergePolicy");
     try {
-      writer.setMergePolicy(Class.forName(mergePolicy).asSubclass(MergePolicy.class).getConstructor(IndexWriter.class).newInstance(writer));
+      writer.setMergePolicy(Class.forName(mergePolicy).asSubclass(MergePolicy.class).newInstance());
     } catch (Exception e) {
       throw new RuntimeException("unable to instantiate class '" + mergePolicy + "' as merge policy", e);
     }

Modified: lucene/java/trunk/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java (original)
+++ lucene/java/trunk/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java Fri Mar 19 22:25:56 2010
@@ -676,11 +676,11 @@ public class TestPerfTasksLogic extends 
 
   public static class MyMergePolicy extends LogDocMergePolicy {
     boolean called;
-    public MyMergePolicy(IndexWriter writer) {
-      super(writer);
+    public MyMergePolicy() {
       called = true;
     }
   }
+  
   /**
    * Test that we can set merge policy".
    */
@@ -710,7 +710,7 @@ public class TestPerfTasksLogic extends 
 
     // 2. execute the algorithm  (required in every "logic" test)
     Benchmark benchmark = execBenchmark(algLines);
-    assertTrue("did not use the specified MergeScheduler", ((MyMergePolicy) benchmark.getRunData().getIndexWriter().getMergePolicy()).called);
+    assertTrue("did not use the specified MergePolicy", ((MyMergePolicy) benchmark.getRunData().getIndexWriter().getConfig().getMergePolicy()).called);
     benchmark.getRunData().getIndexWriter().close();
     
     // 3. test number of docs in the index
@@ -754,8 +754,8 @@ public class TestPerfTasksLogic extends 
     final IndexWriter writer = benchmark.getRunData().getIndexWriter();
     assertEquals(2, writer.getConfig().getMaxBufferedDocs());
     assertEquals(IndexWriterConfig.DISABLE_AUTO_FLUSH, (int) writer.getConfig().getRAMBufferSizeMB());
-    assertEquals(3, ((LogMergePolicy) writer.getMergePolicy()).getMergeFactor());
-    assertFalse(((LogMergePolicy) writer.getMergePolicy()).getUseCompoundFile());
+    assertEquals(3, ((LogMergePolicy) writer.getConfig().getMergePolicy()).getMergeFactor());
+    assertFalse(((LogMergePolicy) writer.getConfig().getMergePolicy()).getUseCompoundFile());
     writer.close();
     Directory dir = benchmark.getRunData().getDirectory();
     IndexReader reader = IndexReader.open(dir, true);

Modified: lucene/java/trunk/contrib/misc/src/java/org/apache/lucene/index/BalancedSegmentMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/misc/src/java/org/apache/lucene/index/BalancedSegmentMergePolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/contrib/misc/src/java/org/apache/lucene/index/BalancedSegmentMergePolicy.java (original)
+++ lucene/java/trunk/contrib/misc/src/java/org/apache/lucene/index/BalancedSegmentMergePolicy.java Fri Mar 19 22:25:56 2010
@@ -30,19 +30,18 @@ import java.util.Set;
  * <p>This is based on code from zoie, described in more detail
  * at http://code.google.com/p/zoie/wiki/ZoieMergePolicy.</p>
  */
-public class BalancedSegmentMergePolicy extends LogByteSizeMergePolicy
-{
+public class BalancedSegmentMergePolicy extends LogByteSizeMergePolicy {
+  
   public static final int DEFAULT_NUM_LARGE_SEGMENTS = 10;
   
   private boolean _partialExpunge = false;
   private int _numLargeSegments = DEFAULT_NUM_LARGE_SEGMENTS;
   private int _maxSmallSegments = 2 * LogMergePolicy.DEFAULT_MERGE_FACTOR;
   private int _maxSegments = _numLargeSegments + _maxSmallSegments;
-  
-  public BalancedSegmentMergePolicy(IndexWriter writer) {
-    super(writer);
+
+  public BalancedSegmentMergePolicy() {
   }
-  
+
   public void setMergePolicyParams(MergePolicyParams params) {
     if (params!=null) {
       setPartialExpunge(params._doPartialExpunge);
@@ -122,6 +121,7 @@ public class BalancedSegmentMergePolicy 
   
   private boolean isOptimized(IndexWriter writer, SegmentInfo info)
     throws IOException {
+    assert writer != null;
     return !info.hasDeletions() &&
       !info.hasSeparateNorms() &&
       info.dir == writer.getDirectory() &&
@@ -135,7 +135,7 @@ public class BalancedSegmentMergePolicy 
 
     MergeSpecification spec = null;
 
-    if (!isOptimized(infos, writer, maxNumSegments, segmentsToOptimize)) {
+    if (!isOptimized(infos, writer.get(), maxNumSegments, segmentsToOptimize)) {
 
       // Find the newest (rightmost) segment that needs to
       // be optimized (other segments may have been flushed
@@ -158,7 +158,7 @@ public class BalancedSegmentMergePolicy 
           // Since we must optimize down to 1 segment, the
           // choice is simple:
           boolean useCompoundFile = getUseCompoundFile();
-          if (last > 1 || !isOptimized(writer, infos.info(0))) {
+          if (last > 1 || !isOptimized(writer.get(), infos.info(0))) {
 
             spec = new MergeSpecification();
             spec.add(new OneMerge(infos.range(0, last), useCompoundFile));

Modified: lucene/java/trunk/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java (original)
+++ lucene/java/trunk/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java Fri Mar 19 22:25:56 2010
@@ -114,7 +114,7 @@ public class TestRemoteSort extends Luce
     IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(
         TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT))
         .setMaxBufferedDocs(2));
-    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(1000);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(1000);
     for (int i=0; i<data.length; ++i) {
       if (((i%2)==0 && even) || ((i%2)==1 && odd)) {
         Document doc = new Document();

Modified: lucene/java/trunk/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java (original)
+++ lucene/java/trunk/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java Fri Mar 19 22:25:56 2010
@@ -397,7 +397,7 @@ public class SpellChecker implements jav
       ensureOpen();
       final Directory dir = this.spellIndex;
       final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Version.LUCENE_CURRENT, new WhitespaceAnalyzer(Version.LUCENE_CURRENT)).setRAMBufferSizeMB(ramMB));
-      ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(mergeFactor);
+      ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(mergeFactor);
   
       Iterator<String> iter = dict.getWordsIterator();
       while (iter.hasNext()) {

Modified: lucene/java/trunk/contrib/wordnet/src/java/org/apache/lucene/wordnet/Syns2Index.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/wordnet/src/java/org/apache/lucene/wordnet/Syns2Index.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/contrib/wordnet/src/java/org/apache/lucene/wordnet/Syns2Index.java (original)
+++ lucene/java/trunk/contrib/wordnet/src/java/org/apache/lucene/wordnet/Syns2Index.java Fri Mar 19 22:25:56 2010
@@ -250,8 +250,8 @@ public class Syns2Index
           // override the specific index if it already exists
           IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
               Version.LUCENE_CURRENT, ana).setOpenMode(OpenMode.CREATE));
-          ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(true); // why?
-          ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(true); // why?
+          ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(true); // why?
+          ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(true); // why?
           Iterator<String> i1 = word2Nums.keySet().iterator();
           while (i1.hasNext()) // for each word
           {

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Fri Mar 19 22:25:56 2010
@@ -290,7 +290,7 @@ public class IndexWriter implements Clos
   // merges
   private HashSet<SegmentInfo> mergingSegments = new HashSet<SegmentInfo>();
 
-  private MergePolicy mergePolicy = new LogByteSizeMergePolicy(this);
+  private MergePolicy mergePolicy;
   // TODO 4.0: this should be made final once the setter is removed
   private /*final*/MergeScheduler mergeScheduler;
   private LinkedList<MergePolicy.OneMerge> pendingMerges = new LinkedList<MergePolicy.OneMerge>();
@@ -871,8 +871,8 @@ public class IndexWriter implements Clos
   public void setTermIndexInterval(int interval) {
     ensureOpen();
     this.termIndexInterval = interval;
-    // Required so config.getSimilarity returns the right value. But this will
-    // go away together with the method in 4.0.
+    // Required so config.getTermIndexInterval returns the right value. But this
+    // will go away together with the method in 4.0.
     config.setTermIndexInterval(interval);
   }
 
@@ -1077,6 +1077,8 @@ public class IndexWriter implements Clos
     termIndexInterval = conf.getTermIndexInterval();
     writeLockTimeout = conf.getWriteLockTimeout();
     similarity = conf.getSimilarity();
+    mergePolicy = conf.getMergePolicy();
+    mergePolicy.setIndexWriter(this);
     mergeScheduler = conf.getMergeScheduler();
     mergedSegmentWarmer = conf.getMergedSegmentWarmer();
     
@@ -1210,6 +1212,8 @@ public class IndexWriter implements Clos
   
   /**
    * Expert: set the merge policy used by this writer.
+   * 
+   * @deprecated use {@link IndexWriterConfig#setMergePolicy(MergePolicy)} instead.
    */
   public void setMergePolicy(MergePolicy mp) {
     ensureOpen();
@@ -1219,14 +1223,20 @@ public class IndexWriter implements Clos
     if (mergePolicy != mp)
       mergePolicy.close();
     mergePolicy = mp;
+    mergePolicy.setIndexWriter(this);
     pushMaxBufferedDocs();
     if (infoStream != null)
       message("setMergePolicy " + mp);
+    // Required so config.getMergePolicy returns the right value. But this will
+    // go away together with the method in 4.0.
+    config.setMergePolicy(mp);
   }
 
   /**
    * Expert: returns the current MergePolicy in use by this writer.
    * @see #setMergePolicy
+   * 
+   * @deprecated use {@link IndexWriterConfig#getMergePolicy()} instead
    */
   public MergePolicy getMergePolicy() {
     ensureOpen();
@@ -1249,7 +1259,7 @@ public class IndexWriter implements Clos
     this.mergeScheduler = mergeScheduler;
     if (infoStream != null)
       message("setMergeScheduler " + mergeScheduler);
-    // Required so config.getSimilarity returns the right value. But this will
+    // Required so config.getMergeScheduler returns the right value. But this will
     // go away together with the method in 4.0.
     config.setMergeScheduler(mergeScheduler);
   }
@@ -1327,8 +1337,8 @@ public class IndexWriter implements Clos
     docWriter.setMaxFieldLength(maxFieldLength);
     if (infoStream != null)
       message("setMaxFieldLength " + maxFieldLength);
-    // Required so config.getSimilarity returns the right value. But this will
-    // go away together with the method in 4.0.
+    // Required so config.getMaxFieldLength returns the right value. But this
+    // will go away together with the method in 4.0.
     config.setMaxFieldLength(maxFieldLength);
   }
 
@@ -1376,8 +1386,8 @@ public class IndexWriter implements Clos
     pushMaxBufferedDocs();
     if (infoStream != null)
       message("setMaxBufferedDocs " + maxBufferedDocs);
-    // Required so config.getSimilarity returns the right value. But this will
-    // go away together with the method in 4.0.
+    // Required so config.getMaxBufferedDocs returns the right value. But this
+    // will go away together with the method in 4.0.
     config.setMaxBufferedDocs(maxBufferedDocs);
   }
 
@@ -1464,8 +1474,8 @@ public class IndexWriter implements Clos
     docWriter.setRAMBufferSizeMB(mb);
     if (infoStream != null)
       message("setRAMBufferSizeMB " + mb);
-    // Required so config.getSimilarity returns the right value. But this will
-    // go away together with the method in 4.0.
+    // Required so config.getRAMBufferSizeMB returns the right value. But this
+    // will go away together with the method in 4.0.
     config.setRAMBufferSizeMB(mb);
   }
 
@@ -1499,8 +1509,8 @@ public class IndexWriter implements Clos
     docWriter.setMaxBufferedDeleteTerms(maxBufferedDeleteTerms);
     if (infoStream != null)
       message("setMaxBufferedDeleteTerms " + maxBufferedDeleteTerms);
-    // Required so config.getSimilarity returns the right value. But this will
-    // go away together with the method in 4.0.
+    // Required so config.getMaxBufferedDeleteTerms returns the right value. But
+    // this will go away together with the method in 4.0.
     config.setMaxBufferedDeleteTerms(maxBufferedDeleteTerms);
   }
 
@@ -1612,8 +1622,8 @@ public class IndexWriter implements Clos
   public void setWriteLockTimeout(long writeLockTimeout) {
     ensureOpen();
     this.writeLockTimeout = writeLockTimeout;
-    // Required so config.getSimilarity returns the right value. But this will
-    // go away together with the method in 4.0.
+    // Required so config.getWriteLockTimeout returns the right value. But this
+    // will go away together with the method in 4.0.
     config.setWriteLockTimeout(writeLockTimeout);
   }
 
@@ -4959,8 +4969,8 @@ public class IndexWriter implements Clos
    */
   public void setMergedSegmentWarmer(IndexReaderWarmer warmer) {
     mergedSegmentWarmer = warmer;
-    // Required so config.getSimilarity returns the right value. But this will
-    // go away together with the method in 4.0.
+    // Required so config.getMergedSegmentWarmer returns the right value. But
+    // this will go away together with the method in 4.0.
     config.setMergedSegmentWarmer(mergedSegmentWarmer);
   }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriterConfig.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriterConfig.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriterConfig.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriterConfig.java Fri Mar 19 22:25:56 2010
@@ -116,6 +116,7 @@ public final class IndexWriterConfig imp
   private int maxBufferedDocs;
   private IndexingChain indexingChain;
   private IndexReaderWarmer mergedSegmentWarmer;
+  private MergePolicy mergePolicy;
   private int maxThreadStates;
   
   // required for clone
@@ -144,6 +145,7 @@ public final class IndexWriterConfig imp
     maxBufferedDocs = DEFAULT_MAX_BUFFERED_DOCS;
     indexingChain = DocumentsWriter.defaultIndexingChain;
     mergedSegmentWarmer = null;
+    mergePolicy = new LogByteSizeMergePolicy();
     maxThreadStates = DEFAULT_MAX_THREAD_STATES;
   }
   
@@ -491,10 +493,26 @@ public final class IndexWriterConfig imp
     return mergedSegmentWarmer;
   }
 
-  /** Sets the max number of simultaneous threads that may
-   *  be indexing documents at once in IndexWriter. */
+  /**
+   * Expert: {@link MergePolicy} is invoked whenever there are changes to the
+   * segments in the index. Its role is to select which merges to do, if any,
+   * and return a {@link MergePolicy.MergeSpecification} describing the merges.
+   * It also selects merges to do for optimize(). (The default is
+   * {@link LogByteSizeMergePolicy}.
+   */
+  public IndexWriterConfig setMergePolicy(MergePolicy mergePolicy) {
+    this.mergePolicy = mergePolicy == null ? new LogByteSizeMergePolicy() : mergePolicy;
+    return this;
+  }
+  
+  /**
+   * Sets the max number of simultaneous threads that may be indexing documents
+   * at once in IndexWriter. Values &lt; 1 are invalid and if passed
+   * <code>maxThreadStates</code> will be set to
+   * {@link #DEFAULT_MAX_THREAD_STATES}.
+   */
   public IndexWriterConfig setMaxThreadStates(int maxThreadStates) {
-    this.maxThreadStates = maxThreadStates;
+    this.maxThreadStates = maxThreadStates < 1 ? DEFAULT_MAX_THREAD_STATES : maxThreadStates;
     return this;
   }
 
@@ -504,6 +522,15 @@ public final class IndexWriterConfig imp
     return maxThreadStates;
   }
 
+  /**
+   * Returns the current MergePolicy in use by this writer.
+   * 
+   * @see #setMergePolicy(MergePolicy)
+   */
+  public MergePolicy getMergePolicy() {
+    return mergePolicy;
+  }
+
   /** Expert: sets the {@link DocConsumer} chain to be used to process documents. */
   IndexWriterConfig setIndexingChain(IndexingChain indexingChain) {
     this.indexingChain = indexingChain == null ? DocumentsWriter.defaultIndexingChain : indexingChain;
@@ -533,6 +560,7 @@ public final class IndexWriterConfig imp
     sb.append("ramBufferSizeMB=").append(ramBufferSizeMB).append("\n");
     sb.append("maxBufferedDocs=").append(maxBufferedDocs).append("\n");
     sb.append("mergedSegmentWarmer=").append(mergedSegmentWarmer).append("\n");
+    sb.append("mergePolicy=").append(mergePolicy).append("\n");
     sb.append("maxThreadStates=").append(maxThreadStates).append("\n");
     return sb.toString();
   }

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java Fri Mar 19 22:25:56 2010
@@ -30,11 +30,11 @@ public class LogByteSizeMergePolicy exte
    *  or larger will never be merged.  @see setMaxMergeMB */
   public static final double DEFAULT_MAX_MERGE_MB = Long.MAX_VALUE;
 
-  public LogByteSizeMergePolicy(IndexWriter writer) {
-    super(writer);
+  public LogByteSizeMergePolicy() {
     minMergeSize = (long) (DEFAULT_MIN_MERGE_MB*1024*1024);
     maxMergeSize = (long) (DEFAULT_MAX_MERGE_MB*1024*1024);
   }
+  
   @Override
   protected long size(SegmentInfo info) throws IOException {
     return sizeBytes(info);

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/LogDocMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/LogDocMergePolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/LogDocMergePolicy.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/LogDocMergePolicy.java Fri Mar 19 22:25:56 2010
@@ -28,14 +28,14 @@ public class LogDocMergePolicy extends L
   /** Default minimum segment size.  @see setMinMergeDocs */
   public static final int DEFAULT_MIN_MERGE_DOCS = 1000;
 
-  public LogDocMergePolicy(IndexWriter writer) {
-    super(writer);
+  public LogDocMergePolicy() {
     minMergeSize = DEFAULT_MIN_MERGE_DOCS;
-
+    
     // maxMergeSize is never used by LogDocMergePolicy; set
     // it to Long.MAX_VALUE to disable it
     maxMergeSize = Long.MAX_VALUE;
   }
+
   @Override
   protected long size(SegmentInfo info) throws IOException {
     return sizeDocs(info);

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/LogMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/LogMergePolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/LogMergePolicy.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/LogMergePolicy.java Fri Mar 19 22:25:56 2010
@@ -66,17 +66,18 @@ public abstract class LogMergePolicy ext
   private boolean useCompoundFile = true;
   private boolean useCompoundDocStore = true;
 
-  public LogMergePolicy(IndexWriter writer) {
-    super(writer);
+  public LogMergePolicy() {
+    super();
   }
-  
+
   protected boolean verbose() {
-    return writer != null && writer.verbose();
+    IndexWriter w = writer.get();
+    return w != null && w.verbose();
   }
   
   private void message(String message) {
     if (verbose())
-      writer.message("LMP: " + message);
+      writer.get().message("LMP: " + message);
   }
 
   /** <p>Returns the number of segments that are merged at
@@ -160,7 +161,7 @@ public abstract class LogMergePolicy ext
 
   protected long sizeDocs(SegmentInfo info) throws IOException {
     if (calibrateSizeByDeletes) {
-      int delCount = writer.numDeletedDocs(info);
+      int delCount = writer.get().numDeletedDocs(info);
       return (info.docCount - (long)delCount);
     } else {
       return info.docCount;
@@ -170,7 +171,7 @@ public abstract class LogMergePolicy ext
   protected long sizeBytes(SegmentInfo info) throws IOException {
     long byteSize = info.sizeInBytes();
     if (calibrateSizeByDeletes) {
-      int delCount = writer.numDeletedDocs(info);
+      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)));
     } else {
@@ -199,10 +200,12 @@ public abstract class LogMergePolicy ext
    *  writer, and matches the current compound file setting */
   private boolean isOptimized(SegmentInfo info)
     throws IOException {
-    boolean hasDeletions = writer.numDeletedDocs(info) > 0;
+    IndexWriter w = writer.get();
+    assert w != null;
+    boolean hasDeletions = w.numDeletedDocs(info) > 0;
     return !hasDeletions &&
       !info.hasSeparateNorms() &&
-      info.dir == writer.getDirectory() &&
+      info.dir == w.getDirectory() &&
       info.getUseCompoundFile() == useCompoundFile;
   }
 
@@ -309,9 +312,11 @@ public abstract class LogMergePolicy ext
 
     MergeSpecification spec = new MergeSpecification();
     int firstSegmentWithDeletions = -1;
+    IndexWriter w = writer.get();
+    assert w != null;
     for(int i=0;i<numSegments;i++) {
       final SegmentInfo info = segmentInfos.info(i);
-      int delCount = writer.numDeletedDocs(info);
+      int delCount = w.numDeletedDocs(info);
       if (delCount > 0) {
         if (verbose())
           message("  segment " + info.name + " has deletions");

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/MergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/MergePolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/MergePolicy.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/MergePolicy.java Fri Mar 19 22:25:56 2010
@@ -18,6 +18,8 @@ package org.apache.lucene.index;
  */
 
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.SetOnce;
+import org.apache.lucene.util.SetOnce.AlreadySetException;
 
 import java.io.IOException;
 import java.util.List;
@@ -52,12 +54,6 @@ import java.util.Set;
  * LogByteSizeMergePolicy}.</p>
  *
  * @lucene.experimental
- *
- * <p><b>NOTE</b>: This class typically requires access to
- * package-private APIs (e.g. <code>SegmentInfos</code>) to do its job;
- * if you implement your own MergePolicy, you'll need to put
- * it in package org.apache.lucene.index in order to use
- * these APIs.
  */
 
 public abstract class MergePolicy implements java.io.Closeable {
@@ -225,13 +221,29 @@ public abstract class MergePolicy implem
     }
   }
 
-  final protected IndexWriter writer;
-  
-  public MergePolicy(IndexWriter writer) {
-    this.writer = writer;
+  protected final SetOnce<IndexWriter> writer;
+
+  /**
+   * Creates a new merge policy instance. Note that if you intend to use it
+   * without passing it to {@link IndexWriter}, you should call
+   * {@link #setIndexWriter(IndexWriter)}.
+   */
+  public MergePolicy() {
+    writer = new SetOnce<IndexWriter>();
   }
 
   /**
+   * Sets the {@link IndexWriter} to use by this merge policy. This method is
+   * allowed to be called only once, and is usually set by IndexWriter. If it is
+   * called more than once, {@link AlreadySetException} is thrown.
+   * 
+   * @see SetOnce
+   */
+  public void setIndexWriter(IndexWriter writer) {
+    this.writer.set(writer);
+  }
+  
+  /**
    * Determine what set of merge operations are now necessary on the index.
    * {@link IndexWriter} calls this whenever there is a change to the segments.
    * This call is always synchronized on the {@link IndexWriter} instance so

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/MergeScheduler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/MergeScheduler.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/MergeScheduler.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/MergeScheduler.java Fri Mar 19 22:25:56 2010
@@ -25,12 +25,6 @@ import java.io.IOException;
  *  MergeScheduler is {@link ConcurrentMergeScheduler}.</p>
  *
  * @lucene.experimental
- *
- * <p><b>NOTE</b>: This class typically requires access to
- * package-private APIs (eg, SegmentInfos) to do its job;
- * if you implement your own MergePolicy, you'll need to put
- * it in package org.apache.lucene.index in order to use
- * these APIs.
 */
 
 public abstract class MergeScheduler {

Added: lucene/java/trunk/src/java/org/apache/lucene/util/SetOnce.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/util/SetOnce.java?rev=925462&view=auto
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/util/SetOnce.java (added)
+++ lucene/java/trunk/src/java/org/apache/lucene/util/SetOnce.java Fri Mar 19 22:25:56 2010
@@ -0,0 +1,77 @@
+package org.apache.lucene.util;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * 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.
+ */
+
+/**
+ * A convenient class which offers a semi-immutable object wrapper
+ * implementation which allows one to set the value of an object exactly once,
+ * and retrieve it many times. If {@link #set(Object)} is called more than once,
+ * {@link AlreadySetException} is thrown and the operation
+ * will fail.
+ *
+ * @lucene.experimental
+ */
+public final class SetOnce<T> {
+
+  /** Thrown when {@link SetOnce#set(Object)} is called more than once. */
+  public static final class AlreadySetException extends RuntimeException {
+    public AlreadySetException() {
+      super("The object cannot be set twice!");
+    }
+  }
+  
+  private volatile T obj = null;
+  private final AtomicBoolean set;
+  
+  /**
+   * A default constructor which does not set the internal object, and allows
+   * setting it by calling {@link #set(Object)}.
+   */
+  public SetOnce() {
+    set = new AtomicBoolean(false);
+  }
+
+  /**
+   * Creates a new instnace with the internal object set to the given object.
+   * Note that any calls to {@link #set(Object)} afterwards will result in
+   * {@link AlreadySetException}
+   *
+   * @throws AlreadySetException if called more than once
+   * @see #set(Object)
+   */
+  public SetOnce(T obj) {
+    this.obj = obj;
+    set = new AtomicBoolean(true);
+  }
+  
+  /** Sets the given object. If the object has already been set, an exception is thrown. */
+  public final void set(T obj) {
+    if (set.compareAndSet(false, true)) {
+      this.obj = obj;
+    } else {
+      throw new AlreadySetException();
+    }
+  }
+  
+  /** Returns the object set by {@link #set(Object)}. */
+  public final T get() {
+    return obj;
+  }
+}

Propchange: lucene/java/trunk/src/java/org/apache/lucene/util/SetOnce.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/src/test/org/apache/lucene/TestSearch.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/TestSearch.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/TestSearch.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/TestSearch.java Fri Mar 19 22:25:56 2010
@@ -73,11 +73,11 @@ public class TestSearch extends LuceneTe
     throws Exception {
       Directory directory = new RAMDirectory();
       Analyzer analyzer = new SimpleAnalyzer(TEST_VERSION_CURRENT);
-      IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, analyzer));
-      LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+      IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
+      LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundFile);
       lmp.setUseCompoundDocStore(useCompoundFile);
+      IndexWriter writer = new IndexWriter(directory, conf);
 
       String[] docs = {
         "a b c d e",

Modified: lucene/java/trunk/src/test/org/apache/lucene/TestSearchForDuplicates.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/TestSearchForDuplicates.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/TestSearchForDuplicates.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/TestSearchForDuplicates.java Fri Mar 19 22:25:56 2010
@@ -78,11 +78,11 @@ public class TestSearchForDuplicates ext
   private void doTest(PrintWriter out, boolean useCompoundFiles) throws Exception {
       Directory directory = new RAMDirectory();
       Analyzer analyzer = new SimpleAnalyzer(TEST_VERSION_CURRENT);
-      IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, analyzer));
-      LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+      IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
+      LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundFiles);
       lmp.setUseCompoundDocStore(useCompoundFiles);
+      IndexWriter writer = new IndexWriter(directory, conf);
 
       final int MAX_DOCS = 225;
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestAddIndexesNoOptimize.java Fri Mar 19 22:25:56 2010
@@ -49,8 +49,8 @@ public class TestAddIndexesNoOptimize ex
     writer.close();
 
     writer = newWriter(aux, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
     // add 40 documents in separate files
     addDocs(writer, 40);
     assertEquals(40, writer.maxDoc());
@@ -257,14 +257,14 @@ public class TestAddIndexesNoOptimize ex
     writer.close();
 
     writer = newWriter(aux, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
     // add 140 documents in separate files
     addDocs(writer, 40);
     writer.close();
     writer = newWriter(aux, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
     addDocs(writer, 100);
     writer.close();
 
@@ -297,7 +297,7 @@ public class TestAddIndexesNoOptimize ex
     IndexWriter writer = newWriter(dir, new IndexWriterConfig(
         TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
         .setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(10));
-    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(4);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(4);
     addDocs(writer, 10);
 
     writer.addIndexesNoOptimize(new Directory[] { aux });
@@ -320,7 +320,7 @@ public class TestAddIndexesNoOptimize ex
     setUpDirs(dir, aux);
 
     IndexWriter writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(9));
-    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(4);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(4);
     addDocs(writer, 2);
 
     writer.addIndexesNoOptimize(new Directory[] { aux });
@@ -345,7 +345,7 @@ public class TestAddIndexesNoOptimize ex
     IndexWriter writer = newWriter(dir, new IndexWriterConfig(
         TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
         .setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(10));
-    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(4);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(4);
 
     writer.addIndexesNoOptimize(new Directory[] { aux, new RAMDirectory(aux) });
     assertEquals(1060, writer.maxDoc());
@@ -375,7 +375,7 @@ public class TestAddIndexesNoOptimize ex
     IndexWriter writer = newWriter(dir, new IndexWriterConfig(
         TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
         .setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(4));
-    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(4);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(4);
 
     writer.addIndexesNoOptimize(new Directory[] { aux, new RAMDirectory(aux) });
     assertEquals(1020, writer.maxDoc());
@@ -399,7 +399,7 @@ public class TestAddIndexesNoOptimize ex
     IndexWriter writer = newWriter(aux2, new IndexWriterConfig(
         TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
         .setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(100));
-    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);
     writer.addIndexesNoOptimize(new Directory[] { aux });
     assertEquals(30, writer.maxDoc());
     assertEquals(3, writer.getSegmentCount());
@@ -421,7 +421,7 @@ public class TestAddIndexesNoOptimize ex
 
     writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
         .setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(6));
-    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(4);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(4);
 
     writer.addIndexesNoOptimize(new Directory[] { aux, aux2 });
     assertEquals(1025, writer.maxDoc());
@@ -434,8 +434,8 @@ public class TestAddIndexesNoOptimize ex
 
   private IndexWriter newWriter(Directory dir, IndexWriterConfig conf)
       throws IOException {
+    conf.setMergePolicy(new LogDocMergePolicy());
     final IndexWriter writer = new IndexWriter(dir, conf);
-    writer.setMergePolicy(new LogDocMergePolicy(writer));
     return writer;
   }
 
@@ -486,17 +486,17 @@ public class TestAddIndexesNoOptimize ex
     writer.close();
 
     writer = newWriter(aux, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(100));
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
-    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);
     // add 30 documents in 3 segments
     for (int i = 0; i < 3; i++) {
       addDocs(writer, 10);
       writer.close();
       writer = newWriter(aux, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(100));
-      ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
-      ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
-      ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
+      ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
+      ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
+      ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);
     }
     assertEquals(30, writer.maxDoc());
     assertEquals(3, writer.getSegmentCount());
@@ -507,12 +507,13 @@ public class TestAddIndexesNoOptimize ex
   public void testHangOnClose() throws IOException {
 
     Directory dir = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(5));
-    LogByteSizeMergePolicy lmp = new LogByteSizeMergePolicy(writer);
+    LogByteSizeMergePolicy lmp = new LogByteSizeMergePolicy();
     lmp.setUseCompoundFile(false);
     lmp.setUseCompoundDocStore(false);
     lmp.setMergeFactor(100);
-    writer.setMergePolicy(lmp);
+    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+        TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+        .setMaxBufferedDocs(5).setMergePolicy(lmp));
 
     Document doc = new Document();
     doc.add(new Field("content", "aaa bbb ccc ddd eee fff ggg hhh iii", Field.Store.YES,
@@ -534,13 +535,14 @@ public class TestAddIndexesNoOptimize ex
     writer.close();
 
     Directory dir2 = new MockRAMDirectory();
-    writer = new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMergeScheduler(new SerialMergeScheduler()));
-    lmp = new LogByteSizeMergePolicy(writer);
+    lmp = new LogByteSizeMergePolicy();
     lmp.setMinMergeMB(0.0001);
     lmp.setUseCompoundFile(false);
     lmp.setUseCompoundDocStore(false);
     lmp.setMergeFactor(4);
-    writer.setMergePolicy(lmp);
+    writer = new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT,
+        new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+        .setMergeScheduler(new SerialMergeScheduler()).setMergePolicy(lmp));
     writer.addIndexesNoOptimize(new Directory[] {dir});
     writer.close();
     dir.close();
@@ -552,15 +554,15 @@ public class TestAddIndexesNoOptimize ex
   public void testTargetCFS() throws IOException {
     Directory dir = new RAMDirectory();
     IndexWriter writer = newWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false);
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false);
     addDocs(writer, 1);
     writer.close();
 
     Directory other = new RAMDirectory();
     writer = newWriter(other, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(true);
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(true);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(true);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(true);
     writer.addIndexesNoOptimize(new Directory[] {dir});
     assertTrue(writer.newestSegment().getUseCompoundFile());
     writer.close();

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestAtomicUpdate.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestAtomicUpdate.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestAtomicUpdate.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestAtomicUpdate.java Fri Mar 19 22:25:56 2010
@@ -126,10 +126,11 @@ public class TestAtomicUpdate extends Lu
 
     TimedThread[] threads = new TimedThread[4];
 
-    IndexWriter writer = new MockIndexWriter(directory, new IndexWriterConfig(
+    IndexWriterConfig conf = new IndexWriterConfig(
         TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT))
-        .setMaxBufferedDocs(7));
-    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(3);
+        .setMaxBufferedDocs(7);
+    ((LogMergePolicy) conf.getMergePolicy()).setMergeFactor(3);
+    IndexWriter writer = new MockIndexWriter(directory, conf);
 
     // Establish a base index of 100 docs:
     for(int i=0;i<100;i++) {

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Fri Mar 19 22:25:56 2010
@@ -472,9 +472,10 @@ public class TestBackwardsCompatibility 
     dirName = fullDir(dirName);
 
     Directory dir = FSDirectory.open(new File(dirName));
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(10));
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(doCFS);
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(doCFS);
+    IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(10);
+    ((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(doCFS);
+    ((LogMergePolicy) conf.getMergePolicy()).setUseCompoundDocStore(doCFS);
+    IndexWriter writer = new IndexWriter(dir, conf);
     
     for(int i=0;i<35;i++) {
       addDoc(writer, i);
@@ -483,9 +484,10 @@ public class TestBackwardsCompatibility 
     writer.close();
 
     // open fresh writer so we get no prx file in the added segment
-    writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(10));
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(doCFS);
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(doCFS);
+    conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(10);
+    ((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(doCFS);
+    ((LogMergePolicy) conf.getMergePolicy()).setUseCompoundDocStore(doCFS);
+    writer = new IndexWriter(dir, conf);
     addNoProxDoc(writer);
     writer.close();
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java Fri Mar 19 22:25:56 2010
@@ -109,15 +109,14 @@ public class TestConcurrentMergeSchedule
 
     RAMDirectory directory = new MockRAMDirectory();
 
-    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT)));
-
-    LogDocMergePolicy mp = new LogDocMergePolicy(writer);
-    writer.setMergePolicy(mp);
-
+    LogDocMergePolicy mp = new LogDocMergePolicy();
     // Force degenerate merging so we can get a mix of
     // merging of segments with and without deletes at the
     // start:
     mp.setMinMergeDocs(1000);
+    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(
+        TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT))
+        .setMergePolicy(mp));
 
     Document doc = new Document();
     Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);
@@ -183,7 +182,7 @@ public class TestConcurrentMergeSchedule
     doc.add(idField);
 
     IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(2));
-    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(100);
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(100);
 
     for(int iter=0;iter<10;iter++) {
 
@@ -200,7 +199,7 @@ public class TestConcurrentMergeSchedule
 
       // Force a bunch of merge threads to kick off so we
       // stress out aborting them on close:
-      ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(3);
+      ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(3);
       writer.addDocument(doc);
       writer.commit();
 
@@ -212,7 +211,7 @@ public class TestConcurrentMergeSchedule
 
       // Reopen
       writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
-      ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(100);
+      ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(100);
     }
     writer.close();
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java Fri Mar 19 22:25:56 2010
@@ -202,10 +202,13 @@ public class TestDeletionPolicy extends 
 
     Directory dir = new RAMDirectory();
     ExpirationTimeDeletionPolicy policy = new ExpirationTimeDeletionPolicy(dir, SECONDS);
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setIndexDeletionPolicy(policy));
-    LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+    IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT,
+        new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+        .setIndexDeletionPolicy(policy);
+    LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
     lmp.setUseCompoundFile(useCompoundFile);
     lmp.setUseCompoundDocStore(useCompoundFile);
+    IndexWriter writer = new IndexWriter(dir, conf);
     writer.close();
 
     long lastDeleteTime = 0;
@@ -213,11 +216,13 @@ public class TestDeletionPolicy extends 
       // Record last time when writer performed deletes of
       // past commits
       lastDeleteTime = System.currentTimeMillis();
-      writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
-          .setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy));
-      lmp = (LogMergePolicy) writer.getMergePolicy();
+      conf = new IndexWriterConfig(TEST_VERSION_CURRENT,
+          new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(
+          OpenMode.APPEND).setIndexDeletionPolicy(policy);
+      lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundFile);
       lmp.setUseCompoundDocStore(useCompoundFile);
+      writer = new IndexWriter(dir, conf);
       for(int j=0;j<17;j++) {
         addDoc(writer);
       }
@@ -277,24 +282,26 @@ public class TestDeletionPolicy extends 
       Directory dir = new RAMDirectory();
       policy.dir = dir;
 
-      IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+      IndexWriterConfig conf = new IndexWriterConfig(
           TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
           .setIndexDeletionPolicy(policy).setMaxBufferedDocs(10)
-          .setMergeScheduler(new SerialMergeScheduler()));
-      LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+          .setMergeScheduler(new SerialMergeScheduler());
+      LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundFile);
       lmp.setUseCompoundDocStore(useCompoundFile);
+      IndexWriter writer = new IndexWriter(dir, conf);
       for(int i=0;i<107;i++) {
         addDoc(writer);
       }
       writer.close();
 
-      writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,
+      conf = new IndexWriterConfig(TEST_VERSION_CURRENT,
           new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(
-          OpenMode.APPEND).setIndexDeletionPolicy(policy));
-      lmp = (LogMergePolicy) writer.getMergePolicy();
+          OpenMode.APPEND).setIndexDeletionPolicy(policy);
+      lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundFile);
       lmp.setUseCompoundDocStore(useCompoundFile);
+      writer = new IndexWriter(dir, conf);
       writer.optimize();
       writer.close();
 
@@ -462,23 +469,25 @@ public class TestDeletionPolicy extends 
 
       Directory dir = new RAMDirectory();
 
-      IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+      IndexWriterConfig conf = new IndexWriterConfig(
           TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
           .setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy)
-          .setMaxBufferedDocs(10));
-      LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+          .setMaxBufferedDocs(10);
+      LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundFile);
       lmp.setUseCompoundDocStore(useCompoundFile);
+      IndexWriter writer = new IndexWriter(dir, conf);
       for(int i=0;i<107;i++) {
         addDoc(writer);
       }
       writer.close();
 
-      writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
-          .setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy));
-      lmp = (LogMergePolicy) writer.getMergePolicy();
+      conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+          .setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy);
+      lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundFile);
       lmp.setUseCompoundDocStore(useCompoundFile);
+      writer = new IndexWriter(dir, conf);
       writer.optimize();
       writer.close();
 
@@ -512,13 +521,14 @@ public class TestDeletionPolicy extends 
       KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);
 
       for(int j=0;j<N+1;j++) {
-        IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+        IndexWriterConfig conf = new IndexWriterConfig(
             TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
             .setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy)
-            .setMaxBufferedDocs(10));
-        LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+            .setMaxBufferedDocs(10);
+        LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
         lmp.setUseCompoundFile(useCompoundFile);
         lmp.setUseCompoundDocStore(useCompoundFile);
+        IndexWriter writer = new IndexWriter(dir, conf);
         for(int i=0;i<17;i++) {
           addDoc(writer);
         }
@@ -571,23 +581,25 @@ public class TestDeletionPolicy extends 
       KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);
 
       Directory dir = new RAMDirectory();
-      IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+      IndexWriterConfig conf = new IndexWriterConfig(
           TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
-          .setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy));
-      LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+          .setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy);
+      LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundFile);
       lmp.setUseCompoundDocStore(useCompoundFile);
+      IndexWriter writer = new IndexWriter(dir, conf);
       writer.close();
       Term searchTerm = new Term("content", "aaa");        
       Query query = new TermQuery(searchTerm);
 
       for(int i=0;i<N+1;i++) {
-        writer = new IndexWriter(dir, new IndexWriterConfig(
+        conf = new IndexWriterConfig(
             TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
-            .setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy));
-        lmp = (LogMergePolicy) writer.getMergePolicy();
+            .setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy);
+        lmp = (LogMergePolicy) conf.getMergePolicy();
         lmp.setUseCompoundFile(useCompoundFile);
         lmp.setUseCompoundDocStore(useCompoundFile);
+        writer = new IndexWriter(dir, conf);
         for(int j=0;j<17;j++) {
           addDoc(writer);
         }
@@ -603,11 +615,12 @@ public class TestDeletionPolicy extends 
         reader.close();
         searcher.close();
       }
-      writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
-          .setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy));
-      lmp = (LogMergePolicy) writer.getMergePolicy();
+      conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+          .setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy);
+      lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundFile);
       lmp.setUseCompoundDocStore(useCompoundFile);
+      writer = new IndexWriter(dir, conf);
       writer.optimize();
       // this is a commit
       writer.close();
@@ -677,26 +690,28 @@ public class TestDeletionPolicy extends 
       KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);
 
       Directory dir = new RAMDirectory();
-      IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+      IndexWriterConfig conf = new IndexWriterConfig(
           TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
           .setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy)
-          .setMaxBufferedDocs(10));
-      LogMergePolicy lmp = (LogMergePolicy) writer.getMergePolicy();
+          .setMaxBufferedDocs(10);
+      LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
       lmp.setUseCompoundFile(useCompoundFile);
       lmp.setUseCompoundDocStore(useCompoundFile);
+      IndexWriter writer = new IndexWriter(dir, conf);
       writer.close();
       Term searchTerm = new Term("content", "aaa");        
       Query query = new TermQuery(searchTerm);
 
       for(int i=0;i<N+1;i++) {
 
-        writer = new IndexWriter(dir, new IndexWriterConfig(
+        conf = new IndexWriterConfig(
             TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
             .setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy)
-            .setMaxBufferedDocs(10));
-        lmp = (LogMergePolicy) writer.getMergePolicy();
+            .setMaxBufferedDocs(10);
+        lmp = (LogMergePolicy) conf.getMergePolicy();
         lmp.setUseCompoundFile(useCompoundFile);
         lmp.setUseCompoundDocStore(useCompoundFile);
+        writer = new IndexWriter(dir, conf);
         for(int j=0;j<17;j++) {
           addDoc(writer);
         }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java?rev=925462&r1=925461&r2=925462&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java Fri Mar 19 22:25:56 2010
@@ -60,9 +60,10 @@ public class TestFieldsReader extends Lu
     fieldInfos = new FieldInfos();
     DocHelper.setupDoc(testDoc);
     fieldInfos.add(testDoc);
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false);
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundDocStore(false);
+    IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT));
+    ((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(false);
+    ((LogMergePolicy) conf.getMergePolicy()).setUseCompoundDocStore(false);
+    IndexWriter writer = new IndexWriter(dir, conf);
     writer.addDocument(testDoc);
     writer.close();
   }
@@ -216,8 +217,9 @@ public class TestFieldsReader extends Lu
     FSDirectory tmpDir = FSDirectory.open(file);
     assertTrue(tmpDir != null);
 
-    IndexWriter writer = new IndexWriter(tmpDir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
-    ((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(false);
+    IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE);
+    ((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(false);
+    IndexWriter writer = new IndexWriter(tmpDir, conf);
     writer.addDocument(testDoc);
     writer.close();
 



Mime
View raw message