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 2014/11/27 12:34:48 UTC

svn commit: r1642110 [11/12] - in /lucene/dev/branches/lucene6005/lucene: analysis/uima/src/test/org/apache/lucene/analysis/uima/ backward-codecs/src/test/org/apache/lucene/index/ benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/ benchmark/s...

Modified: lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java Thu Nov 27 11:34:43 2014
@@ -37,6 +37,7 @@ import org.apache.lucene.document.Binary
 import org.apache.lucene.document.Document2;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldTypes;
 import org.apache.lucene.document.FloatDocValuesField;
 import org.apache.lucene.document.NumericDocValuesField;
 import org.apache.lucene.document.SortedDocValuesField;
@@ -73,22 +74,30 @@ import static org.apache.lucene.index.So
 public abstract class BaseDocValuesFormatTestCase extends BaseIndexFileFormatTestCase {
 
   @Override
-  protected void addRandomFields(Document doc) {
+  protected void addRandomFields(Document2 doc) {
+    FieldTypes fieldTypes = doc.getFieldTypes();
+    fieldTypes.disableExistsFilters();
+    for(String fieldName : new String[] {"ndv", "bdv", "sdv", "ssdv", "sndv"}) {
+      fieldTypes.setIndexOptions(fieldName, IndexOptions.NONE);
+    }
+    fieldTypes.disableSorting("bdv");
+    fieldTypes.setMultiValued("ssdv");
+    fieldTypes.setMultiValued("sndv");
     if (usually()) {
-      doc.add(new NumericDocValuesField("ndv", random().nextInt(1 << 12)));
-      doc.add(new BinaryDocValuesField("bdv", new BytesRef(TestUtil.randomSimpleString(random()))));
-      doc.add(new SortedDocValuesField("sdv", new BytesRef(TestUtil.randomSimpleString(random(), 2))));
+      doc.addInt("ndv", random().nextInt(1 << 12));
+      doc.addBinary("bdv", new BytesRef(TestUtil.randomSimpleString(random())));
+      doc.addAtom("sdv", new BytesRef(TestUtil.randomSimpleString(random(), 2)));
     }
     if (codecSupportsSortedSet()) {
       final int numValues = random().nextInt(5);
       for (int i = 0; i < numValues; ++i) {
-        doc.add(new SortedSetDocValuesField("ssdv", new BytesRef(TestUtil.randomSimpleString(random(), 2))));
+        doc.addAtom("ssdv", new BytesRef(TestUtil.randomSimpleString(random(), 2)));
       }
     }
     if (codecSupportsSortedNumeric()) {
       final int numValues = random().nextInt(5);
       for (int i = 0; i < numValues; ++i) {
-        doc.add(new SortedNumericDocValuesField("sndv", TestUtil.nextLong(random(), Long.MIN_VALUE, Long.MAX_VALUE)));
+        doc.addLong("sndv", TestUtil.nextLong(random(), Long.MIN_VALUE, Long.MAX_VALUE));
       }
     }
   }
@@ -96,11 +105,11 @@ public abstract class BaseDocValuesForma
   public void testOneNumber() throws IOException {
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
-    Document doc = new Document();
+    Document2 doc = iwriter.newDocument();
     String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
     String text = "This is the text to be indexed. " + longTerm;
-    doc.add(newTextField("fieldname", text, Field.Store.YES));
-    doc.add(new NumericDocValuesField("dv", 5));
+    doc.addLargeText("fieldname", text);
+    doc.addInt("dv", 5);
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -128,11 +137,11 @@ public abstract class BaseDocValuesForma
   public void testOneFloat() throws IOException {
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
-    Document doc = new Document();
+    Document2 doc = iwriter.newDocument();
     String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
     String text = "This is the text to be indexed. " + longTerm;
-    doc.add(newTextField("fieldname", text, Field.Store.YES));
-    doc.add(new FloatDocValuesField("dv", 5.7f));
+    doc.addLargeText("fieldname", text);
+    doc.addFloat("dv", 5.7f);
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -160,12 +169,12 @@ public abstract class BaseDocValuesForma
   public void testTwoNumbers() throws IOException {
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
-    Document doc = new Document();
+    Document2 doc = iwriter.newDocument();
     String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
     String text = "This is the text to be indexed. " + longTerm;
-    doc.add(newTextField("fieldname", text, Field.Store.YES));
-    doc.add(new NumericDocValuesField("dv1", 5));
-    doc.add(new NumericDocValuesField("dv2", 17));
+    doc.addLargeText("fieldname", text);
+    doc.addInt("dv1", 5);
+    doc.addInt("dv2", 17);
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -195,12 +204,15 @@ public abstract class BaseDocValuesForma
   public void testTwoBinaryValues() throws IOException {
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
-    Document doc = new Document();
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("dv1");
+    fieldTypes.disableSorting("dv2");
+    Document2 doc = iwriter.newDocument();
     String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
     String text = "This is the text to be indexed. " + longTerm;
-    doc.add(newTextField("fieldname", text, Field.Store.YES));
-    doc.add(new BinaryDocValuesField("dv1", new BytesRef(longTerm)));
-    doc.add(new BinaryDocValuesField("dv2", new BytesRef(text)));
+    doc.addLargeText("fieldname", text);
+    doc.addBinary("dv1", new BytesRef(longTerm));
+    doc.addBinary("dv2", new BytesRef(text));
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -232,12 +244,14 @@ public abstract class BaseDocValuesForma
   public void testTwoFieldsMixed() throws IOException {
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
-    Document doc = new Document();
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("dv2");
+    Document2 doc = iwriter.newDocument();
     String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
     String text = "This is the text to be indexed. " + longTerm;
-    doc.add(newTextField("fieldname", text, Field.Store.YES));
-    doc.add(new NumericDocValuesField("dv1", 5));
-    doc.add(new BinaryDocValuesField("dv2", new BytesRef("hello world")));
+    doc.addLargeText("fieldname", text);
+    doc.addInt("dv1", 5);
+    doc.addBinary("dv2", new BytesRef("hello world"));
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -268,13 +282,15 @@ public abstract class BaseDocValuesForma
   public void testThreeFieldsMixed() throws IOException {
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
-    Document doc = new Document();
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("dv3");
+    Document2 doc = iwriter.newDocument();
     String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
     String text = "This is the text to be indexed. " + longTerm;
-    doc.add(newTextField("fieldname", text, Field.Store.YES));
-    doc.add(new SortedDocValuesField("dv1", new BytesRef("hello hello")));
-    doc.add(new NumericDocValuesField("dv2", 5));
-    doc.add(new BinaryDocValuesField("dv3", new BytesRef("hello world")));
+    doc.addLargeText("fieldname", text);
+    doc.addBinary("dv1", new BytesRef("hello hello"));
+    doc.addInt("dv2", 5);
+    doc.addBinary("dv3", new BytesRef("hello world"));
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -309,13 +325,16 @@ public abstract class BaseDocValuesForma
   public void testThreeFieldsMixed2() throws IOException {
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
-    Document doc = new Document();
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("dv1");
+
+    Document2 doc = iwriter.newDocument();
     String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
     String text = "This is the text to be indexed. " + longTerm;
-    doc.add(newTextField("fieldname", text, Field.Store.YES));
-    doc.add(new BinaryDocValuesField("dv1", new BytesRef("hello world")));
-    doc.add(new SortedDocValuesField("dv2", new BytesRef("hello hello")));
-    doc.add(new NumericDocValuesField("dv3", 5));
+    doc.addLargeText("fieldname", text);
+    doc.addBinary("dv1", new BytesRef("hello world"));
+    doc.addBinary("dv2", new BytesRef("hello hello"));
+    doc.addInt("dv3", 5);
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -355,11 +374,11 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new NumericDocValuesField("dv", 1));
+    Document2 doc = iwriter.newDocument();
+    doc.addInt("dv", 1);
     iwriter.addDocument(doc);
-    doc = new Document();
-    doc.add(new NumericDocValuesField("dv", 2));
+    doc = iwriter.newDocument();
+    doc.addInt("dv", 2);
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     iwriter.close();
@@ -382,14 +401,14 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(newField("id", "0", StringField.TYPE_STORED));
-    doc.add(new NumericDocValuesField("dv", -10));
+    Document2 doc = iwriter.newDocument();
+    doc.addAtom("id", "0");
+    doc.addInt("dv", -10);
     iwriter.addDocument(doc);
     iwriter.commit();
-    doc = new Document();
-    doc.add(newField("id", "1", StringField.TYPE_STORED));
-    doc.add(new NumericDocValuesField("dv", 99));
+    doc = iwriter.newDocument();
+    doc.addAtom("id", "1");
+    doc.addInt("dv", 99);
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     iwriter.close();
@@ -420,11 +439,11 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new NumericDocValuesField("dv", Long.MIN_VALUE));
+    Document2 doc = iwriter.newDocument();
+    doc.addLong("dv", Long.MIN_VALUE);
     iwriter.addDocument(doc);
-    doc = new Document();
-    doc.add(new NumericDocValuesField("dv", Long.MAX_VALUE));
+    doc = iwriter.newDocument();
+    doc.addLong("dv", Long.MAX_VALUE);
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     iwriter.close();
@@ -447,11 +466,11 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new NumericDocValuesField("dv", -8841491950446638677L));
+    Document2 doc = iwriter.newDocument();
+    doc.addLong("dv", -8841491950446638677L);
     iwriter.addDocument(doc);
-    doc = new Document();
-    doc.add(new NumericDocValuesField("dv", 9062230939892376225L));
+    doc = iwriter.newDocument();
+    doc.addLong("dv", 9062230939892376225L);
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     iwriter.close();
@@ -473,11 +492,13 @@ public abstract class BaseDocValuesForma
     Directory directory = newDirectory();
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("dv");
+    Document2 doc = iwriter.newDocument();
     String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
     String text = "This is the text to be indexed. " + longTerm;
-    doc.add(newTextField("fieldname", text, Field.Store.YES));
-    doc.add(new BinaryDocValuesField("dv", new BytesRef("hello world")));
+    doc.addLargeText("fieldname", text);
+    doc.addBinary("dv", new BytesRef("hello world"));
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -510,14 +531,17 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(newField("id", "0", StringField.TYPE_STORED));
-    doc.add(new BinaryDocValuesField("dv", new BytesRef("hello world 1")));
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("dv");
+
+    Document2 doc = iwriter.newDocument();
+    doc.addAtom("id", "0");
+    doc.addBinary("dv", new BytesRef("hello world 1"));
     iwriter.addDocument(doc);
     iwriter.commit();
-    doc = new Document();
-    doc.add(newField("id", "1", StringField.TYPE_STORED));
-    doc.add(new BinaryDocValuesField("dv", new BytesRef("hello 2")));
+    doc = iwriter.newDocument();
+    doc.addAtom("id", "1");
+    doc.addBinary("dv", new BytesRef("hello 2"));
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     iwriter.close();
@@ -549,13 +573,15 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("field");
     
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.NO));
+    Document2 doc = iwriter.newDocument();
+    doc.addAtom("id", "0");
     iwriter.addDocument(doc);    
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.NO));
-    doc.add(new BinaryDocValuesField("field", new BytesRef("hi")));
+    doc = iwriter.newDocument();
+    doc.addAtom("id", "1");
+    doc.addBinary("field", new BytesRef("hi"));
     iwriter.addDocument(doc);
     iwriter.commit();
     iwriter.deleteDocuments(new Term("id", "1"));
@@ -577,11 +603,11 @@ public abstract class BaseDocValuesForma
     Directory directory = newDirectory();
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
+    Document2 doc = iwriter.newDocument();
     String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
     String text = "This is the text to be indexed. " + longTerm;
-    doc.add(newTextField("fieldname", text, Field.Store.YES));
-    doc.add(new SortedDocValuesField("dv", new BytesRef("hello world")));
+    doc.addLargeText("fieldname", text);
+    doc.addBinary("dv", new BytesRef("hello world"));
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -615,11 +641,11 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 1")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef("hello world 1"));
     iwriter.addDocument(doc);
-    doc = new Document();
-    doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 2")));
+    doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef("hello world 2"));
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     iwriter.close();
@@ -645,14 +671,14 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 1")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef("hello world 1"));
     iwriter.addDocument(doc);
-    doc = new Document();
-    doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 2")));
+    doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef("hello world 2"));
     iwriter.addDocument(doc);
