diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesFormat.java index a96f8c1639d..d692705fdad 100644 --- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesFormat.java +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesFormat.java @@ -34,6 +34,7 @@ import org.apache.lucene.index.SegmentWriteState; * for numbers this is a "fixed-width" file, for example a single byte range: *
  *  field myField
+ *    type NUMERIC
  *    minvalue 0
  *    pattern 000
  *  005
@@ -47,6 +48,7 @@ import org.apache.lucene.index.SegmentWriteState;
  *  for bytes this is also a "fixed-width" file, for example:
  *  
  *  field myField
+ *    type BINARY
  *    maxlength 6
  *    pattern 0
  *  length 6
@@ -61,6 +63,7 @@ import org.apache.lucene.index.SegmentWriteState;
  *  for sorted bytes this is a fixed-width file, for example:
  *  
  *  field myField
+ *    type SORTED
  *    numvalues 10
  *    maxLength 8
  *    pattern 0
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java
index 654aecf9afb..1452e02bd87 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java
@@ -48,7 +48,7 @@ import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.MINV
 import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.NUMVALUES;
 import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.ORDPATTERN;
 import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.PATTERN;
-
+import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.TYPE;
 
 // nocommit make sure we test "all docs have 0 value",
 // "all docs have empty BytesREf"
@@ -56,7 +56,6 @@ import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.PATT
 class SimpleTextDocValuesReader extends DocValuesProducer {
 
   static class OneField {
-    FieldInfo fieldInfo;
     long dataStartFilePointer;
     String pattern;
     String ordPattern;
@@ -90,11 +89,10 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
       OneField field = new OneField();
       fields.put(fieldName, field);
 
-      field.fieldInfo = fieldInfo;
-      //System.out.println("  field=" + fieldName);
+      readLine();
+      assert startsWith(TYPE) : scratch.utf8ToString();
 
-      // nocommit hack hack hack!!:
-      DocValuesType dvType = ext.equals("len") ? DocValuesType.NUMERIC : fieldInfo.getDocValuesType();
+      DocValuesType dvType = DocValuesType.valueOf(stripPrefix(TYPE));
       assert dvType != null;
       if (dvType == DocValuesType.NUMERIC) {
         readLine();
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesWriter.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesWriter.java
index e8547484218..7e590360bdd 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesWriter.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesWriter.java
@@ -37,6 +37,7 @@ import org.apache.lucene.util.IOUtils;
 class SimpleTextDocValuesWriter extends DocValuesConsumer {
   final static BytesRef END     = new BytesRef("END");
   final static BytesRef FIELD   = new BytesRef("field ");
+  final static BytesRef TYPE    = new BytesRef("  type ");
   // used for numerics
   final static BytesRef MINVALUE = new BytesRef("  minvalue ");
   final static BytesRef PATTERN  = new BytesRef("  pattern ");
@@ -50,15 +51,12 @@ class SimpleTextDocValuesWriter extends DocValuesConsumer {
   final IndexOutput data;
   final BytesRef scratch = new BytesRef();
   final int numDocs;
-  // nocommit
-  final boolean isNorms;
   private final Set fieldsSeen = new HashSet(); // for asserting
   
   public SimpleTextDocValuesWriter(SegmentWriteState state, String ext) throws IOException {
     //System.out.println("WRITE: " + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext) + " " + state.segmentInfo.getDocCount() + " docs");
     data = state.directory.createOutput(IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext), state.context);
     numDocs = state.segmentInfo.getDocCount();
-    isNorms = ext.equals("len");
   }
 
   // for asserting
@@ -71,10 +69,9 @@ class SimpleTextDocValuesWriter extends DocValuesConsumer {
   @Override
   public void addNumericField(FieldInfo field, Iterable values) throws IOException {
     assert fieldSeen(field.name);
-    // nocommit: this must be multiple asserts
-    //assert (field.getDocValuesType() != null && (DocValues.isNumber(field.getDocValuesType()) || DocValues.isFloat(field.getDocValuesType()))) ||
-    //  (field.getNormType() != null && (DocValues.isNumber(field.getNormType()) || DocValues.isFloat(field.getNormType()))): "field=" + field.name;
-    writeFieldEntry(field);
+    assert (field.getDocValuesType() == FieldInfo.DocValuesType.NUMERIC ||
+            field.getNormType() == FieldInfo.DocValuesType.NUMERIC);
+    writeFieldEntry(field, FieldInfo.DocValuesType.NUMERIC);
 
     // first pass to find min/max
     long minValue = Long.MAX_VALUE;
@@ -132,12 +129,11 @@ class SimpleTextDocValuesWriter extends DocValuesConsumer {
   public void addBinaryField(FieldInfo field, Iterable values) throws IOException {
     assert fieldSeen(field.name);
     assert field.getDocValuesType() == DocValuesType.BINARY;
-    assert !isNorms;
     int maxLength = 0;
     for(BytesRef value : values) {
       maxLength = Math.max(maxLength, value.length);
     }
-    writeFieldEntry(field);
+    writeFieldEntry(field, FieldInfo.DocValuesType.BINARY);
 
     // write maxLength
     SimpleTextUtil.write(data, MAXLENGTH);
@@ -181,8 +177,7 @@ class SimpleTextDocValuesWriter extends DocValuesConsumer {
   public void addSortedField(FieldInfo field, Iterable values, Iterable docToOrd) throws IOException {
     assert fieldSeen(field.name);
     assert field.getDocValuesType() == DocValuesType.SORTED;
-    assert !isNorms;
-    writeFieldEntry(field);
+    writeFieldEntry(field, FieldInfo.DocValuesType.SORTED);
 
     int valueCount = 0;
     int maxLength = -1;
@@ -256,10 +251,14 @@ class SimpleTextDocValuesWriter extends DocValuesConsumer {
   }
 
   /** write the header for this field */
-  private void writeFieldEntry(FieldInfo field) throws IOException {
+  private void writeFieldEntry(FieldInfo field, FieldInfo.DocValuesType type) throws IOException {
     SimpleTextUtil.write(data, FIELD);
     SimpleTextUtil.write(data, field.name, scratch);
     SimpleTextUtil.writeNewline(data);
+    
+    SimpleTextUtil.write(data, TYPE);
+    SimpleTextUtil.write(data, type.toString(), scratch);
+    SimpleTextUtil.writeNewline(data);
   }
   
   @Override