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 2012/01/16 00:05:15 UTC

svn commit: r1231791 [1/4] - in /lucene/dev/trunk: lucene/ lucene/contrib/demo/src/java/org/apache/lucene/demo/ lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/ lucene/contrib/misc/src/java/org/apache/lucene/document/ lucene/cont...

Author: mikemccand
Date: Sun Jan 15 23:05:13 2012
New Revision: 1231791

URL: http://svn.apache.org/viewvc?rev=1231791&view=rev
Log:
LUCENE-3453: simplify DocValues/Field API

Added:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/StoredField.java
      - copied, changed from r1231541, lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/BinaryField.java
Removed:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/BinaryField.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocValue.java
Modified:
    lucene/dev/trunk/lucene/MIGRATE.txt
    lucene/dev/trunk/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexFiles.java
    lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
    lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java
    lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
    lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/DocValuesConsumer.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/FixedStraightBytesImpl.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsWriter.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/DocValuesField.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/Field.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/FieldType.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/NumericField.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/StringField.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/TextField.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DocValues.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexableField.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexableFieldType.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/NormsConsumer.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/NormsConsumerPerField.java
    lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexNormsConsumer.java
    lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/index/DocHelper.java
    lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/index/RandomIndexWriter.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/codecs/lucene40/TestDocValues.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/document/TestBinaryDocument.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/document/TestDocument.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestConsistentFieldNumbers.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDuelingCodecs.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexableField.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestTermsEnum.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestTypePromotion.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDocValuesScoring.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestFieldCache.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSort.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestTopDocsMerge.java
    lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java
    lucene/dev/trunk/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java
    lucene/dev/trunk/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java
    lucene/dev/trunk/modules/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
    lucene/dev/trunk/modules/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
    lucene/dev/trunk/modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestNumericQueryParser.java
    lucene/dev/trunk/modules/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/transform/BaseEditorialTransformer.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/BinaryField.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/TrieField.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/PolyFieldTest.java

Modified: lucene/dev/trunk/lucene/MIGRATE.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/MIGRATE.txt?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/MIGRATE.txt (original)
+++ lucene/dev/trunk/lucene/MIGRATE.txt Sun Jan 15 23:05:13 2012
@@ -422,13 +422,13 @@ LUCENE-1458, LUCENE-2111: Flexible Index
 
 
 
-* LUCENE-2308: Separate IndexableFieldType from Field instances
+* LUCENE-2308,LUCENE-3453: Separate IndexableFieldType from Field instances
 
 With this change, the indexing details (indexed, tokenized, norms,
 indexOptions, stored, etc.) are moved into a separate FieldType
 instance (rather than being stored directly on the Field).
 
-This means you can create the IndexableFieldType instance once, up front,
+This means you can create the FieldType instance once, up front,
 for a given field, and then re-use that instance whenever you instantiate
 the Field.
 
@@ -439,15 +439,21 @@ Certain field types are pre-defined sinc
     IDS (does not index term frequency nor positions).  This field
     does not store its value, but exposes TYPE_STORED as well.
 
-  * BinaryField: a byte[] value that's only stored.
-
   * TextField: indexes and tokenizes a String, Reader or TokenStream
     value, without term vectors.  This field does not store its value,
     but exposes TYPE_STORED as well.
 
+  * StoredField: field that stores its value
+
+  * DocValuesField: indexes the value as a DocValues field
+
+  * NumericField: indexes the numeric value so that NumericRangeQuery
+    can be used at search-time.
+
 If your usage fits one of those common cases you can simply
-instantiate the above class.  To use the TYPE_STORED variant, do this
-instead:
+instantiate the above class.  If you need to store the value, you can
+add a separate StoredField to the document, or you can use
+TYPE_STORED for the field:
 
   Field f = new Field("field", "value", StringField.TYPE_STORED);
 
@@ -465,9 +471,14 @@ You can of course also create your own F
   t.setStored(true);
   t.setOmitNorms(true);
   t.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
+  t.freeze();
 
 FieldType has a freeze() method to prevent further changes.
 
+There is also a deprecated transition API, providing the same Index,
+Store, TermVector enums from 3.x, and Field constructors taking these
+enums.
+
 When migrating from the 3.x API, if you did this before:
 
   new Field("field", "value", Field.Store.NO, Field.Indexed.NOT_ANALYZED_NO_NORMS)