-    doc = new Document();
-    doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 1")));
+    doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef("hello world 1"));
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     iwriter.close();
@@ -681,14 +707,14 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(newField("id", "0", StringField.TYPE_STORED));
-    doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 1")));
+    Document2 doc = iwriter.newDocument();
+    doc.addAtom("id", "0");
+    doc.addBinary("dv", new BytesRef("hello world 1"));
     iwriter.addDocument(doc);
     iwriter.commit();
-    doc = new Document();
-    doc.add(newField("id", "1", StringField.TYPE_STORED));
-    doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 2")));
+    doc = iwriter.newDocument();
+    doc.addAtom("id", "1");
+    doc.addBinary("dv", new BytesRef("hello world 2"));
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     iwriter.close();
@@ -725,12 +751,12 @@ public abstract class BaseDocValuesForma
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
     
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.NO));
+    Document2 doc = iwriter.newDocument();
+    doc.addAtom("id", "0");
     iwriter.addDocument(doc);    
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.NO));
-    doc.add(new SortedDocValuesField("field", new BytesRef("hello")));
+    doc = iwriter.newDocument();
+    doc.addAtom("id", "1");
+    doc.addBinary("field", new BytesRef("hello"));
     iwriter.addDocument(doc);
     iwriter.commit();
     iwriter.deleteDocuments(new Term("id", "1"));
@@ -761,8 +787,11 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new BinaryDocValuesField("dv", new BytesRef("hello\nworld\r1")));
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("dv");
+
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef("hello\nworld\r1"));
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -784,11 +813,11 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 2")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef("hello world 2"));
     iwriter.addDocument(doc);
     // 2nd doc missing the DV field
-    iwriter.addDocument(new Document());
+    iwriter.addDocument(iwriter.newDocument());
     iwriter.close();
     
     // Now search the index:
@@ -813,16 +842,16 @@ public abstract class BaseDocValuesForma
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
     
-    Document doc = new Document();
-    doc.add(new SortedDocValuesField("field", new BytesRef("hello")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
     iwriter.addDocument(doc);
     
-    doc = new Document();
-    doc.add(new SortedDocValuesField("field", new BytesRef("world")));
+    doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("world"));
     iwriter.addDocument(doc);
 
-    doc = new Document();
-    doc.add(new SortedDocValuesField("field", new BytesRef("beer")));
+    doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("beer"));
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     
@@ -886,11 +915,11 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new SortedDocValuesField("dv", new BytesRef("")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef(""));
     iwriter.addDocument(doc);
-    doc = new Document();
-    doc.add(new SortedDocValuesField("dv", new BytesRef("")));
+    doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef(""));
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     iwriter.close();
@@ -915,11 +944,14 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new BinaryDocValuesField("dv", new BytesRef("")));
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("dv");
+
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef(""));
     iwriter.addDocument(doc);
-    doc = new Document();
-    doc.add(new BinaryDocValuesField("dv", new BytesRef("")));
+    doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef(""));
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     iwriter.close();
@@ -944,11 +976,13 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("dv");
+    Document2 doc = iwriter.newDocument();
     byte bytes[] = new byte[32766];
     BytesRef b = new BytesRef(bytes);
     random().nextBytes(bytes);
-    doc.add(new BinaryDocValuesField("dv", b));
+    doc.addBinary("dv", b);
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -970,11 +1004,11 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
+    Document2 doc = iwriter.newDocument();
     byte bytes[] = new byte[32766];
     BytesRef b = new BytesRef(bytes);
     random().nextBytes(bytes);
