You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2011/10/29 21:16:55 UTC

svn commit: r1194980 - in /lucene/dev/branches/lucene2621/lucene/src: java/org/apache/lucene/index/codecs/lucene40/ test-framework/org/apache/lucene/util/ test/org/apache/lucene/index/

Author: mikemccand
Date: Sat Oct 29 19:16:55 2011
New Revision: 1194980

URL: http://svn.apache.org/viewvc?rev=1194980&view=rev
Log:
get TestAddIndexes to compile

Modified:
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40PostingsFormat.java
    lucene/dev/branches/lucene2621/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestCodecs.java

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40PostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40PostingsFormat.java?rev=1194980&r1=1194979&r2=1194980&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40PostingsFormat.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40PostingsFormat.java Sat Oct 29 19:16:55 2011
@@ -34,6 +34,11 @@ import org.apache.lucene.store.Directory
 
 /** Default codec. 
  *  @lucene.experimental */
+
+// nocommit -- this class should be "generic" instance of a
+// wrapper class that just takes the
+// Lucene40PostingsBaseFormat and wraps BlockTree terms dict
+// around it?
 public class Lucene40PostingsFormat extends PostingsFormat {
 
   private final int minBlockSize;

Modified: lucene/dev/branches/lucene2621/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java?rev=1194980&r1=1194979&r2=1194980&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java Sat Oct 29 19:16:55 2011
@@ -385,6 +385,7 @@ public class _TestUtil {
   /** Return a CodecProvider that can read any of the
    *  default codecs and formats, but always writes in the specified
    *  format. */
+  // nocommit rename to .alwaysPostingsFormat?
   public static CodecProvider alwaysFormat(final PostingsFormat format) {
     final Codec codec = new Lucene40Codec() {
       @Override

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java?rev=1194980&r1=1194979&r2=1194980&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java Sat Oct 29 19:16:55 2011
@@ -17,8 +17,8 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
-import java.io.IOException;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -30,8 +30,11 @@ import org.apache.lucene.document.String
 import org.apache.lucene.document.TextField;
 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
 import org.apache.lucene.index.codecs.CodecProvider;
+import org.apache.lucene.index.codecs.PostingsFormat;
+import org.apache.lucene.index.codecs.lucene40.Lucene40PostingsBaseFormat;
 import org.apache.lucene.index.codecs.lucene40.Lucene40PostingsFormat;
 import org.apache.lucene.index.codecs.mocksep.MockSepPostingsFormat;
+import org.apache.lucene.index.codecs.perfield.PerFieldPostingsFormat;
 import org.apache.lucene.index.codecs.pulsing.PulsingPostingsFormat;
 import org.apache.lucene.index.codecs.simpletext.SimpleTextPostingsFormat;
 import org.apache.lucene.search.DocIdSetIterator;
@@ -981,7 +984,7 @@ public class TestAddIndexes extends Luce
     // two auxiliary directories
     Directory aux = newDirectory();
     Directory aux2 = newDirectory();
-    CodecProvider provider = new MockCodecProvider();
+    CodecProvider provider = _TestUtil.alwaysFormat(new CustomPerFieldPostingsFormat());
     IndexWriter writer = null;
 
     writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
@@ -1037,16 +1040,33 @@ public class TestAddIndexes extends Luce
     aux2.close();
   }
 
-  public static class MockCodecProvider extends CodecProvider {
-    public MockCodecProvider() {
-      Lucene40PostingsFormat standardCodec = new Lucene40PostingsFormat();
-      SimpleTextPostingsFormat simpleTextCodec = new SimpleTextPostingsFormat();
-      MockSepPostingsFormat mockSepCodec = new MockSepPostingsFormat();
-      register(standardCodec);
-      register(mockSepCodec);
-      register(simpleTextCodec);
-      setFieldCodec("id", simpleTextCodec.name);
-      setFieldCodec("content", mockSepCodec.name);
+  // nocommit factor to helper class in _TestUtil (this is
+  // copied from TestExternalCodecs)
+  private static class CustomPerFieldPostingsFormat extends PerFieldPostingsFormat {
+    private final PostingsFormat simpleTextFormat = new SimpleTextPostingsFormat();
+    private final PostingsFormat defaultFormat = new Lucene40PostingsFormat();
+    private final PostingsFormat mockSepFormat = new MockSepPostingsFormat();
+
+    @Override
+    public String getPostingsFormatForField(String field) {
+      if (field.equals("id")) {
+        return "simple text";
+      } else if (field.equals("content")) {
+        return "mock sep";
+      } else {
+        return "lucene 40";
+      }
+    }
+
+    @Override
+    public PostingsFormat getPostingsFormat(String formatName) {
+      if (formatName.equals("simple text")) {
+        return simpleTextFormat;
+      } else if (formatName.equals("mock sep")) {
+        return mockSepFormat;
+      } else {
+        return defaultFormat;
+      }
     }
   }
 
@@ -1145,9 +1165,7 @@ public class TestAddIndexes extends Luce
     {
       IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT,
           new MockAnalyzer(random));
-      CodecProvider provider = new CodecProvider();
-      provider.register(new Lucene40PostingsFormat());
-      conf.setCodecProvider(provider);
+      conf.setCodecProvider(_TestUtil.alwaysFormat(new Lucene40PostingsFormat()));
       IndexWriter w = new IndexWriter(toAdd, conf);
       Document doc = new Document();
       FieldType customType = new FieldType();
@@ -1156,13 +1174,12 @@ public class TestAddIndexes extends Luce
       w.addDocument(doc);
       w.close();
     }
+
     {
       Directory dir = newDirectory();
       IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT,
           new MockAnalyzer(random));
-      CodecProvider provider = new CodecProvider();
-      provider.register(new PulsingPostingsFormat(1 + random.nextInt(20)));
-      conf.setCodecProvider(provider);
+      conf.setCodecProvider(_TestUtil.alwaysFormat(new PulsingPostingsFormat(new Lucene40PostingsBaseFormat(), 1 + random.nextInt(20))));
       IndexWriter w = new IndexWriter(dir, conf);
       try {
         w.addIndexes(toAdd);
@@ -1181,9 +1198,7 @@ public class TestAddIndexes extends Luce
       Directory dir = newDirectory();
       IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT,
           new MockAnalyzer(random));
-      CodecProvider provider = new CodecProvider();
-      provider.register(new PulsingPostingsFormat(1 + random.nextInt(20)));
-      conf.setCodecProvider(provider);
+      conf.setCodecProvider(_TestUtil.alwaysFormat(new PulsingPostingsFormat(new Lucene40PostingsBaseFormat(), 1 + random.nextInt(20))));
       IndexWriter w = new IndexWriter(dir, conf);
       IndexReader indexReader = IndexReader.open(toAdd);
       try {

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestCodecs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestCodecs.java?rev=1194980&r1=1194979&r2=1194980&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestCodecs.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestCodecs.java Sat Oct 29 19:16:55 2011
@@ -340,7 +340,7 @@ public class TestCodecs extends LuceneTe
     final Directory dir = newDirectory();
     final IndexWriterConfig config = newIndexWriterConfig(Version.LUCENE_31,
       new MockAnalyzer(random));
-    config.setCodecProvider(new MockSepCodecs());
+    config.setCodecProvider(_TestUtil.alwaysFormat(new MockSepPostingsFormat()));
     final IndexWriter writer = new IndexWriter(dir, config);
 
     try {
@@ -395,15 +395,6 @@ public class TestCodecs extends LuceneTe
     }
   }
 
-  public static class MockSepCodecs extends CodecProvider {
-
-    protected MockSepCodecs() {
-      this.register(new MockSepPostingsFormat());
-      this.setDefaultFieldCodec("MockSep");
-    }
-    
-  }
-
   private class Verify extends Thread {
     final Fields termsDict;
     final FieldData[] fields;