@@ -528,7 +539,7 @@ If you did this before (bytes is a byte[
 
 you can now do this:
 
-  new BinaryField("field", bytes)
+  new StoredField("field", bytes)
 
 * LUCENE-3396: Analyzer.tokenStream() and .reusableTokenStream() have been made final.
   It is now necessary to use Analyzer.TokenStreamComponents to define an analysis process.

Modified: lucene/dev/trunk/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexFiles.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexFiles.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexFiles.java (original)
+++ lucene/dev/trunk/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexFiles.java Sun Jan 15 23:05:13 2012
@@ -184,9 +184,7 @@ public class IndexFiles {
           // year/month/day/hour/minutes/seconds, down the resolution you require.
           // For example the long value 2011021714 would mean
           // February 17, 2011, 2-3 PM.
-          NumericField modifiedField = new NumericField("modified");
-          modifiedField.setLongValue(file.lastModified());
-          doc.add(modifiedField);
+          doc.add(new NumericField("modified", file.lastModified()));
 
           // Add the contents of the file to a field named "contents".  Specify a Reader,
           // so that the text of the file is tokenized and indexed, but not stored.

Modified: lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java (original)
+++ lucene/dev/trunk/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java Sun Jan 15 23:05:13 2012
@@ -386,7 +386,7 @@ public class HighlighterTest extends Bas
     Highlighter highlighter = new Highlighter(this, scorer);
     
     for (int i = 0; i < hits.totalHits; i++) {
-      String text = searcher.doc(hits.scoreDocs[i].doc).get(NUMERIC_FIELD_NAME);
+      String text = searcher.doc(hits.scoreDocs[i].doc).getField(NUMERIC_FIELD_NAME).numericValue().toString();
       TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, new StringReader(text));
 
       highlighter.setTextFragmenter(new SimpleFragmenter(40));
@@ -1738,25 +1738,21 @@ public class HighlighterTest extends Bas
       addDoc(writer, text);
     }
     Document doc = new Document();
-    NumericField nfield = new NumericField(NUMERIC_FIELD_NAME, NumericField.TYPE_STORED);
-    nfield.setIntValue(1);
-    doc.add(nfield);
+    doc.add(new NumericField(NUMERIC_FIELD_NAME, 1, NumericField.getFieldType(NumericField.DataType.INT, true)));
     writer.addDocument(doc, analyzer);
-    nfield = new NumericField(NUMERIC_FIELD_NAME, NumericField.TYPE_STORED);
-    nfield.setIntValue(3);
+
     doc = new Document();
-    doc.add(nfield);
+    doc.add(new NumericField(NUMERIC_FIELD_NAME, 3, NumericField.getFieldType(NumericField.DataType.INT, true)));
     writer.addDocument(doc, analyzer);
-    nfield = new NumericField(NUMERIC_FIELD_NAME, NumericField.TYPE_STORED);
-    nfield.setIntValue(5);
+
     doc = new Document();
-    doc.add(nfield);
+    doc.add(new NumericField(NUMERIC_FIELD_NAME, 5, NumericField.getFieldType(NumericField.DataType.INT, true)));
     writer.addDocument(doc, analyzer);
-    nfield = new NumericField(NUMERIC_FIELD_NAME, NumericField.TYPE_STORED);
-    nfield.setIntValue(7);
+
     doc = new Document();
-    doc.add(nfield);
+    doc.add(new NumericField(NUMERIC_FIELD_NAME, 7, NumericField.getFieldType(NumericField.DataType.INT, true)));
     writer.addDocument(doc, analyzer);
+
     writer.forceMerge(1);
     writer.close();
     reader = IndexReader.open(ramDir);

Modified: lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java (original)
+++ lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java Sun Jan 15 23:05:13 2012
@@ -23,13 +23,10 @@ import java.util.Map;
 
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.TokenStream;
-import org.apache.lucene.document.NumericField.DataType;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.index.IndexableFieldType;
-import org.apache.lucene.index.DocValue;
-import org.apache.lucene.index.DocValues;
 import org.apache.lucene.util.BytesRef;
 
 /** Defers actually loading a field's value until you ask
@@ -121,24 +118,6 @@ public class LazyDocument {
     }
 
     @Override
-    public boolean numeric() {
-      if (num == 0) {
-        return getDocument().getField(name).numeric();
-      } else {
-        return getDocument().getFields(name)[num].numeric();
-      }
-    }
-
-    @Override
-    public DataType numericDataType() {
-      if (num == 0) {
-        return getDocument().getField(name).numericDataType();
-      } else {
-        return getDocument().getFields(name)[num].numericDataType();
-      }
-    }
-
-    @Override
     public Number numericValue() {
       if (num == 0) {
         return getDocument().getField(name).numericValue();
@@ -157,24 +136,6 @@ public class LazyDocument {
     }
 
     @Override
-    public DocValue docValue() {
-      if (num == 0) {
-        return getDocument().getField(name).docValue();
-      } else {
-        return getDocument().getFields(name)[num].docValue();
-      }
-    }
-
-    @Override
-    public DocValues.Type docValueType() {
-      if (num == 0) {
-        return getDocument().getField(name).docValueType();
-      } else {
-        return getDocument().getFields(name)[num].docValueType();
-      }
-    }
-
-    @Override
     public TokenStream tokenStream(Analyzer analyzer) throws IOException {
       if (num == 0) {
         return getDocument().getField(name).tokenStream(analyzer);

Modified: lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java (original)
+++ lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java Sun Jan 15 23:05:13 2012
@@ -23,9 +23,11 @@ import java.util.Map;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.document.FieldType;
 import org.apache.lucene.document.NumericField;
 import org.apache.lucene.document.StringField;
 import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.FieldInfo.IndexOptions;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
@@ -91,6 +93,18 @@ public class TestCartesian extends Lucen
     }
   }
   
+  private static final FieldType latLongType = new FieldType();
+  static {
+    latLongType.setIndexed(true);
+    latLongType.setStored(true);
+    latLongType.setTokenized(true);
+    latLongType.setOmitNorms(true);
+    latLongType.setIndexOptions(IndexOptions.DOCS_ONLY);
+    latLongType.setNumericType(NumericField.DataType.DOUBLE);
+    latLongType.setNumericPrecisionStep(Integer.MAX_VALUE);
+    latLongType.freeze();
+  }
+  
   private void addPoint(IndexWriter writer, String name, double lat, double lng) throws IOException{
     
     Document doc = new Document();
@@ -98,8 +112,8 @@ public class TestCartesian extends Lucen
     doc.add(newField("name", name, TextField.TYPE_STORED));
     
     // convert the lat / long to lucene fields
-    doc.add(new NumericField(latField, Integer.MAX_VALUE, NumericField.TYPE_STORED).setDoubleValue(lat));
-    doc.add(new NumericField(lngField, Integer.MAX_VALUE, NumericField.TYPE_STORED).setDoubleValue(lng));
+    doc.add(new NumericField(latField, lat, latLongType));
+    doc.add(new NumericField(lngField, lng, latLongType));
     
     // add a default meta field to make searching all documents easy 
     doc.add(newField("metafile", "doc", TextField.TYPE_STORED));
@@ -107,7 +121,7 @@ public class TestCartesian extends Lucen
     int ctpsize = ctps.size();
     for (int i =0; i < ctpsize; i++){
       CartesianTierPlotter ctp = ctps.get(i);
-      doc.add(new NumericField(ctp.getTierFieldName(), Integer.MAX_VALUE, TextField.TYPE_STORED).setDoubleValue(ctp.getTierBoxId(lat,lng)));
+      doc.add(new NumericField(ctp.getTierFieldName(), ctp.getTierBoxId(lat, lng), latLongType));
       
       doc.add(newField(geoHashPrefix, GeoHashUtils.encode(lat,lng), StringField.TYPE_STORED));
     }
@@ -248,8 +262,8 @@ public class TestCartesian extends Lucen
       Document d = searcher.doc(scoreDocs[i].doc);
 
       String name = d.get("name");
-      double rsLat = Double.parseDouble(d.get(latField));
-      double rsLng = Double.parseDouble(d.get(lngField));
+      double rsLat = d.getField(latField).numericValue().doubleValue();
+      double rsLng = d.getField(lngField).numericValue().doubleValue();
       Double geo_distance = distances.get(scoreDocs[i].doc);
 
       double distance = DistanceUtils.getDistanceMi(lat, lng, rsLat, rsLng);
@@ -317,8 +331,8 @@ public class TestCartesian extends Lucen
     for(int i =0 ; i < results; i++){
       Document d = searcher.doc(scoreDocs[i].doc);
       String name = d.get("name");
-      double rsLat = Double.parseDouble(d.get(latField));
-      double rsLng = Double.parseDouble(d.get(lngField));
+      double rsLat = d.getField(latField).numericValue().doubleValue();
+      double rsLng = d.getField(lngField).numericValue().doubleValue();
       Double geo_distance = distances.get(scoreDocs[i].doc);
 
       double distance = DistanceUtils.getDistanceMi(lat, lng, rsLat, rsLng);
@@ -389,8 +403,8 @@ public class TestCartesian extends Lucen
         Document d = searcher.doc(scoreDocs[i].doc);
       
         String name = d.get("name");
-        double rsLat = Double.parseDouble(d.get(latField));
-        double rsLng = Double.parseDouble(d.get(lngField)); 
+        double rsLat = d.getField(latField).numericValue().doubleValue();
+        double rsLng = d.getField(lngField).numericValue().doubleValue(); 
         Double geo_distance = distances.get(scoreDocs[i].doc);
       
         double distance = DistanceUtils.getDistanceMi(lat, lng, rsLat, rsLng);
@@ -461,8 +475,8 @@ public class TestCartesian extends Lucen
         Document d = searcher.doc(scoreDocs[i].doc);
 	      
         String name = d.get("name");
-        double rsLat = Double.parseDouble(d.get(latField));
-        double rsLng = Double.parseDouble(d.get(lngField)); 
+        double rsLat = d.getField(latField).numericValue().doubleValue();
+        double rsLng = d.getField(lngField).numericValue().doubleValue(); 
         Double geo_distance = distances.get(scoreDocs[i].doc);
 	      
         double distance = DistanceUtils.getDistanceMi(lat, lng, rsLat, rsLng);

Modified: lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java (original)
+++ lucene/dev/trunk/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java Sun Jan 15 23:05:13 2012
@@ -20,17 +20,19 @@ import java.io.IOException;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.document.FieldType;
 import org.apache.lucene.document.NumericField;
 import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.FieldInfo.IndexOptions;
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.QueryWrapperFilter;
 import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.QueryWrapperFilter;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.ReaderUtil;
-import org.apache.lucene.store.Directory;
 
 
 public class TestDistance extends LuceneTestCase {
@@ -58,6 +60,18 @@ public class TestDistance extends Lucene
     directory.close();
     super.tearDown();
   }
+
+  private static final FieldType latLongType = new FieldType();
+  static {
+    latLongType.setIndexed(true);
+    latLongType.setStored(true);
+    latLongType.setTokenized(true);
+    latLongType.setOmitNorms(true);
+    latLongType.setIndexOptions(IndexOptions.DOCS_ONLY);
+    latLongType.setNumericType(NumericField.DataType.DOUBLE);
+    latLongType.setNumericPrecisionStep(Integer.MAX_VALUE);
+    latLongType.freeze();
+  }
   
   private void addPoint(IndexWriter writer, String name, double lat, double lng) throws IOException{
     
@@ -66,8 +80,8 @@ public class TestDistance extends Lucene
     doc.add(newField("name", name, TextField.TYPE_STORED));
     
     // convert the lat / long to lucene fields
-    doc.add(new NumericField(latField, Integer.MAX_VALUE, NumericField.TYPE_STORED).setDoubleValue(lat));
-    doc.add(new NumericField(lngField, Integer.MAX_VALUE, NumericField.TYPE_STORED).setDoubleValue(lng));
+    doc.add(new NumericField(latField, lat, latLongType));
+    doc.add(new NumericField(lngField, lng, latLongType));
     
     // add a default meta field to make searching all documents easy 
     doc.add(newField("metafile", "doc", TextField.TYPE_STORED));

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/DocValuesConsumer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/DocValuesConsumer.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/DocValuesConsumer.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/DocValuesConsumer.java Sun Jan 15 23:05:13 2012
@@ -19,51 +19,50 @@ package org.apache.lucene.codecs;
 import java.io.IOException;
 
 import org.apache.lucene.codecs.lucene40.values.Writer;
-import org.apache.lucene.index.DocValues;
+import org.apache.lucene.document.DocValuesField;
+import org.apache.lucene.document.Field;
 import org.apache.lucene.index.DocValues.Source;
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.index.MergeState;
-import org.apache.lucene.index.DocValue;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 
 /**
- * Abstract API that consumes {@link DocValue}s.
+ * Abstract API that consumes {@link IndexableField}s.
  * {@link DocValuesConsumer} are always associated with a specific field and
  * segments. Concrete implementations of this API write the given
- * {@link DocValue} into a implementation specific format depending on
+ * {@link IndexableField} into a implementation specific format depending on
  * the fields meta-data.
  * 
  * @lucene.experimental
  */
 public abstract class DocValuesConsumer {
 
-  protected Source currentMergeSource;
   protected final BytesRef spare = new BytesRef();
 
   /**
-   * Adds the given {@link DocValue} instance to this
+   * Adds the given {@link IndexableField} instance to this
    * {@link DocValuesConsumer}
    * 
    * @param docID
    *          the document ID to add the value for. The docID must always
    *          increase or be <tt>0</tt> if it is the first call to this method.
-   * @param docValue
+   * @param value
    *          the value to add
    * @throws IOException
    *           if an {@link IOException} occurs
    */
-  public abstract void add(int docID, DocValue docValue)
+  public abstract void add(int docID, IndexableField value)
       throws IOException;
 
   /**
-   * Called when the consumer of this API is doc with adding
-   * {@link DocValue} to this {@link DocValuesConsumer}
+   * Called when the consumer of this API is done adding values.
    * 
    * @param docCount
    *          the total number of documents in this {@link DocValuesConsumer}.
    *          Must be greater than or equal the last given docID to
-   *          {@link #add(int, DocValue)}.
+   *          {@link #add(int, IndexableField)}.
    * @throws IOException
    */
   public abstract void finish(int docCount) throws IOException;
@@ -87,8 +86,8 @@ public abstract class DocValuesConsumer 
       final org.apache.lucene.index.MergeState.IndexReaderAndLiveDocs reader = mergeState.readers.get(readerIDX);
       if (docValues[readerIDX] != null) {
         hasMerged = true;
-        merge(new SingleSubMergeState(docValues[readerIDX], mergeState.docBase[readerIDX], reader.reader.maxDoc(),
-                                    reader.liveDocs));
+        merge(docValues[readerIDX], mergeState.docBase[readerIDX],
+              reader.reader.maxDoc(), reader.liveDocs);
         mergeState.checkAbort.work(reader.reader.maxDoc());
       }
     }
@@ -99,73 +98,66 @@ public abstract class DocValuesConsumer 
   }
 
   /**
-   * Merges the given {@link SingleSubMergeState} into this {@link DocValuesConsumer}.
+   * Merges the given {@link DocValues} into this {@link DocValuesConsumer}.
    * 
-   * @param state
-   *          the {@link SingleSubMergeState} to merge
    * @throws IOException
    *           if an {@link IOException} occurs
    */
-  protected void merge(SingleSubMergeState state) throws IOException {
+  protected void merge(DocValues reader, int docBase, int docCount, Bits liveDocs) throws IOException {
     // This enables bulk copies in subclasses per MergeState, subclasses can
     // simply override this and decide if they want to merge
     // segments using this generic implementation or if a bulk merge is possible
     // / feasible.
-    final Source source = state.reader.getDirectSource();
+    final Source source = reader.getDirectSource();
     assert source != null;
-    setNextMergeSource(source); // set the current enum we are working on - the
-    // impl. will get the correct reference for the type
-    // it supports
-    int docID = state.docBase;
-    final Bits liveDocs = state.liveDocs;
-    final int docCount = state.docCount;
+    int docID = docBase;
+    final DocValues.Type type = reader.type();
+    final Field scratchField;
+    switch(type) {
+    case VAR_INTS:
+      scratchField = new DocValuesField("", (long) 0, type);
+      break;
+    case FIXED_INTS_16:
+      scratchField = new DocValuesField("", (short) 0, type);
+      break;
+    case FIXED_INTS_32:
+      scratchField = new DocValuesField("", 0, type);
+      break;
+    case FIXED_INTS_64:
+      scratchField = new DocValuesField("", (long) 0, type);
+      break;
+    case FIXED_INTS_8:
+      scratchField = new DocValuesField("", (byte) 0, type);
+      break;
+    case FLOAT_32:
+      scratchField = new DocValuesField("", (float) 0, type);
+      break;
+    case FLOAT_64:
+      scratchField = new DocValuesField("", (double) 0, type);
+      break;
+    case BYTES_FIXED_STRAIGHT:
+    case BYTES_FIXED_DEREF:
+    case BYTES_FIXED_SORTED:
+    case BYTES_VAR_STRAIGHT:
+    case BYTES_VAR_DEREF:
+    case BYTES_VAR_SORTED:
+      scratchField = new DocValuesField("", new BytesRef(), type);
+      break;
+    default:
+      assert false;
+      scratchField = null;
+    }
     for (int i = 0; i < docCount; i++) {
       if (liveDocs == null || liveDocs.get(i)) {
-        mergeDoc(docID++, i);
+        mergeDoc(scratchField, source, docID++, i);
       }
     }
   }
 
   /**
-   * Records the specified <tt>long</tt> value for the docID or throws an
-   * {@link UnsupportedOperationException} if this {@link Writer} doesn't record
-   * <tt>long</tt> values.
-   * 
-   * @throws UnsupportedOperationException
-   *           if this writer doesn't record <tt>long</tt> values
-   */
-  protected void add(int docID, long value) throws IOException {
-    throw new UnsupportedOperationException("override this method to support integer types");
-  }
-
-  /**
-   * Records the specified <tt>double</tt> value for the docID or throws an
-   * {@link UnsupportedOperationException} if this {@link Writer} doesn't record
-   * <tt>double</tt> values.
-   * 
-   * @throws UnsupportedOperationException
-   *           if this writer doesn't record <tt>double</tt> values
-   */
-  protected void add(int docID, double value) throws IOException {
-    throw new UnsupportedOperationException("override this method to support floating point types");
-  }
-
-  /**
-   * Records the specified {@link BytesRef} value for the docID or throws an
-   * {@link UnsupportedOperationException} if this {@link Writer} doesn't record
-   * {@link BytesRef} values.
-   * 
-   * @throws UnsupportedOperationException
-   *           if this writer doesn't record {@link BytesRef} values
-   */
-  protected void add(int docID, BytesRef value) throws IOException {
-    throw new UnsupportedOperationException("override this method to support byte types");
-  }
-
-  /**
    * Merges a document with the given <code>docID</code>. The methods
    * implementation obtains the value for the <i>sourceDoc</i> id from the
-   * current {@link Source} set to <i>setNextMergeSource(Source)</i>.
+   * current {@link Source}.
    * <p>
    * This method is used during merging to provide implementation agnostic
    * default merge implementation.
@@ -177,67 +169,29 @@ public abstract class DocValuesConsumer 
    * ID must always be greater than the previous ID or <tt>0</tt> if called the
    * first time.
    */
-  protected void mergeDoc(int docID, int sourceDoc)
+  protected void mergeDoc(Field scratchField, Source source, int docID, int sourceDoc)
       throws IOException {
-    switch(currentMergeSource.type()) {
+    switch(source.type()) {
     case BYTES_FIXED_DEREF:
     case BYTES_FIXED_SORTED:
     case BYTES_FIXED_STRAIGHT:
     case BYTES_VAR_DEREF:
     case BYTES_VAR_SORTED:
     case BYTES_VAR_STRAIGHT:
-      add(docID, currentMergeSource.getBytes(sourceDoc, spare));
+      scratchField.setValue(source.getBytes(sourceDoc, spare));
       break;
     case FIXED_INTS_16:
     case FIXED_INTS_32:
     case FIXED_INTS_64:
     case FIXED_INTS_8:
     case VAR_INTS:
-      add(docID, currentMergeSource.getInt(sourceDoc));
+      scratchField.setValue(source.getInt(sourceDoc));
       break;
     case FLOAT_32:
     case FLOAT_64:
-      add(docID, currentMergeSource.getFloat(sourceDoc));
+      scratchField.setValue(source.getFloat(sourceDoc));
       break;
     }
-  }
-  
-  /**
-   * Sets the next {@link Source} to consume values from on calls to
-   * {@link #mergeDoc(int, int)}
-   * 
-   * @param mergeSource
-   *          the next {@link Source}, this must not be null
-   */
-  protected final void setNextMergeSource(Source mergeSource) {
-    currentMergeSource = mergeSource;
-  }
-
-  /**
-   * Specialized auxiliary MergeState is necessary since we don't want to
-   * exploit internals up to the codecs consumer. An instance of this class is
-   * created for each merged low level {@link IndexReader} we are merging to
-   * support low level bulk copies.
-   */
-  public static class SingleSubMergeState {
-    /**
-     * the source reader for this MergeState - merged values should be read from
-     * this instance
-     */
-    public final DocValues reader;
-    /** the absolute docBase for this MergeState within the resulting segment */
-    public final int docBase;
-    /** the number of documents in this MergeState */
-    public final int docCount;
-    /** the not deleted bits for this MergeState */
-    public final Bits liveDocs;
-
-    public SingleSubMergeState(DocValues reader, int docBase, int docCount, Bits liveDocs) {
-      assert reader != null;
-      this.reader = reader;
-      this.docBase = docBase;
-      this.docCount = docCount;
-      this.liveDocs = liveDocs;
-    }
+    add(docID, scratchField);
   }
 }

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java Sun Jan 15 23:05:13 2012
@@ -85,7 +85,6 @@ public final class Lucene40StoredFieldsR
     } finally {
       idxStream.close();
     }
-  
   }
   
   // Used only by clone

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java Sun Jan 15 23:05:13 2012
@@ -25,9 +25,9 @@ import org.apache.lucene.index.CorruptIn
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.IndexFileNames;
 import org.apache.lucene.index.IndexableField;