-    doc.add(new SortedDocValuesField("dv", b));
+    doc.addBinary("dv", b);
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -995,8 +1029,10 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new BinaryDocValuesField("dv", new BytesRef("boo!")));
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.disableSorting("dv");
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef("boo!"));
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -1020,8 +1056,8 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new SortedDocValuesField("dv", new BytesRef("boo!")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("dv", new BytesRef("boo!"));
     iwriter.addDocument(doc);
     iwriter.close();
     
@@ -1048,9 +1084,9 @@ public abstract class BaseDocValuesForma
     conf.setMergePolicy(newLogMergePolicy());
     IndexWriter writer = new IndexWriter(dir, conf);
     for (int i = 0; i < 5; i++) {
-      Document doc = new Document();
-      doc.add(new NumericDocValuesField("docId", i));
-      doc.add(new TextField("docId", "" + i, Field.Store.NO));
+      Document2 doc = writer.newDocument();
+      doc.addInt("docId", i);
+      doc.addLargeText("text", "" + i);
       writer.addDocument(doc);
     }
     writer.commit();
@@ -1064,11 +1100,11 @@ public abstract class BaseDocValuesForma
     IndexSearcher searcher = new IndexSearcher(reader);
 
     BooleanQuery query = new BooleanQuery();
-    query.add(new TermQuery(new Term("docId", "0")), BooleanClause.Occur.SHOULD);
-    query.add(new TermQuery(new Term("docId", "1")), BooleanClause.Occur.SHOULD);
-    query.add(new TermQuery(new Term("docId", "2")), BooleanClause.Occur.SHOULD);
-    query.add(new TermQuery(new Term("docId", "3")), BooleanClause.Occur.SHOULD);
-    query.add(new TermQuery(new Term("docId", "4")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term("text", "0")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term("text", "1")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term("text", "2")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term("text", "3")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term("text", "4")), BooleanClause.Occur.SHOULD);
 
     TopDocs search = searcher.search(query, 10);
     assertEquals(5, search.totalHits);
@@ -1096,11 +1132,11 @@ public abstract class BaseDocValuesForma
     Map<String, String> docToString = new HashMap<>();
     int maxLength = TestUtil.nextInt(random(), 1, 50);
     for (int i = 0; i < numDocs; i++) {
-      Document doc = new Document();
-      doc.add(newTextField("id", "" + i, Field.Store.YES));
+      Document2 doc = w.newDocument();
+      doc.addLargeText("id", "" + i);
       String string = TestUtil.randomRealisticUnicodeString(random(), 1, maxLength);
       BytesRef br = new BytesRef(string);
-      doc.add(new SortedDocValuesField("field", br));
+      doc.addBinary("field", br);
       hash.add(br);
       docToString.put("" + i, string);
       w.addDocument(doc);
@@ -1110,8 +1146,8 @@ public abstract class BaseDocValuesForma
     }
     int numDocsNoValue = atLeast(10);
     for (int i = 0; i < numDocsNoValue; i++) {
-      Document doc = new Document();
-      doc.add(newTextField("id", "noValue", Field.Store.YES));
+      Document2 doc = w.newDocument();
+      doc.addLargeText("id", "noValue");
       w.addDocument(doc);
     }
     if (!codecSupportsDocsWithField()) {
@@ -1127,14 +1163,14 @@ public abstract class BaseDocValuesForma
       w.forceMerge(1);
     }
     for (int i = 0; i < numDocs; i++) {
-      Document doc = new Document();
+      Document2 doc = w.newDocument();
       String id = "" + i + numDocs;
-      doc.add(newTextField("id", id, Field.Store.YES));
+      doc.addLargeText("id", id);
       String string = TestUtil.randomRealisticUnicodeString(random(), 1, maxLength);
       BytesRef br = new BytesRef(string);
       hash.add(br);
       docToString.put(id, string);
-      doc.add(new SortedDocValuesField("field", br));
+      doc.addBinary("field", br);
       w.addDocument(doc);
     }
     w.commit();
@@ -1184,13 +1220,6 @@ public abstract class BaseDocValuesForma
     Directory dir = newDirectory();
     IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);
-    Document doc = new Document();
-    Field idField = new StringField("id", "", Field.Store.NO);
-    Field storedField = newStringField("stored", "", Field.Store.YES);
-    Field dvField = new NumericDocValuesField("dv", 0);
-    doc.add(idField);
-    doc.add(storedField);
-    doc.add(dvField);
     
     // index some docs
     int numDocs = atLeast(300);
@@ -1198,10 +1227,11 @@ public abstract class BaseDocValuesForma
     // for numbers of values <= 256, all storage layouts are tested
     assert numDocs > 256;
     for (int i = 0; i < numDocs; i++) {
-      idField.setStringValue(Integer.toString(i));
+      Document2 doc = writer.newDocument();
+      doc.addAtom("id", Integer.toString(i));
       long value = longs.next();
-      storedField.setStringValue(Long.toString(value));
-      dvField.setLongValue(value);
+      doc.addAtom("stored", Long.toString(value));
+      doc.addLong("dv", value);
       writer.addDocument(doc);
       if (random().nextInt(31) == 0) {
         writer.commit();
@@ -1239,6 +1269,9 @@ public abstract class BaseDocValuesForma
     Directory dir = newDirectory();
     IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.setMultiValued("stored");
+    fieldTypes.setMultiValued("dv");
     
     // index some docs
     int numDocs = atLeast(300);
@@ -1246,19 +1279,19 @@ public abstract class BaseDocValuesForma
     // for numbers of values <= 256, all storage layouts are tested
     assert numDocs > 256;
     for (int i = 0; i < numDocs; i++) {
-      Document doc = new Document();
-      doc.add(new StringField("id", Integer.toString(i), Field.Store.NO));
+      Document2 doc = writer.newDocument();
+      doc.addAtom("id", Integer.toString(i));
       
       int valueCount = (int) counts.next();
       long valueArray[] = new long[valueCount];
       for (int j = 0; j < valueCount; j++) {
         long value = values.next();
         valueArray[j] = value;
-        doc.add(new SortedNumericDocValuesField("dv", value));
+        doc.addLong("dv", value);
       }
       Arrays.sort(valueArray);
       for (int j = 0; j < valueCount; j++) {
-        doc.add(new StoredField("stored", Long.toString(valueArray[j])));
+        doc.addStored("stored", Long.toString(valueArray[j]));
       }
       writer.addDocument(doc);
       if (random().nextInt(31) == 0) {
@@ -1337,18 +1370,14 @@ public abstract class BaseDocValuesForma
     Directory dir = newDirectory();
     IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);
-    Document doc = new Document();
-    Field idField = new StringField("id", "", Field.Store.NO);
-    Field storedField = new StoredField("stored", new byte[0]);
-    Field dvField = new BinaryDocValuesField("dv", new BytesRef());
-    doc.add(idField);
-    doc.add(storedField);
-    doc.add(dvField);
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.disableSorting("dv");
     
     // index some docs
     int numDocs = atLeast(300);
     for (int i = 0; i < numDocs; i++) {
-      idField.setStringValue(Integer.toString(i));
+      Document2 doc = writer.newDocument();
+      doc.addAtom("id", Integer.toString(i));
       final int length;
       if (minLength == maxLength) {
         length = minLength; // fixed length
@@ -1357,8 +1386,8 @@ public abstract class BaseDocValuesForma
       }
       byte buffer[] = new byte[length];
       random().nextBytes(buffer);
-      storedField.setBytesValue(buffer);
-      dvField.setBytesValue(buffer);
+      doc.addStored("stored", buffer);
+      doc.addBinary("dv", buffer);
       writer.addDocument(doc);
       if (random().nextInt(31) == 0) {
         writer.commit();
@@ -1421,17 +1450,11 @@ public abstract class BaseDocValuesForma
     Directory dir = newFSDirectory(createTempDir("dvduel"));
     IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);
-    Document doc = new Document();
-    Field idField = new StringField("id", "", Field.Store.NO);
-    Field storedField = new StoredField("stored", new byte[0]);
-    Field dvField = new SortedDocValuesField("dv", new BytesRef());
-    doc.add(idField);
-    doc.add(storedField);
-    doc.add(dvField);
-    
+
     // index some docs
     for (int i = 0; i < numDocs; i++) {
-      idField.setStringValue(Integer.toString(i));
+      Document2 doc = writer.newDocument();
+      doc.addAtom("id", Integer.toString(i));
       final int length;
       if (minLength == maxLength) {
         length = minLength; // fixed length
@@ -1440,8 +1463,8 @@ public abstract class BaseDocValuesForma
       }
       byte buffer[] = new byte[length];
       random().nextBytes(buffer);
-      storedField.setBytesValue(buffer);
-      dvField.setBytesValue(buffer);
+      doc.addStored("stored", buffer);
+      doc.addBinary("dv", buffer);
       writer.addDocument(doc);
       if (random().nextInt(31) == 0) {
         writer.commit();
@@ -1504,9 +1527,11 @@ public abstract class BaseDocValuesForma
     assumeTrue("Codec does not support SORTED_SET", codecSupportsSortedSet());
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
-    
-    Document doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
+
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
     iwriter.addDocument(doc);
     
     DirectoryReader ireader = iwriter.getReader();
@@ -1529,10 +1554,13 @@ public abstract class BaseDocValuesForma
     assumeTrue("Codec does not support SORTED_SET", codecSupportsSortedSet());
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
-    
-    Document doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
-    doc.add(new SortedSetDocValuesField("field2", new BytesRef("world")));
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
+    fieldTypes.setMultiValued("field2");
+    
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
+    doc.addBinary("field2", new BytesRef("world"));
     iwriter.addDocument(doc);
     
     DirectoryReader ireader = iwriter.getReader();
@@ -1567,14 +1595,16 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
   
-    Document doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
     iwriter.addDocument(doc);
     iwriter.commit();
     
-    doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("world")));
+    doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("world"));
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     
@@ -1607,9 +1637,12 @@ public abstract class BaseDocValuesForma
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
     
-    Document doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("world")));
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
+
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
+    doc.addBinary("field", new BytesRef("world"));
     iwriter.addDocument(doc);
     
     DirectoryReader ireader = iwriter.getReader();
@@ -1636,10 +1669,12 @@ public abstract class BaseDocValuesForma
     assumeTrue("Codec does not support SORTED_SET", codecSupportsSortedSet());
     Directory directory = newDirectory();
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
     
-    Document doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("world")));
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("world"));
+    doc.addBinary("field", new BytesRef("hello"));
     iwriter.addDocument(doc);
     
     DirectoryReader ireader = iwriter.getReader();