+import org.apache.lucene.index.MergePolicy.MergeAbortedException;
 import org.apache.lucene.index.MergeState;
 import org.apache.lucene.index.SegmentReader;
-import org.apache.lucene.index.MergePolicy.MergeAbortedException;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
@@ -50,11 +50,11 @@ public final class Lucene40StoredFieldsW
   static final int FIELD_IS_NUMERIC_LONG = 2 << _NUMERIC_BIT_SHIFT;
   static final int FIELD_IS_NUMERIC_FLOAT = 3 << _NUMERIC_BIT_SHIFT;
   static final int FIELD_IS_NUMERIC_DOUBLE = 4 << _NUMERIC_BIT_SHIFT;
+
+  // the next possible bits are: 1 << 6; 1 << 7
   // currently unused: static final int FIELD_IS_NUMERIC_SHORT = 5 << _NUMERIC_BIT_SHIFT;
   // currently unused: static final int FIELD_IS_NUMERIC_BYTE = 6 << _NUMERIC_BIT_SHIFT;
 
-  // the next possible bits are: 1 << 6; 1 << 7
-  
   // Lucene 3.0: Removal of compressed fields
   static final int FORMAT_LUCENE_3_0_NO_COMPRESSED_FIELDS = 2;
 
@@ -127,7 +127,7 @@ public final class Lucene40StoredFieldsW
         IndexFileNames.segmentFileName(segment, "", FIELDS_INDEX_EXTENSION));
   }
 