@@ -1669,16 +1704,18 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
     
-    Document doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("world")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
+    doc.addBinary("field", new BytesRef("world"));
     iwriter.addDocument(doc);
     iwriter.commit();
     
-    doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("beer")));
+    doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
+    doc.addBinary("field", new BytesRef("beer"));
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     
@@ -1718,12 +1755,14 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
     
-    Document doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
     iwriter.addDocument(doc);
     
-    doc = new Document();
+    doc = iwriter.newDocument();
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     DirectoryReader ireader = iwriter.getReader();
@@ -1750,13 +1789,15 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
     
-    Document doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
     iwriter.addDocument(doc);
     iwriter.commit();
     
-    doc = new Document();
+    doc = iwriter.newDocument();
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
    
@@ -1784,12 +1825,14 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
     
-    Document doc = new Document();
+    Document2 doc = iwriter.newDocument();
     iwriter.addDocument(doc);
     
-    doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
+    doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
     iwriter.addDocument(doc);
     
     iwriter.forceMerge(1);
@@ -1817,13 +1860,15 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
     
-    Document doc = new Document();
+    Document2 doc = iwriter.newDocument();
     iwriter.addDocument(doc);
     iwriter.commit();
     
-    doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
+    doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
     iwriter.addDocument(doc);
     iwriter.forceMerge(1);
     
@@ -1851,13 +1896,15 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
     
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.NO));
+    Document2 doc = iwriter.newDocument();
+    doc.addAtom("id", "0");
     iwriter.addDocument(doc);    
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.NO));
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
+    doc = iwriter.newDocument();
+    doc.addAtom("id", "1");
+    doc.addBinary("field", new BytesRef("hello"));
     iwriter.addDocument(doc);
     iwriter.commit();
     iwriter.deleteDocuments(new Term("id", "1"));
@@ -1880,11 +1927,13 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
     
-    Document doc = new Document();
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("world")));
-    doc.add(new SortedSetDocValuesField("field", new BytesRef("beer")));
+    Document2 doc = iwriter.newDocument();
+    doc.addBinary("field", new BytesRef("hello"));
+    doc.addBinary("field", new BytesRef("world"));
+    doc.addBinary("field", new BytesRef("beer"));
     iwriter.addDocument(doc);
     
     DirectoryReader ireader = iwriter.getReader();
@@ -1942,12 +1991,14 @@ public abstract class BaseDocValuesForma
     Directory dir = newFSDirectory(createTempDir("dvduel"));
     IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);
-    
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.setMultiValued("stored");
+    fieldTypes.setMultiValued("dv");
+
     // index some docs
     for (int i = 0; i < numDocs; i++) {
-      Document doc = new Document();
-      Field idField = new StringField("id", Integer.toString(i), Field.Store.NO);
-      doc.add(idField);
+      Document2 doc = writer.newDocument();
+      doc.addAtom("id", Integer.toString(i));
       final int length;
       if (minLength == maxLength) {
         length = minLength; // fixed length
@@ -1963,14 +2014,14 @@ public abstract class BaseDocValuesForma
       
       // add ordered to the stored field
       for (String v : values) {
-        doc.add(new StoredField("stored", v));
+        doc.addStored("stored", v);
       }
 
       // add in any order to the dv field
       ArrayList<String> unordered = new ArrayList<>(values);
       Collections.shuffle(unordered, random());
       for (String v : unordered) {
-        doc.add(new SortedSetDocValuesField("dv", new BytesRef(v)));
+        doc.addBinary("dv", new BytesRef(v));
       }
 
       writer.addDocument(doc);
@@ -2171,12 +2222,12 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(null);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iw = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.YES));
-    doc.add(new NumericDocValuesField("dv1", 0));
+    Document2 doc = iw.newDocument();
+    doc.addAtom("id", "0");
+    doc.addLong("dv1", 0);
     iw.addDocument(doc);
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.YES));
+    doc = iw.newDocument();
+    doc.addAtom("id", "1");
     iw.addDocument(doc);
     iw.forceMerge(1);
     iw.close();
@@ -2200,13 +2251,13 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(null);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iw = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.YES));
-    doc.add(new NumericDocValuesField("dv1", 0));
+    Document2 doc = iw.newDocument();
+    doc.addAtom("id", "0");
+    doc.addLong("dv1", 0);
     iw.addDocument(doc);
     iw.commit();
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.YES));
+    doc = iw.newDocument();
+    doc.addAtom("id", "1");
     iw.addDocument(doc);
     iw.forceMerge(1);
     iw.close();
@@ -2230,17 +2281,17 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(null);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iw = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.YES));
-    doc.add(new NumericDocValuesField("dv1", 0));
+    Document2 doc = iw.newDocument();
+    doc.addAtom("id", "0");
+    doc.addLong("dv1", 0);
     iw.addDocument(doc);
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.YES));
+    doc = iw.newDocument();
+    doc.addAtom("id", "1");
     iw.addDocument(doc);
     iw.commit();
-    doc = new Document();
-    doc.add(new StringField("id", "2", Field.Store.YES));
-    doc.add(new NumericDocValuesField("dv1", 5));
+    doc = iw.newDocument();
+    doc.addAtom("id", "2");
+    doc.addLong("dv1", 5);
     iw.addDocument(doc);
     iw.forceMerge(1);
     iw.close();
@@ -2266,12 +2317,14 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(null);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iw = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.YES));
-    doc.add(new BinaryDocValuesField("dv1", new BytesRef()));
+    FieldTypes fieldTypes = iw.getFieldTypes();
+    fieldTypes.disableSorting("dv1");
+    Document2 doc = iw.newDocument();
+    doc.addAtom("id", "0");
+    doc.addBinary("dv1", new BytesRef());
     iw.addDocument(doc);
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.YES));
+    doc = iw.newDocument();
+    doc.addAtom("id", "1");
     iw.addDocument(doc);
     iw.forceMerge(1);
     iw.close();
@@ -2297,13 +2350,15 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(null);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iw = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.YES));
-    doc.add(new BinaryDocValuesField("dv1", new BytesRef()));
+    FieldTypes fieldTypes = iw.getFieldTypes();
+    fieldTypes.disableSorting("dv1");
+    Document2 doc = iw.newDocument();
+    doc.addAtom("id", "0");
+    doc.addBinary("dv1", new BytesRef());
     iw.addDocument(doc);
     iw.commit();
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.YES));
+    doc = iw.newDocument();
+    doc.addAtom("id", "1");
     iw.addDocument(doc);
     iw.forceMerge(1);
     iw.close();
@@ -2329,17 +2384,19 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig conf = newIndexWriterConfig(null);
     conf.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iw = new RandomIndexWriter(random(), directory, conf);
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.YES));
-    doc.add(new BinaryDocValuesField("dv1", new BytesRef()));
+    FieldTypes fieldTypes = iw.getFieldTypes();
+    fieldTypes.disableSorting("dv1");
+    Document2 doc = iw.newDocument();
+    doc.addAtom("id", "0");
+    doc.addBinary("dv1", new BytesRef());
     iw.addDocument(doc);
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.YES));
+    doc = iw.newDocument();
+    doc.addAtom("id", "1");
     iw.addDocument(doc);
     iw.commit();
-    doc = new Document();
-    doc.add(new StringField("id", "2", Field.Store.YES));
-    doc.add(new BinaryDocValuesField("dv1", new BytesRef("boo")));
+    doc = iw.newDocument();
+    doc.addAtom("id", "2");
+    doc.addBinary("dv1", new BytesRef("boo"));
     iw.addDocument(doc);
     iw.forceMerge(1);
     iw.close();
@@ -2367,33 +2424,23 @@ public abstract class BaseDocValuesForma
     Directory dir = newDirectory();
     IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);
-    Document doc = new Document();
-    Field idField = new StringField("id", "", Field.Store.NO);
-    Field storedBinField = new StoredField("storedBin", new byte[0]);
-    Field dvBinField = new BinaryDocValuesField("dvBin", new BytesRef());
-    Field dvSortedField = new SortedDocValuesField("dvSorted", new BytesRef());
-    Field storedNumericField = new StoredField("storedNum", "");
-    Field dvNumericField = new NumericDocValuesField("dvNum", 0);
-    doc.add(idField);
-    doc.add(storedBinField);
-    doc.add(dvBinField);
-    doc.add(dvSortedField);
-    doc.add(storedNumericField);
-    doc.add(dvNumericField);
-    
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.disableSorting("dvBin");
+
     // index some docs
     int numDocs = atLeast(300);
     for (int i = 0; i < numDocs; i++) {
-      idField.setStringValue(Integer.toString(i));
+      Document2 doc = writer.newDocument();
+      doc.addAtom("id",Integer.toString(i));
       int length = TestUtil.nextInt(random(), 0, 8);
       byte buffer[] = new byte[length];
       random().nextBytes(buffer);
-      storedBinField.setBytesValue(buffer);
-      dvBinField.setBytesValue(buffer);
-      dvSortedField.setBytesValue(buffer);
+      doc.addStored("storedBin", buffer);
+      doc.addBinary("dvBin", buffer);
+      doc.addBinary("dvSorted", buffer);
       long numericValue = random().nextLong();
-      storedNumericField.setStringValue(Long.toString(numericValue));
-      dvNumericField.setLongValue(numericValue);
+      doc.addStored("storedNum", Long.toString(numericValue));
+      doc.addLong("dvNum", numericValue);
       writer.addDocument(doc);
       if (random().nextInt(31) == 0) {
         writer.commit();
@@ -2459,36 +2506,30 @@ public abstract class BaseDocValuesForma
     Directory dir = newDirectory();
     IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);
-    Field idField = new StringField("id", "", Field.Store.NO);
-    Field storedBinField = new StoredField("storedBin", new byte[0]);
-    Field dvBinField = new BinaryDocValuesField("dvBin", new BytesRef());
-    Field dvSortedField = new SortedDocValuesField("dvSorted", new BytesRef());
-    Field storedNumericField = new StoredField("storedNum", "");
-    Field dvNumericField = new NumericDocValuesField("dvNum", 0);
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.disableSorting("dvBin");
+    fieldTypes.setMultiValued("dvSortedSet");
+    fieldTypes.setMultiValued("storedSortedSet");
+    fieldTypes.setMultiValued("dvSortedNumeric");
+    fieldTypes.setMultiValued("storedSortedNumeric");
     
     // index some docs
     int numDocs = TestUtil.nextInt(random(), 1025, 2047);
     for (int i = 0; i < numDocs; i++) {
-      idField.setStringValue(Integer.toString(i));
+      Document2 doc = writer.newDocument();
+      doc.addAtom("id", Integer.toString(i));
       int length = TestUtil.nextInt(random(), 0, 8);
       byte buffer[] = new byte[length];
       random().nextBytes(buffer);
-      storedBinField.setBytesValue(buffer);
-      dvBinField.setBytesValue(buffer);
-      dvSortedField.setBytesValue(buffer);
-      long numericValue = random().nextLong();
-      storedNumericField.setStringValue(Long.toString(numericValue));
-      dvNumericField.setLongValue(numericValue);
-      Document doc = new Document();
-      doc.add(idField);
       if (random().nextInt(4) > 0) {
-        doc.add(storedBinField);
-        doc.add(dvBinField);
-        doc.add(dvSortedField);
+        doc.addStored("storedBin", buffer);
+        doc.addBinary("dvBin", buffer);
+        doc.addBinary("dvSorted", buffer);
       }
+      long numericValue = random().nextLong();
       if (random().nextInt(4) > 0) {
-        doc.add(storedNumericField);
-        doc.add(dvNumericField);
+        doc.addStored("storedNum", Long.toString(numericValue));
+        doc.addLong("dvNum", numericValue);
       }
       int numSortedSetFields = random().nextInt(3);
       Set<String> values = new TreeSet<>();
@@ -2496,8 +2537,8 @@ public abstract class BaseDocValuesForma
         values.add(TestUtil.randomSimpleString(random()));
       }
       for (String v : values) {
-        doc.add(new SortedSetDocValuesField("dvSortedSet", new BytesRef(v)));
-        doc.add(new StoredField("storedSortedSet", v));
+        doc.addBinary("dvSortedSet", new BytesRef(v));
+        doc.addStored("storedSortedSet", v);
       }
       int numSortedNumericFields = random().nextInt(3);
       Set<Long> numValues = new TreeSet<>();
@@ -2505,8 +2546,8 @@ public abstract class BaseDocValuesForma
         numValues.add(TestUtil.nextLong(random(), Long.MIN_VALUE, Long.MAX_VALUE));
       }
       for (Long l : numValues) {
-        doc.add(new SortedNumericDocValuesField("dvSortedNumeric", l));
-        doc.add(new StoredField("storedSortedNumeric", Long.toString(l)));
+        doc.addLong("dvSortedNumeric", l);
+        doc.addStored("storedSortedNumeric", Long.toString(l));
       }
       writer.addDocument(doc);
       if (random().nextInt(31) == 0) {
@@ -2631,27 +2672,38 @@ public abstract class BaseDocValuesForma
     Directory dir = newFSDirectory(createTempDir());
     IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);
+    FieldTypes fieldTypes = writer.getFieldTypes();
     
     int numSortedSets = random().nextInt(21);
     int numBinaries = random().nextInt(21);
     int numSortedNums = random().nextInt(21);
+
+    for (int j = 0; j < numSortedSets; j++) {
+      fieldTypes.setMultiValued("ss" + j);
+    }
+    for (int j = 0; j < numBinaries; j++) {
+      fieldTypes.disableSorting("b" + j);
+    }
+    for (int j = 0; j < numSortedNums; j++) {
+      fieldTypes.setMultiValued("sn" + j);
+    }
     
     int numDocs = TestUtil.nextInt(random(), 2025, 2047);
     for (int i = 0; i < numDocs; i++) {
-      Document doc = new Document();
+      Document2 doc = writer.newDocument();
       
       for (int j = 0; j < numSortedSets; j++) {
-        doc.add(new SortedSetDocValuesField("ss" + j, new BytesRef(TestUtil.randomSimpleString(random()))));
-        doc.add(new SortedSetDocValuesField("ss" + j, new BytesRef(TestUtil.randomSimpleString(random()))));
+        doc.addBinary("ss" + j, new BytesRef(TestUtil.randomSimpleString(random())));
+        doc.addBinary("ss" + j, new BytesRef(TestUtil.randomSimpleString(random())));
       }
       
       for (int j = 0; j < numBinaries; j++) {
-        doc.add(new BinaryDocValuesField("b" + j, new BytesRef(TestUtil.randomSimpleString(random()))));
+        doc.addBinary("b" + j, new BytesRef(TestUtil.randomSimpleString(random())));
       }
       
       for (int j = 0; j < numSortedNums; j++) {
-        doc.add(new SortedNumericDocValuesField("sn" + j, TestUtil.nextLong(random(), Long.MIN_VALUE, Long.MAX_VALUE)));
-        doc.add(new SortedNumericDocValuesField("sn" + j, TestUtil.nextLong(random(), Long.MIN_VALUE, Long.MAX_VALUE)));
+        doc.addLong("sn" + j, TestUtil.nextLong(random(), Long.MIN_VALUE, Long.MAX_VALUE));
+        doc.addLong("sn" + j, TestUtil.nextLong(random(), Long.MIN_VALUE, Long.MAX_VALUE));
       }
       writer.addDocument(doc);
     }