-  public final void writeField(FieldInfo info, IndexableField field) throws IOException {
+  public void writeField(FieldInfo info, IndexableField field) throws IOException {
     fieldsStream.writeVInt(info.number);
     int bits = 0;
     final BytesRef bytes;
@@ -136,18 +136,19 @@ public final class Lucene40StoredFieldsW
     // this way we don't bake into indexer all these
     // specific encodings for different fields?  and apps
     // can customize...
-    if (field.numeric()) {
-      switch (field.numericDataType()) {
-        case INT:
-          bits |= FIELD_IS_NUMERIC_INT; break;
-        case LONG:
-          bits |= FIELD_IS_NUMERIC_LONG; break;
-        case FLOAT:
-          bits |= FIELD_IS_NUMERIC_FLOAT; break;
-        case DOUBLE:
-          bits |= FIELD_IS_NUMERIC_DOUBLE; break;
-        default:
-          assert false : "Should never get here";
+
+    Number number = field.numericValue();
+    if (number != null) {
+      if (number instanceof Byte || number instanceof Short || number instanceof Integer) {
+        bits |= FIELD_IS_NUMERIC_INT;
+      } else if (number instanceof Long) {
+        bits |= FIELD_IS_NUMERIC_LONG;
+      } else if (number instanceof Float) {
+        bits |= FIELD_IS_NUMERIC_FLOAT;
+      } else if (number instanceof Double) {
+        bits |= FIELD_IS_NUMERIC_DOUBLE;
+      } else {
+        throw new IllegalArgumentException("cannot store numeric type " + number.getClass());
       }
       string = null;
       bytes = null;
@@ -158,6 +159,9 @@ public final class Lucene40StoredFieldsW
         string = null;
       } else {
         string = field.stringValue();
+        if (string == null) {
+          throw new IllegalArgumentException("field " + field.name() + " is stored but does not have binaryValue, stringValue nor numericValue");
+        }
       }
     }
 
@@ -169,21 +173,16 @@ public final class Lucene40StoredFieldsW
     } else if (string != null) {
       fieldsStream.writeString(field.stringValue());
     } else {
-      final Number n = field.numericValue();
-      if (n == null) {
-        throw new IllegalArgumentException("field " + field.name() + " is stored but does not have binaryValue, stringValue nor numericValue");
-      }
-      switch (field.numericDataType()) {
-        case INT:
-          fieldsStream.writeInt(n.intValue()); break;
-        case LONG:
-          fieldsStream.writeLong(n.longValue()); break;
-        case FLOAT:
-          fieldsStream.writeInt(Float.floatToIntBits(n.floatValue())); break;
-        case DOUBLE:
-          fieldsStream.writeLong(Double.doubleToLongBits(n.doubleValue())); break;
-        default:
-          assert false : "Should never get here";
+      if (number instanceof Byte || number instanceof Short || number instanceof Integer) {
+        fieldsStream.writeInt(number.intValue());
+      } else if (number instanceof Long) {
+        fieldsStream.writeLong(number.longValue());
+      } else if (number instanceof Float) {
+        fieldsStream.writeInt(Float.floatToIntBits(number.floatValue()));
+      } else if (number instanceof Double) {
+        fieldsStream.writeLong(Double.doubleToLongBits(number.doubleValue()));
+      } else {
+        assert false;
       }
     }
   }
@@ -193,7 +192,7 @@ public final class Lucene40StoredFieldsW
    *  document.  The stream IndexInput is the
    *  fieldsStream from which we should bulk-copy all
    *  bytes. */
-  public final void addRawDocuments(IndexInput stream, int[] lengths, int numDocs) throws IOException {
+  public void addRawDocuments(IndexInput stream, int[] lengths, int numDocs) throws IOException {
     long position = fieldsStream.getFilePointer();
     long start = position;
     for(int i=0;i<numDocs;i++) {

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java Sun Jan 15 23:05:13 2012
@@ -23,12 +23,13 @@ import java.util.Comparator;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.DocValue;
+import org.apache.lucene.document.Field;
 import org.apache.lucene.index.DocValues.SortedSource;
 import org.apache.lucene.index.DocValues.Source;
 import org.apache.lucene.index.DocValues.Type;
+import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.IndexFileNames;
+import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.store.DataOutput;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
@@ -295,7 +296,6 @@ public final class Bytes {
      * Must be called only with increasing docIDs. It's OK for some docIDs to be
      * skipped; they will be filled with 0 bytes.
      */
-    @Override
     protected
     abstract void add(int docID, BytesRef bytes) throws IOException;
 
@@ -303,16 +303,13 @@ public final class Bytes {
     public abstract void finish(int docCount) throws IOException;
 
     @Override
-    protected void mergeDoc(int docID, int sourceDoc) throws IOException {
-      add(docID, currentMergeSource.getBytes(sourceDoc, bytesRef));
+    protected void mergeDoc(Field scratchField, Source source, int docID, int sourceDoc) throws IOException {
+      add(docID, source.getBytes(sourceDoc, bytesRef));
     }
 
     @Override
-    public void add(int docID, DocValue docValue) throws IOException {
-      final BytesRef ref;
-      if ((ref = docValue.getBytes()) != null) {
-        add(docID, ref);
-      }
+    public void add(int docID, IndexableField docValue) throws IOException {
+      add(docID, docValue.binaryValue());
     }
   }
 

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/FixedStraightBytesImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/FixedStraightBytesImpl.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/FixedStraightBytesImpl.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/FixedStraightBytesImpl.java Sun Jan 15 23:05:13 2012
@@ -17,27 +17,29 @@ package org.apache.lucene.codecs.lucene4
  * limitations under the License.
  */
 
-import static org.apache.lucene.util.ByteBlockPool.BYTE_BLOCK_SIZE;
-
 import java.io.IOException;
 
 import org.apache.lucene.codecs.lucene40.values.Bytes.BytesReaderBase;
 import org.apache.lucene.codecs.lucene40.values.Bytes.BytesSourceBase;
 import org.apache.lucene.codecs.lucene40.values.Bytes.BytesWriterBase;
-import org.apache.lucene.index.DocValues;
+import org.apache.lucene.document.Field;
 import org.apache.lucene.index.DocValues.Source;
 import org.apache.lucene.index.DocValues.Type;
+import org.apache.lucene.index.DocValues;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.ByteBlockPool;
+import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.ByteBlockPool.DirectTrackingAllocator;
+import org.apache.lucene.util.ByteBlockPool;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.Counter;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.PagedBytes;
 
+import static org.apache.lucene.util.ByteBlockPool.BYTE_BLOCK_SIZE;
+
 // Simplest storage: stores fixed length byte[] per
 // document, with no dedup and no sorting.
 /**
@@ -69,12 +71,11 @@ class FixedStraightBytesImpl {
 
       if (size == -1) {
         if (bytes.length > BYTE_BLOCK_SIZE) {
-          throw new IllegalArgumentException("bytes arrays > " + Short.MAX_VALUE + " are not supported");
+          throw new IllegalArgumentException("bytes arrays > " + BYTE_BLOCK_SIZE + " are not supported");
         }
         size = bytes.length;
       } else if (bytes.length != size) {
-        throw new IllegalArgumentException("expected bytes size=" + size
-            + " but got " + bytes.length);
+        throw new IllegalArgumentException("byte[] length changed for BYTES_FIXED_STRAIGHT type (before=" + size + " now=" + bytes.length);
       }
       if (lastDocID+1 < docID) {
         advancePool(docID);
@@ -134,7 +135,7 @@ class FixedStraightBytesImpl {
 
 
     @Override
-    protected void merge(SingleSubMergeState state) throws IOException {
+    protected void merge(DocValues readerIn, int docBase, int docCount, Bits liveDocs) throws IOException {
       datOut = getOrCreateDataOut();
       boolean success = false;
       try {
@@ -142,8 +143,8 @@ class FixedStraightBytesImpl {
           datOut.writeInt(size);
         }
 
-        if (state.liveDocs == null && tryBulkMerge(state.reader)) {
-          FixedStraightReader reader = (FixedStraightReader) state.reader;
+        if (liveDocs == null && tryBulkMerge(readerIn)) {
+          FixedStraightReader reader = (FixedStraightReader) readerIn;
           final int maxDocs = reader.maxDoc;
           if (maxDocs == 0) {
             return;
@@ -155,9 +156,9 @@ class FixedStraightBytesImpl {
             throw new IllegalArgumentException("expected bytes size=" + size
                 + " but got " + reader.size);
            }
-          if (lastDocID+1 < state.docBase) {
-            fill(datOut, state.docBase);
-            lastDocID = state.docBase-1;
+          if (lastDocID+1 < docBase) {
+            fill(datOut, docBase);
+            lastDocID = docBase-1;
           }
           // TODO should we add a transfer to API to each reader?
           final IndexInput cloneData = reader.cloneData();
@@ -169,7 +170,7 @@ class FixedStraightBytesImpl {
         
           lastDocID += maxDocs;
         } else {
-          super.merge(state);
+          super.merge(readerIn, docBase, docCount, liveDocs);
         }
         success = true;
       } finally {
@@ -185,9 +186,9 @@ class FixedStraightBytesImpl {
     }
     
     @Override
-    protected void mergeDoc(int docID, int sourceDoc) throws IOException {
+    protected void mergeDoc(Field scratchField, Source source, int docID, int sourceDoc) throws IOException {
       assert lastDocID < docID;
-      setMergeBytes(sourceDoc);
+      setMergeBytes(source, sourceDoc);
       if (size == -1) {
         size = bytesRef.length;
         datOut.writeInt(size);
@@ -200,12 +201,10 @@ class FixedStraightBytesImpl {
       lastDocID = docID;
     }
     
-    protected void setMergeBytes(int sourceDoc) {
-      currentMergeSource.getBytes(sourceDoc, bytesRef);
+    protected void setMergeBytes(Source source, int sourceDoc) {
+      source.getBytes(sourceDoc, bytesRef);
     }
 
-
-
     // Fills up to but not including this docID
     private void fill(IndexOutput datOut, int docID) throws IOException {
       assert size >= 0;

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java Sun Jan 15 23:05:13 2012
@@ -19,10 +19,10 @@ package org.apache.lucene.codecs.lucene4
 import java.io.IOException;
 
 import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.DocValue;
 import org.apache.lucene.index.DocValues.Source;
 import org.apache.lucene.index.DocValues.Type;
+import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
@@ -86,8 +86,8 @@ public class Floats {
     }
     
     @Override
-    public void add(int docID, DocValue docValue) throws IOException {
-      add(docID, docValue.getFloat());
+    public void add(int docID, IndexableField docValue) throws IOException {
+      add(docID, docValue.numericValue().doubleValue());
     }
     
     @Override
@@ -97,8 +97,8 @@ public class Floats {
     }
     
     @Override
-    protected void setMergeBytes(int sourceDoc) {
-      final double value = currentMergeSource.getFloat(sourceDoc);
+    protected void setMergeBytes(Source source, int sourceDoc) {
+      final double value = source.getFloat(sourceDoc);
       template.toBytes(value, bytesRef);
     }
   }

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java Sun Jan 15 23:05:13 2012
@@ -20,9 +20,10 @@ package org.apache.lucene.codecs.lucene4
 import java.io.IOException;
 
 import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.DocValues.Source;
 import org.apache.lucene.index.DocValues.Type;
-import org.apache.lucene.index.DocValue;
+import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
@@ -103,20 +104,19 @@ public final class Ints {
       template = DocValuesArray.TEMPLATES.get(valueType);
     }
     
-    @Override
     protected void add(int docID, long v) throws IOException {
       template.toBytes(v, bytesRef);
       add(docID, bytesRef);
     }
 
     @Override
-    public void add(int docID, DocValue docValue) throws IOException {
-      add(docID, docValue.getInt());
+    public void add(int docID, IndexableField docValue) throws IOException {
+      add(docID, docValue.numericValue().longValue());
     }
     
     @Override
-    protected void setMergeBytes(int sourceDoc) {
-      final long value = currentMergeSource.getInt(sourceDoc);
+    protected void setMergeBytes(Source source, int sourceDoc) {
+      final long value = source.getInt(sourceDoc);
       template.toBytes(value, bytesRef);
     }
     

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java Sun Jan 15 23:05:13 2012
@@ -20,11 +20,12 @@ import java.io.IOException;
 
 import org.apache.lucene.codecs.lucene40.values.DocValuesArray.LongValues;
 import org.apache.lucene.codecs.lucene40.values.FixedStraightBytesImpl.FixedBytesWriterBase;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.DocValue;
+import org.apache.lucene.document.Field;
 import org.apache.lucene.index.DocValues.Source;
 import org.apache.lucene.index.DocValues.Type;
+import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.IndexFileNames;
+import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
@@ -62,7 +63,6 @@ class PackedIntValues {
       bytesRef = new BytesRef(8);
     }
 
-    @Override
     protected void add(int docID, long v) throws IOException {
       assert lastDocId < docID;
       if (!started) {
@@ -113,10 +113,10 @@ class PackedIntValues {
     }
 
     @Override
-    protected void mergeDoc(int docID, int sourceDoc) throws IOException {
+    protected void mergeDoc(Field scratchField, Source source, int docID, int sourceDoc) throws IOException {
       assert docID > lastDocId : "docID: " + docID
           + " must be greater than the last added doc id: " + lastDocId;
-        add(docID, currentMergeSource.getInt(sourceDoc));
+        add(docID, source.getInt(sourceDoc));
     }
 
     private void writePackedInts(IndexOutput datOut, int docCount) throws IOException {
@@ -151,8 +151,8 @@ class PackedIntValues {
     }
 
     @Override
-    public void add(int docID, DocValue docValue) throws IOException {
-      add(docID, docValue.getInt());
+    public void add(int docID, IndexableField docValue) throws IOException {
+      add(docID, docValue.numericValue().longValue());
     }
   }
 

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java Sun Jan 15 23:05:13 2012
@@ -22,21 +22,25 @@ import java.io.IOException;
 import org.apache.lucene.codecs.lucene40.values.Bytes.BytesReaderBase;
 import org.apache.lucene.codecs.lucene40.values.Bytes.BytesSourceBase;
 import org.apache.lucene.codecs.lucene40.values.Bytes.BytesWriterBase;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.DocValues.Source;
 import org.apache.lucene.index.DocValues.Type;
+import org.apache.lucene.index.DocValues;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.ByteBlockPool.DirectTrackingAllocator;
 import org.apache.lucene.util.ByteBlockPool;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.Counter;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.PagedBytes;
 import org.apache.lucene.util.RamUsageEstimator;
-import org.apache.lucene.util.ByteBlockPool.DirectTrackingAllocator;
-import org.apache.lucene.util.packed.PackedInts;
 import org.apache.lucene.util.packed.PackedInts.ReaderIterator;
+import org.apache.lucene.util.packed.PackedInts;
 
 // Variable length byte[] per document, no sharing
 
@@ -93,21 +97,21 @@ class VarStraightBytesImpl {
     }
     
     @Override
-    protected void merge(SingleSubMergeState state) throws IOException {
+    protected void merge(DocValues readerIn, int docBase, int docCount, Bits liveDocs) throws IOException {
       merge = true;
       datOut = getOrCreateDataOut();
       boolean success = false;
       try {
-        if (state.liveDocs == null && state.reader instanceof VarStraightReader) {
+        if (liveDocs == null && readerIn instanceof VarStraightReader) {
           // bulk merge since we don't have any deletes
-          VarStraightReader reader = (VarStraightReader) state.reader;
+          VarStraightReader reader = (VarStraightReader) readerIn;
           final int maxDocs = reader.maxDoc;
           if (maxDocs == 0) {
             return;
           }
-          if (lastDocID+1 < state.docBase) {
-            fill(state.docBase, address);
-            lastDocID = state.docBase-1;
+          if (lastDocID+1 < docBase) {
+            fill(docBase, address);
+            lastDocID = docBase-1;
           }
           final long numDataBytes;
           final IndexInput cloneIdx = reader.cloneIndex();
@@ -137,7 +141,7 @@ class VarStraightBytesImpl {
             IOUtils.close(cloneData);  
           }
         } else {
-          super.merge(state);
+          super.merge(readerIn, docBase, docCount, liveDocs);
         }
         success = true;
       } finally {
@@ -148,10 +152,10 @@ class VarStraightBytesImpl {
     }
     
     @Override
-    protected void mergeDoc(int docID, int sourceDoc) throws IOException {
+    protected void mergeDoc(Field scratchField, Source source, int docID, int sourceDoc) throws IOException {
       assert merge;
       assert lastDocID < docID;
-      currentMergeSource.getBytes(sourceDoc, bytesRef);
+      source.getBytes(sourceDoc, bytesRef);
       if (bytesRef.length == 0) {
         return; // default
       }
@@ -226,7 +230,7 @@ class VarStraightBytesImpl {
   }
 
   public static class VarStraightReader extends BytesReaderBase {
-    private final int maxDoc;
+    final int maxDoc;
 
     VarStraightReader(Directory dir, String id, int maxDoc, IOContext context) throws IOException {
       super(dir, id, CODEC_NAME, VERSION_START, true, context, Type.BYTES_VAR_STRAIGHT);

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java Sun Jan 15 23:05:13 2012
@@ -23,13 +23,13 @@ import java.util.Set;
 
 import org.apache.lucene.codecs.DocValuesConsumer;
 import org.apache.lucene.codecs.PerDocConsumer;
-import org.apache.lucene.index.DocValue;
 import org.apache.lucene.index.DocValues.Type;
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.FieldInfos;
 import org.apache.lucene.index.IndexFileNames;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.index.SegmentInfo;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
@@ -130,8 +130,8 @@ public class SimpleTextNormsConsumer ext
     }
 
     @Override
-    public void add(int docID, DocValue docValue) throws IOException {
-      add(docID, docValue.getBytes());
+    public void add(int docID, IndexableField docValue) throws IOException {
+      add(docID, docValue.binaryValue());
     }
     
     protected void add(int docID, BytesRef value) throws IOException {

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsWriter.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsWriter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsWriter.java Sun Jan 15 23:05:13 2012
@@ -98,46 +98,39 @@ public class SimpleTextStoredFieldsWrite
     newLine();
     
     write(TYPE);
-    if (field.numeric()) {
-      switch (field.numericDataType()) {
-        case INT:
-          write(TYPE_INT);
-          newLine();
-          
-          write(VALUE);
-          write(Integer.toString(field.numericValue().intValue()));
-          newLine();
-          
-          break;
-        case LONG:
-          write(TYPE_LONG);
-          newLine();
-          
-          write(VALUE);
-          write(Long.toString(field.numericValue().longValue()));
-          newLine();
-          
-          break;
-        case FLOAT:
-          write(TYPE_FLOAT);
-          newLine();
-          
-          write(VALUE);
-          write(Float.toString(field.numericValue().floatValue()));
-          newLine();
+    final Number n = field.numericValue();
+
+    if (n != null) {
+      if (n instanceof Byte || n instanceof Short || n instanceof Integer) {
+        write(TYPE_INT);
+        newLine();
           
-          break;
-        case DOUBLE:
-          write(TYPE_DOUBLE);
-          newLine();
+        write(VALUE);
+        write(Integer.toString(n.intValue()));
+        newLine();
+      } else if (n instanceof Long) {
+        write(TYPE_LONG);
+        newLine();
+
+        write(VALUE);
+        write(Long.toString(n.longValue()));
+        newLine();
+      } else if (n instanceof Float) {
+        write(TYPE_FLOAT);
+        newLine();
           
-          write(VALUE);
-          write(Double.toString(field.numericValue().doubleValue()));
-          newLine();
+        write(VALUE);
+        write(Float.toString(n.floatValue()));
+        newLine();
+      } else if (n instanceof Double) {
+        write(TYPE_DOUBLE);
+        newLine();
           
-          break;
-        default:
-          assert false : "Should never get here";
+        write(VALUE);
+        write(Double.toString(n.doubleValue()));
+        newLine();
+      } else {
+        throw new IllegalArgumentException("cannot store numeric type " + n.getClass());
       }
     } else { 
       BytesRef bytes = field.binaryValue();

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/DocValuesField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/DocValuesField.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/DocValuesField.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/DocValuesField.java Sun Jan 15 23:05:13 2012
@@ -16,13 +16,14 @@ package org.apache.lucene.document;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import java.io.Reader;
+
 import java.util.Comparator;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
 
-import org.apache.lucene.index.IndexableFieldType;
-import org.apache.lucene.index.DocValue;
-import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.DocValues.Type; // javadocs
+import org.apache.lucene.index.DocValues;
 import org.apache.lucene.util.BytesRef;
 
 /**
@@ -32,14 +33,16 @@ import org.apache.lucene.util.BytesRef;
  * example usage, adding an int value:
  * 
  * <pre>
- * document.add(new DocValuesField(name).setInt(value));
+ * DocValuesField field = new DocValuesField(name, DocValues.Type.VAR_INTS);
+ * field.setInt(value);
+ * document.add(field);
  * </pre>
  * 
  * For optimal performance, re-use the <code>DocValuesField</code> and
  * {@link Document} instance for more than one document:
  * 
  * <pre>
- *  DocValuesField field = new DocValuesField(name);
+ *  DocValuesField field = new DocValuesField(name, DocValues.Type.VAR_INTS);
  *  Document document = new Document();
  *  document.add(field);
  * 
@@ -69,326 +72,79 @@ import org.apache.lucene.util.BytesRef;
  * </pre>
  * 
  * */
-public class DocValuesField extends Field implements DocValue {
-
-  protected BytesRef bytes;
-  protected double doubleValue;
-  protected long longValue;
-  protected DocValues.Type type;
-  protected Comparator<BytesRef> bytesComparator;
-
-  /**
-   * Creates a new {@link DocValuesField} with the given name.
-   */
-  public DocValuesField(String name) {
-    this(name, new FieldType());
-  }
-
-  public DocValuesField(String name, IndexableFieldType type) {
-    this(name, type, null);
-  }
 
-  public DocValuesField(String name, IndexableFieldType type, String value) {
-    super(name, type);
-    fieldsData = value;
-  }
+public class DocValuesField extends Field {
 
-  @Override
-  public DocValue docValue() {
-    return this;
-  }
+  protected Comparator<BytesRef> bytesComparator;
 
-  /**
-   * Sets the given <code>long</code> value and sets the field's {@link Type} to
-   * {@link Type#VAR_INTS} unless already set. If you want to change the
-   * default type use {@link #setDocValuesType(DocValues.Type)}.
-   */
-  public void setInt(long value) {
-    setInt(value, false);
-  }
-  
-  /**
-   * Sets the given <code>long</code> value as a 64 bit signed integer.
-   * 
-   * @param value
-   *          the value to set
-   * @param fixed
-   *          if <code>true</code> {@link Type#FIXED_INTS_64} is used
-   *          otherwise {@link Type#VAR_INTS}
-   */
-  public void setInt(long value, boolean fixed) {
-    if (type == null) {
-      type = fixed ? DocValues.Type.FIXED_INTS_64 : DocValues.Type.VAR_INTS;
+  private static final Map<DocValues.Type,FieldType> types = new HashMap<DocValues.Type,FieldType>();
+  static {
+    for(DocValues.Type type : DocValues.Type.values()) {
+      final FieldType ft = new FieldType();
+      ft.setDocValueType(type);
+      ft.freeze();
+      types.put(type, ft);
     }
-    longValue = value;
   }
 
-  /**
-   * Sets the given <code>int</code> value and sets the field's {@link Type} to
-   * {@link Type#VAR_INTS} unless already set. If you want to change the
-   * default type use {@link #setDocValuesType(DocValues.Type)}.
-   */
-  public void setInt(int value) {
-    setInt(value, false);
-  }
+  private static EnumSet<Type> BYTES = EnumSet.of(
+                     Type.BYTES_FIXED_DEREF,
+                     Type.BYTES_FIXED_STRAIGHT,
+                     Type.BYTES_VAR_DEREF,
+                     Type.BYTES_VAR_STRAIGHT,
+                     Type.BYTES_FIXED_SORTED,
+                     Type.BYTES_VAR_SORTED);
 
-  /**
-   * Sets the given <code>int</code> value as a 32 bit signed integer.
-   * 
-   * @param value
-   *          the value to set
-   * @param fixed
-   *          if <code>true</code> {@link Type#FIXED_INTS_32} is used
-   *          otherwise {@link Type#VAR_INTS}
-   */
-  public void setInt(int value, boolean fixed) {
-    if (type == null) {
-      type = fixed ? DocValues.Type.FIXED_INTS_32 : DocValues.Type.VAR_INTS;
-    }
-    longValue = value;
-  }
+  private static EnumSet<Type> INTS = EnumSet.of(
+                     Type.VAR_INTS,
+                     Type.FIXED_INTS_8,
+                     Type.FIXED_INTS_16,
+                     Type.FIXED_INTS_32,
+                     Type.FIXED_INTS_64);
 
-  /**
-   * Sets the given <code>short</code> value and sets the field's {@link Type} to
-   * {@link Type#VAR_INTS} unless already set. If you want to change the
-   * default type use {@link #setDocValuesType(DocValues.Type)}.
-   */
-  public void setInt(short value) {
-    setInt(value, false);
+  public static FieldType getFieldType(DocValues.Type type) {
+    return types.get(type);
   }
 
-  /**
-   * Sets the given <code>short</code> value as a 16 bit signed integer.
-   * 
-   * @param value
-   *          the value to set
-   * @param fixed
-   *          if <code>true</code> {@link Type#FIXED_INTS_16} is used
-   *          otherwise {@link Type#VAR_INTS}
-   */
-  public void setInt(short value, boolean fixed) {
-    if (type == null) {
-      type = fixed ? DocValues.Type.FIXED_INTS_16 : DocValues.Type.VAR_INTS;
+  public DocValuesField(String name, BytesRef bytes, DocValues.Type docValueType) {
+    super(name, getFieldType(docValueType));
+    if (!BYTES.contains(docValueType)) {
+      throw new IllegalArgumentException("docValueType must be one of: " + BYTES + "; got " + docValueType);
     }
-    longValue = value;
-  }
-
-  /**
-   * Sets the given <code>byte</code> value and sets the field's {@link Type} to
-   * {@link Type#VAR_INTS} unless already set. If you want to change the
-   * default type use {@link #setDocValuesType(DocValues.Type)}.
-   */
-  public void setInt(byte value) {
-    setInt(value, false);
+    fieldsData = bytes;
   }
 
-  /**
-   * Sets the given <code>byte</code> value as a 8 bit signed integer.
-   * 
-   * @param value
-   *          the value to set
-   * @param fixed
-   *          if <code>true</code> {@link Type#FIXED_INTS_8} is used
-   *          otherwise {@link Type#VAR_INTS}
-   */
-  public void setInt(byte value, boolean fixed) {
-    if (type == null) {
-      type = fixed ? DocValues.Type.FIXED_INTS_8 : DocValues.Type.VAR_INTS;
+  public DocValuesField(String name, int value, DocValues.Type docValueType) {
+    super(name, getFieldType(docValueType));
+    if (!INTS.contains(docValueType)) {
+      throw new IllegalArgumentException("docValueType must be one of: " + INTS +"; got " + docValueType);
     }
-    longValue = value;
+    fieldsData = Integer.valueOf(value);
   }
 
-  /**
-   * Sets the given <code>float</code> value and sets the field's {@link Type}
-   * to {@link Type#FLOAT_32} unless already set. If you want to
-   * change the type use {@link #setDocValuesType(DocValues.Type)}.
-   */
-  public void setFloat(float value) {
-    if (type == null) {
-      type = DocValues.Type.FLOAT_32;
+  public DocValuesField(String name, long value, DocValues.Type docValueType) {
+    super(name, getFieldType(docValueType));
+    if (!INTS.contains(docValueType)) {
+      throw new IllegalArgumentException("docValueType must be one of: " + INTS +"; got " + docValueType);
     }
-    doubleValue = value;
+    fieldsData = Long.valueOf(value);
   }
 
-  /**
-   * Sets the given <code>double</code> value and sets the field's {@link Type}
-   * to {@link Type#FLOAT_64} unless already set. If you want to
-   * change the default type use {@link #setDocValuesType(DocValues.Type)}.
-   */
-  public void setFloat(double value) {
-    if (type == null) {
-      type = DocValues.Type.FLOAT_64;
+  public DocValuesField(String name, float value, DocValues.Type docValueType) {
+    super(name, getFieldType(docValueType));
+    if (docValueType != DocValues.Type.FLOAT_32 &&
+        docValueType != DocValues.Type.FLOAT_64) {
+      throw new IllegalArgumentException("docValueType must be FLOAT_32/64; got " + docValueType);
     }
-    doubleValue = value;
+    fieldsData = Float.valueOf(value);
   }
 
-  /**
-   * Sets the given {@link BytesRef} value and the field's {@link Type}. The
-   * comparator for this field is set to <code>null</code>. If a
-   * <code>null</code> comparator is set the default comparator for the given
-   * {@link Type} is used.
-   */
-  public void setBytes(BytesRef value, DocValues.Type type) {
-    setBytes(value, type, null);
-  }
-
-  /**
-   * Sets the given {@link BytesRef} value, the field's {@link Type} and the
-   * field's comparator. If the {@link Comparator} is set to <code>null</code>
-   * the default for the given {@link Type} is used instead.
-   * 
-   * @throws IllegalArgumentException
-   *           if the value or the type are null
-   */
-  public void setBytes(BytesRef value, DocValues.Type type, Comparator<BytesRef> comp) {
-    if (value == null) {
-      throw new IllegalArgumentException("value must not be null");
-    }
-    setDocValuesType(type);
-    if (bytes == null) {
-      bytes = BytesRef.deepCopyOf(value);
-    } else {
-      bytes.copyBytes(value);
-    }
-    bytesComparator = comp;
-  }
-
-  /**
-   * Returns the set {@link BytesRef} or <code>null</code> if not set.
-   */
-  public BytesRef getBytes() {
-    return bytes;
-  }
-
-  /**
-   * Returns the set {@link BytesRef} comparator or <code>null</code> if not set
-   */
-  public Comparator<BytesRef> bytesComparator() {
-    return bytesComparator;
-  }
-
-  /**
-   * Returns the set floating point value or <code>0.0d</code> if not set.
-   */
-  public double getFloat() {
-    return doubleValue;
-  }
-
-  /**
-   * Returns the set <code>long</code> value of <code>0</code> if not set.
-   */
-  public long getInt() {
-    return longValue;
-  }
-
-  /**
-   * Sets the {@link BytesRef} comparator for this field. If the field has a
-   * numeric {@link Type} the comparator will be ignored.
-   */
-  public void setBytesComparator(Comparator<BytesRef> comp) {
-    this.bytesComparator = comp;
-  }
-
-  /**
-   * Sets the {@link Type} for this field.
-   */
-  public void setDocValuesType(DocValues.Type type) {
-    if (type == null) {
-      throw new IllegalArgumentException("Type must not be null");
-    }
-    this.type = type;
-  }
-
-  /**
-   * Returns always <code>null</code>
-   */
-  public Reader readerValue() {
-    return null;
-  }
-
-  @Override
-  public DocValues.Type docValueType() {
-    return type;
-  }
-
-  @Override
-  public String toString() {
-    final String value;
-    switch (type) {
-    case BYTES_FIXED_DEREF:
-    case BYTES_FIXED_STRAIGHT:
-    case BYTES_VAR_DEREF:
-    case BYTES_VAR_STRAIGHT:
-    case BYTES_FIXED_SORTED:
-    case BYTES_VAR_SORTED:
-      // don't use to unicode string this is not necessarily unicode here
-      value = "bytes: " + bytes.toString();
-      break;
-    case FIXED_INTS_16:
-      value = "int16: " + longValue;
-      break;
-    case FIXED_INTS_32:
-      value = "int32: " + longValue;
-      break;
-    case FIXED_INTS_64:
-      value = "int64: " + longValue;
-      break;
-    case FIXED_INTS_8:
-      value = "int8: " + longValue;
-      break;
-    case VAR_INTS:
-      value = "vint: " + longValue;
-      break;
-    case FLOAT_32:
-      value = "float32: " + doubleValue;
-      break;
-    case FLOAT_64:
-      value = "float64: " + doubleValue;
-      break;
-    default:
-      throw new IllegalArgumentException("unknown type: " + type);
-    }
-    return "<" + name() + ": DocValuesField " + value + ">";
-  }
-
-  /**
-   * Returns an DocValuesField holding the value from
-   * the provided string field, as the specified type.  The
-   * incoming field must have a string value.  The name, {@link
-   * FieldType} and string value are carried over from the
-   * incoming Field.
-   */
-  public static DocValuesField build(Field field, DocValues.Type type) {
-    if (field instanceof DocValuesField) {
-      return (DocValuesField) field;
-    }
-    final DocValuesField valField = new DocValuesField(field.name(), field.fieldType(), field.stringValue());
-    switch (type) {
-    case BYTES_FIXED_DEREF:
-    case BYTES_FIXED_STRAIGHT:
-    case BYTES_VAR_DEREF:
-    case BYTES_VAR_STRAIGHT:
-    case BYTES_FIXED_SORTED:
-    case BYTES_VAR_SORTED:
-      BytesRef ref = field.isBinary() ? field.binaryValue() : new BytesRef(field.stringValue());
-      valField.setBytes(ref, type);
-      break;
-    case FIXED_INTS_16:
-    case FIXED_INTS_32:
-    case FIXED_INTS_64:
-    case FIXED_INTS_8:
-    case VAR_INTS:
-      valField.setInt(Long.parseLong(field.stringValue()));
-      break;
-    case FLOAT_32:
-      valField.setFloat(Float.parseFloat(field.stringValue()));
-      break;
-    case FLOAT_64:
-      valField.setFloat(Double.parseDouble(field.stringValue()));
-      break;
-    default:
-      throw new IllegalArgumentException("unknown type: " + type);
+  public DocValuesField(String name, double value, DocValues.Type docValueType) {
+    super(name, getFieldType(docValueType));
+    if (docValueType != DocValues.Type.FLOAT_32 &&
+        docValueType != DocValues.Type.FLOAT_64) {
+      throw new IllegalArgumentException("docValueType must be FLOAT_32/64; got " + docValueType);
     }
-    return valField;
+    fieldsData = Double.valueOf(value);
   }
 }

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java?rev=1231791&r1=1231790&r2=1231791&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java Sun Jan 15 23:05:13 2012
@@ -57,7 +57,7 @@ public class DocumentStoredFieldVisitor 
 
   @Override
   public void binaryField(FieldInfo fieldInfo, byte[] value, int offset, int length) throws IOException {
-    doc.add(new BinaryField(fieldInfo.name, value));
+    doc.add(new StoredField(fieldInfo.name, value));
   }
 
   @Override
@@ -73,30 +73,22 @@ public class DocumentStoredFieldVisitor 
 
   @Override
   public void intField(FieldInfo fieldInfo, int value) {
-    FieldType ft = new FieldType(NumericField.TYPE_STORED);
-    ft.setIndexed(fieldInfo.isIndexed);
-    doc.add(new NumericField(fieldInfo.name, ft).setIntValue(value));
+    doc.add(new StoredField(fieldInfo.name, value));
   }
 
   @Override
   public void longField(FieldInfo fieldInfo, long value) {
-    FieldType ft = new FieldType(NumericField.TYPE_STORED);
-    ft.setIndexed(fieldInfo.isIndexed);
-    doc.add(new NumericField(fieldInfo.name, ft).setLongValue(value));
+    doc.add(new StoredField(fieldInfo.name, value));
   }
 
   @Override
   public void floatField(FieldInfo fieldInfo, float value) {
-    FieldType ft = new FieldType(NumericField.TYPE_STORED);
-    ft.setIndexed(fieldInfo.isIndexed);
-    doc.add(new NumericField(fieldInfo.name, ft).setFloatValue(value));
+    doc.add(new StoredField(fieldInfo.name, value));
   }
 
   @Override
   public void doubleField(FieldInfo fieldInfo, double value) {
-    FieldType ft = new FieldType(NumericField.TYPE_STORED);
-    ft.setIndexed(fieldInfo.isIndexed);
-    doc.add(new NumericField(fieldInfo.name, ft).setDoubleValue(value));
+    doc.add(new StoredField(fieldInfo.name, value));
   }
 
   @Override