@@ -2702,17 +2754,20 @@ public abstract class BaseDocValuesForma
       }
       Directory dir = newDirectory();
       RandomIndexWriter w = new RandomIndexWriter(random(), dir);
+      FieldTypes fieldTypes = w.getFieldTypes();
+      fieldTypes.disableSorting("field");
+
       BytesRef bytes = new BytesRef();
       bytes.bytes = new byte[1<<i];
       bytes.length = 1<<i;
       for(int j=0;j<4;j++) {
-        Document doc = new Document();
-        doc.add(new BinaryDocValuesField("field", bytes));
+        Document2 doc = w.newDocument();
+        doc.addBinary("field", bytes);
         w.addDocument(doc);
       }
-      Document doc = new Document();
-      doc.add(new StoredField("id", "5"));
-      doc.add(new BinaryDocValuesField("field", new BytesRef()));
+      Document2 doc = w.newDocument();
+      doc.addStored("id", "5");
+      doc.addBinary("field", new BytesRef());
       w.addDocument(doc);
       IndexReader r = w.getReader();
       w.close();
@@ -2732,8 +2787,10 @@ public abstract class BaseDocValuesForma
     assumeTrue("Codec does not support SORTED_NUMERIC", codecSupportsSortedNumeric());
     Directory directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random(), directory);
-    Document doc = new Document();
-    doc.add(new SortedNumericDocValuesField("dv", 5));
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.setMultiValued("dv");
+    Document2 doc = writer.newDocument();
+    doc.addLong("dv", 5);
     writer.addDocument(doc);
     writer.close();
     
@@ -2753,10 +2810,12 @@ public abstract class BaseDocValuesForma
     assumeTrue("Codec does not support SORTED_NUMERIC", codecSupportsSortedNumeric());
     Directory directory = newDirectory();
     IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(null));
-    Document doc = new Document();
-    doc.add(new SortedNumericDocValuesField("dv", 5));
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.setMultiValued("dv");
+    Document2 doc = writer.newDocument();
+    doc.addLong("dv", 5);
     writer.addDocument(doc);
-    writer.addDocument(new Document());
+    writer.addDocument(writer.newDocument());
     writer.close();
     
     // Now search the index:
@@ -2785,12 +2844,12 @@ public abstract class BaseDocValuesForma
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
     
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.NO));
+    Document2 doc = iwriter.newDocument();
+    doc.addAtom("id", "0");
     iwriter.addDocument(doc);    
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.NO));
-    doc.add(new NumericDocValuesField("field", 5));
+    doc = iwriter.newDocument();
+    doc.addAtom("id", "1");
+    doc.addLong("field", 5);
     iwriter.addDocument(doc);
     iwriter.commit();
     iwriter.deleteDocuments(new Term("id", "1"));
@@ -2810,9 +2869,11 @@ public abstract class BaseDocValuesForma
     assumeTrue("Codec does not support SORTED_NUMERIC", codecSupportsSortedNumeric());
     Directory directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random(), directory);
-    Document doc = new Document();
-    doc.add(new SortedNumericDocValuesField("dv", 11));
-    doc.add(new SortedNumericDocValuesField("dv", -5));
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.setMultiValued("dv");
+    Document2 doc = writer.newDocument();
+    doc.addLong("dv", 11);
+    doc.addLong("dv", -5);
     writer.addDocument(doc);
     writer.close();
     
@@ -2833,9 +2894,11 @@ public abstract class BaseDocValuesForma
     assumeTrue("Codec does not support SORTED_NUMERIC", codecSupportsSortedNumeric());
     Directory directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random(), directory);
-    Document doc = new Document();
-    doc.add(new SortedNumericDocValuesField("dv", 11));
-    doc.add(new SortedNumericDocValuesField("dv", 11));
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.setMultiValued("dv");
+    Document2 doc = writer.newDocument();
+    doc.addLong("dv", 11);
+    doc.addLong("dv", 11);
     writer.addDocument(doc);
     writer.close();
     
@@ -2856,11 +2919,13 @@ public abstract class BaseDocValuesForma
     assumeTrue("Codec does not support SORTED_NUMERIC", codecSupportsSortedNumeric());
     Directory directory = newDirectory();
     IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(null));
-    Document doc = new Document();
-    doc.add(new SortedNumericDocValuesField("dv", 11));
-    doc.add(new SortedNumericDocValuesField("dv", -5));
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.setMultiValued("dv");
+    Document2 doc = writer.newDocument();
+    doc.addLong("dv", 11);
+    doc.addLong("dv", -5);
     writer.addDocument(doc);
-    writer.addDocument(new Document());
+    writer.addDocument(writer.newDocument());
     writer.close();
     
     // Now search the index:
@@ -2889,12 +2954,14 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwc = new IndexWriterConfig(null);
     iwc.setMergePolicy(newLogMergePolicy());
     IndexWriter writer = new IndexWriter(directory, iwc);
-    Document doc = new Document();
-    doc.add(new SortedNumericDocValuesField("dv", 11));
+    FieldTypes fieldTypes = writer.getFieldTypes();
+    fieldTypes.setMultiValued("dv");
+    Document2 doc = writer.newDocument();
+    doc.addLong("dv", 11);
     writer.addDocument(doc);
     writer.commit();
-    doc = new Document();
-    doc.add(new SortedNumericDocValuesField("dv", -5));
+    doc = writer.newDocument();
+    doc.addLong("dv", -5);
     writer.addDocument(doc);
     writer.forceMerge(1);
     writer.close();
@@ -2921,13 +2988,15 @@ public abstract class BaseDocValuesForma
     IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
     iwconfig.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
+    FieldTypes fieldTypes = iwriter.getFieldTypes();
+    fieldTypes.setMultiValued("field");
     
-    Document doc = new Document();
-    doc.add(new StringField("id", "0", Field.Store.NO));
+    Document2 doc = iwriter.newDocument();
+    doc.addAtom("id", "0");
     iwriter.addDocument(doc);    
-    doc = new Document();
-    doc.add(new StringField("id", "1", Field.Store.NO));
-    doc.add(new SortedNumericDocValuesField("field", 5));
+    doc = iwriter.newDocument();
+    doc.addAtom("id", "1");
+    doc.addLong("field", 5);
     iwriter.addDocument(doc);
     iwriter.commit();
     iwriter.deleteDocuments(new Term("id", "1"));

Modified: lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java Thu Nov 27 11:34:43 2014
@@ -23,6 +23,7 @@ import java.util.Random;
 import java.util.Set;
 
 import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.document.Document2;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.FieldType;
 import org.apache.lucene.document.StoredField;
@@ -179,8 +180,8 @@ public abstract class BaseFieldInfoForma
   }
   
   @Override
-  protected void addRandomFields(Document doc) {
-    doc.add(new StoredField("foobar", TestUtil.randomSimpleString(random())));
+  protected void addRandomFields(Document2 doc) {
+    doc.addStored("foobar", TestUtil.randomSimpleString(random()));
   }
 
   @Override

Modified: lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseIndexFileFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseIndexFileFormatTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseIndexFileFormatTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseIndexFileFormatTestCase.java Thu Nov 27 11:34:43 2014
@@ -32,7 +32,9 @@ import java.util.Set;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.codecs.Codec;
 import org.apache.lucene.codecs.mockrandom.MockRandomPostingsFormat;
+import org.apache.lucene.document.Document2;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.document.FieldTypes;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.MockDirectoryWrapper;
@@ -136,7 +138,7 @@ abstract class BaseIndexFileFormatTestCa
   }
 
   /** Add random fields to the provided document. */
-  protected abstract void addRandomFields(Document doc);
+  protected abstract void addRandomFields(Document2 doc);
 
   private Map<String, Long> bytesUsedByExtension(Directory d) throws IOException {
     Map<String, Long> bytesUsedByExtension = new HashMap<>();
@@ -178,9 +180,12 @@ abstract class BaseIndexFileFormatTestCa
     mp.setNoCFSRatio(0);
     IndexWriterConfig cfg = new IndexWriterConfig(new MockAnalyzer(random())).setUseCompoundFile(false).setMergePolicy(mp);
     IndexWriter w = new IndexWriter(dir, cfg);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.disableExistsFilters();
+
     final int numDocs = atLeast(500);
     for (int i = 0; i < numDocs; ++i) {
-      Document d = new Document();
+      Document2 d = w.newDocument();
       addRandomFields(d);
       w.addDocument(d);
     }
@@ -199,6 +204,8 @@ abstract class BaseIndexFileFormatTestCa
     mp.setNoCFSRatio(0);
     cfg = new IndexWriterConfig(new MockAnalyzer(random())).setUseCompoundFile(false).setMergePolicy(mp);
     w = new IndexWriter(dir2, cfg);
+    fieldTypes = w.getFieldTypes();
+    fieldTypes.disableExistsFilters();
     w.addIndexes(reader);
     w.commit();
     w.close();
@@ -226,7 +233,7 @@ abstract class BaseIndexFileFormatTestCa
     final int numDocs = atLeast(10000);
     LeafReader reader1 = null;
     for (int i = 0; i < numDocs; ++i) {
-      Document d = new Document();
+      Document2 d = w.newDocument();
       addRandomFields(d);
       w.addDocument(d);
       if (i == 100) {

Modified: lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseMergePolicyTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseMergePolicyTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseMergePolicyTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseMergePolicyTestCase.java Thu Nov 27 11:34:43 2014
@@ -52,7 +52,7 @@ public abstract class BaseMergePolicyTes
     for (int i = 0; i < numSegments; ++i) {
       final int numDocs = TestUtil.nextInt(random(), 1, 5);
       for (int j = 0; j < numDocs; ++j) {
-        writer.addDocument(new Document());
+        writer.addDocument(writer.newDocument());
       }
       writer.getReader().close();
     }

Modified: lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseNormsFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseNormsFormatTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseNormsFormatTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseNormsFormatTestCase.java Thu Nov 27 11:34:43 2014
@@ -22,10 +22,10 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
 
-import com.carrotsearch.randomizedtesting.annotations.Seed;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.analysis.MockTokenizer;
+import org.apache.lucene.document.Document2;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.StringField;
@@ -35,6 +35,7 @@ import org.apache.lucene.search.TermStat
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.TestUtil;
+import com.carrotsearch.randomizedtesting.annotations.Seed;
 
 /**
  * Abstract class to do basic tests for a norms format.
@@ -222,16 +223,12 @@ public abstract class BaseNormsFormatTes
     IndexWriterConfig conf = newIndexWriterConfig(analyzer);
     conf.setSimilarity(new CannedNormSimilarity(norms));
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);
-    Document doc = new Document();
-    Field idField = new StringField("id", "", Field.Store.NO);
-    Field storedField = newTextField("stored", "", Field.Store.YES);
-    doc.add(idField);
-    doc.add(storedField);
     
     for (int i = 0; i < numDocs; i++) {
-      idField.setStringValue(Integer.toString(i));
+      Document2 doc = writer.newDocument();
+      doc.addAtom("id", Integer.toString(i));
       long value = norms[i];
-      storedField.setStringValue(Long.toString(value));
+      doc.addLargeText("stored", Long.toString(value));
       writer.addDocument(doc);
       if (random().nextInt(31) == 0) {
         writer.commit();
@@ -307,10 +304,9 @@ public abstract class BaseNormsFormatTes
   }
 
   @Override
-  protected void addRandomFields(Document doc) {
+  protected void addRandomFields(Document2 doc) {
     // TODO: improve
-    doc.add(new TextField("foobar", TestUtil.randomSimpleString(random()), Field.Store.NO));
-    
+    doc.addLargeText("foobar", TestUtil.randomSimpleString(random()));
   }
 
   @Override
@@ -352,11 +348,11 @@ public abstract class BaseNormsFormatTes
     int numDocs = atLeast(1000);
     List<Integer> toDelete = new ArrayList<>();
     for(int i=0;i<numDocs;i++) {
-      Document doc = new Document();
-      doc.add(new StringField("id", ""+i, Field.Store.NO));
+      Document2 doc = w.newDocument();
       if (random().nextInt(5) == 1) {
         toDelete.add(i);
-        doc.add(new TextField("content", "some content", Field.Store.NO));
+        doc.addAtom("id", ""+i);
+        doc.addLargeText("content", "some content");
       }
       w.addDocument(doc);
     }

Modified: lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java Thu Nov 27 11:34:43 2014
@@ -42,9 +42,11 @@ import org.apache.lucene.codecs.FieldsPr
 import org.apache.lucene.codecs.PostingsFormat;
 import org.apache.lucene.codecs.asserting.AssertingCodec;
 import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;
+import org.apache.lucene.document.Document2;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.FieldTypes;
 import org.apache.lucene.index.TermsEnum.SeekStatus;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FlushInfo;
@@ -60,8 +62,8 @@ import org.apache.lucene.util.TestUtil;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.lucene.util.Version;
 import org.apache.lucene.util.automaton.Automaton;
-import org.apache.lucene.util.automaton.AutomatonTestUtil;
 import org.apache.lucene.util.automaton.AutomatonTestUtil.RandomAcceptedStrings;
+import org.apache.lucene.util.automaton.AutomatonTestUtil;
 import org.apache.lucene.util.automaton.CompiledAutomaton;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -1411,8 +1413,10 @@ public abstract class BasePostingsFormat
     IndexWriterConfig iwc = newIndexWriterConfig(null);
     iwc.setCodec(getCodec());
     RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
-    Document doc = new Document();
-    doc.add(newStringField("", "something", Field.Store.NO));
+    FieldTypes fieldTypes = iw.getFieldTypes();
+    fieldTypes.disableExistsFilters();
+    Document2 doc = iw.newDocument();
+    doc.addAtom("", "something");
     iw.addDocument(doc);
     DirectoryReader ir = iw.getReader();
     LeafReader ar = getOnlySegmentReader(ir);
@@ -1436,15 +1440,17 @@ public abstract class BasePostingsFormat
     IndexWriterConfig iwc = newIndexWriterConfig(null);
     iwc.setCodec(getCodec());
     RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
-    Document doc = new Document();
-    doc.add(newStringField("", "", Field.Store.NO));
+    FieldTypes fieldTypes = iw.getFieldTypes();
+    fieldTypes.disableExistsFilters();
+    Document2 doc = iw.newDocument();
+    doc.addAtom("", "");
     iw.addDocument(doc);
     DirectoryReader ir = iw.getReader();
     LeafReader ar = getOnlySegmentReader(ir);
     Fields fields = ar.fields();
     int fieldCount = fields.size();
     // -1 is allowed, if the codec doesn't implement fields.size():
-    assertTrue(fieldCount == 1 || fieldCount == -1);
+    assertTrue("got fieldCount=" + fieldCount, fieldCount == 1 || fieldCount == -1);
     Terms terms = ar.terms("");
     assertNotNull(terms);
     TermsEnum termsEnum = terms.iterator(null);
@@ -1464,9 +1470,11 @@ public abstract class BasePostingsFormat
     iwc.setCodec(getCodec());
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
-    Document doc = new Document();
+    FieldTypes fieldTypes = iw.getFieldTypes();
+    fieldTypes.disableExistsFilters();
+    Document2 doc = iw.newDocument();
     iw.addDocument(doc);
-    doc.add(newStringField("ghostField", "something", Field.Store.NO));
+    doc.addAtom("ghostField", "something");
     iw.addDocument(doc);
     iw.forceMerge(1);
     iw.deleteDocuments(new Term("ghostField", "something")); // delete the only term for the field
@@ -1689,11 +1697,11 @@ public abstract class BasePostingsFormat
 
     RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc);
 
-    LineFileDocs docs = new LineFileDocs(random());
+    LineFileDocs docs = new LineFileDocs(w.w, random());
     int bytesToIndex = atLeast(100) * 1024;
     int bytesIndexed = 0;
     while (bytesIndexed < bytesToIndex) {
-      Document doc = docs.nextDoc();
+      Document2 doc = docs.nextDoc();
       w.addDocument(doc);
       bytesIndexed += RamUsageTester.sizeOf(doc);
     }
@@ -1733,17 +1741,18 @@ public abstract class BasePostingsFormat
   }
 
   @Override
-  protected void addRandomFields(Document doc) {
+  protected void addRandomFields(Document2 doc) {
+    FieldTypes fieldTypes = doc.getFieldTypes();
     for (IndexOptions opts : IndexOptions.values()) {
       if (opts == IndexOptions.NONE) {
         continue;
       }
-      FieldType ft = new FieldType();
-      ft.setIndexOptions(opts);
-      ft.freeze();
+      fieldTypes.setIndexOptions("f_" + opts, opts);
+      fieldTypes.disableHighlighting("f_" + opts);
+      fieldTypes.setMultiValued("f_" + opts);
       final int numFields = random().nextInt(5);
       for (int j = 0; j < numFields; ++j) {
-        doc.add(new Field("f_" + opts, TestUtil.randomSimpleString(random(), 2), ft));
+        doc.addLargeText("f_" + opts, TestUtil.randomSimpleString(random(), 2));
       }
     }
   }

Modified: lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java Thu Nov 27 11:34:43 2014
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.document.Document2;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.StoredField;
 import org.apache.lucene.store.Directory;
@@ -189,8 +190,8 @@ public abstract class BaseSegmentInfoFor
   }
   
   @Override
-  protected void addRandomFields(Document doc) {
-    doc.add(new StoredField("foobar", TestUtil.randomSimpleString(random())));
+  protected void addRandomFields(Document2 doc) {
+    doc.addStored("foobar", TestUtil.randomSimpleString(random()));
   }
 
   @Override

Modified: lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java?rev=1642110&r1=1642109&r2=1642110&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java (original)
+++ lucene/dev/branches/lucene6005/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java Thu Nov 27 11:34:43 2014
@@ -35,15 +35,11 @@ import org.apache.lucene.codecs.StoredFi
 import org.apache.lucene.codecs.simpletext.SimpleTextCodec;
 import org.apache.lucene.document.Document2;
 import org.apache.lucene.document.Document;
-import org.apache.lucene.document.DoubleField;
 import org.apache.lucene.document.Field.Store;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.FieldType.NumericType;
 import org.apache.lucene.document.FieldType;
 import org.apache.lucene.document.FieldTypes;
-import org.apache.lucene.document.FloatField;
-import org.apache.lucene.document.IntField;
-import org.apache.lucene.document.LongField;
 import org.apache.lucene.document.NumericDocValuesField;
 import org.apache.lucene.document.StoredField;
 import org.apache.lucene.document.StringField;
@@ -71,10 +67,12 @@ import com.carrotsearch.randomizedtestin
 public abstract class BaseStoredFieldsFormatTestCase extends BaseIndexFileFormatTestCase {
 
   @Override
-  protected void addRandomFields(Document d) {
+  protected void addRandomFields(Document2 d) {
+    FieldTypes fieldTypes = d.getFieldTypes();
+    fieldTypes.setMultiValued("f");
     final int numValues = random().nextInt(3);
     for (int i = 0; i < numValues; ++i) {
-      d.add(new StoredField("f", TestUtil.randomSimpleString(random(), 100)));
+      d.addStored("f", TestUtil.randomSimpleString(random(), 100));
     }
   }
 
@@ -175,13 +173,13 @@ public abstract class BaseStoredFieldsFo
   public void testStoredFieldsOrder() throws Throwable {
     Directory d = newDirectory();
     IndexWriter w = new IndexWriter(d, newIndexWriterConfig(new MockAnalyzer(random())));
-    Document doc = new Document();
+    Document2 doc = w.newDocument();
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setMultiValued("zzz");
 
-    FieldType customType = new FieldType();
-    customType.setStored(true);
-    doc.add(newField("zzz", "a b c", customType));
-    doc.add(newField("aaa", "a b c", customType));
-    doc.add(newField("zzz", "1 2 3", customType));
+    doc.addStored("zzz", "a b c");
+    doc.addStored("aaa", "a b c");
+    doc.addStored("zzz", "1 2 3");
     w.addDocument(doc);
     IndexReader r = w.getReader();
     Document2 doc2 = r.document(0);
@@ -214,14 +212,11 @@ public abstract class BaseStoredFieldsFo
     for(int i=0;i<50;i++)
       b[i] = (byte) (i+77);
 
-    Document doc = new Document();
-    Field f = new StoredField("binary", b, 10, 17);
-    byte[] bx = f.binaryValue().bytes;
-    assertTrue(bx != null);
-    assertEquals(50, bx.length);
-    assertEquals(10, f.binaryValue().offset);
-    assertEquals(17, f.binaryValue().length);
-    doc.add(f);
+    Document2 doc = w.newDocument();
+    doc.addBinary("binary", new BytesRef(b, 10, 17));
+    BytesRef binaryValue = doc.getBinary("binary");
+    assertEquals(10, binaryValue.offset);
+    assertEquals(17, binaryValue.length);
     w.addDocument(doc);
     w.close();
 
@@ -268,35 +263,45 @@ public abstract class BaseStoredFieldsFo
     final float f = random().nextFloat();
     final double d = random().nextDouble();
 
-    List<Field> fields = Arrays.asList(
-        new Field("bytes", bytes, ft),
-        new Field("string", string, ft),
-        new LongField("long", l, Store.YES),
-        new IntField("int", i, Store.YES),
-        new FloatField("float", f, Store.YES),
-        new DoubleField("double", d, Store.YES)
-    );
-
     for (int k = 0; k < 100; ++k) {
-      Document doc = new Document();
-      for (Field fld : fields) {
-        doc.add(fld);
-      }
+      Document2 doc = iw.newDocument();
+      doc.addStored("bytes", bytes);
+      doc.addStored("string", string);
+      doc.addInt("int", i);
+      doc.addLong("long", l);
+      doc.addFloat("float", f);
+      doc.addDouble("double", d);
       iw.w.addDocument(doc);
     }
     iw.commit();
 
     final DirectoryReader reader = DirectoryReader.open(dir);
     final int docID = random().nextInt(100);
-    for (Field fld : fields) {
-      String fldName = fld.name();
+    for (String fldName : new String[] {"bytes", "string", "int", "long", "float", "double"}) {
       final Document2 sDoc = reader.document(docID, Collections.singleton(fldName));
+
       final IndexableField sField = sDoc.getField(fldName);
-      if (Field.class.equals(fld.getClass())) {
-        assertEquals(fld.binaryValue(), sField.binaryValue());
-        assertEquals(fld.stringValue(), sField.stringValue());
-      } else {
-        assertEquals(fld.numericValue(), sField.numericValue());
+      switch (fldName) {
+      case "bytes":
+        assertEquals(new BytesRef(bytes), sField.binaryValue());
+        break;
+      case "string":
+        assertEquals(string, sField.stringValue());
+        break;
+      case "int":
+        assertEquals(i, sField.numericValue().intValue());
+        break;
+      case "long":
+        assertEquals(l, sField.numericValue().longValue());
+        break;
+      case "float":
+        assertEquals(f, sField.numericValue().floatValue(), 0.0f);
+        break;
+      case "double":
+        assertEquals(d, sField.numericValue().doubleValue(), 0.0);
+        break;
+      default:
+        assert false;
       }
     }
     reader.close();
@@ -311,7 +316,7 @@ public abstract class BaseStoredFieldsFo
     RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwConf);
     
     // make sure that the fact that documents might be empty is not a problem
-    final Document emptyDoc = new Document();
+    final Document2 emptyDoc = iw.newDocument();
     final int numDocs = random().nextBoolean() ? 1 : atLeast(1000);
     for (int i = 0; i < numDocs; ++i) {
       iw.addDocument(emptyDoc);