Apache Lucene open-source search software
LUCENE-2186: made class and var naming consistent, added javadoc and specialized codec provider
Simon Willnauercf8ac7866a41
diff --git a/lucene/src/java/org/apache/lucene/document/DocValuesField.java b/lucene/src/java/org/apache/lucene/document/DocValuesField.javaindex 1f9295859d4..c5f13e17159 100644--- a/lucene/src/java/org/apache/lucene/document/DocValuesField.java+++ b/lucene/src/java/org/apache/lucene/document/DocValuesField.java@@ -99,36 +99,36 @@ public class DocValuesField extends AbstractField implements PerDocFieldValues {/*** Sets the given <code>long</code> value and sets the field's {@link Type} to- * {@link Type#PACKED_INTS} unless already set. If you want to change the+ * {@link Type#INTS} unless already set. If you want to change the* default type use {@link #setType(Type)}.*/public void setInt(long value) {if (type == null) {- type = Type.PACKED_INTS;+ type = Type.INTS;}longValue = value;}/*** Sets the given <code>float</code> value and sets the field's {@link Type}- * to {@link Type#SIMPLE_FLOAT_4BYTE} unless already set. If you want to+ * to {@link Type#FLOAT_32} unless already set. If you want to* change the type use {@link #setType(Type)}.*/public void setFloat(float value) {if (type == null) {- type = Type.SIMPLE_FLOAT_4BYTE;+ type = Type.FLOAT_32;}doubleValue = value;}/*** Sets the given <code>double</code> value and sets the field's {@link Type}- * to {@link Type#SIMPLE_FLOAT_8BYTE} unless already set. If you want to+ * to {@link Type#FLOAT_64} unless already set. If you want to* change the default type use {@link #setType(Type)}.*/public void setFloat(double value) {if (type == null) {- type = Type.SIMPLE_FLOAT_8BYTE;+ type = Type.FLOAT_64;}doubleValue = value;}@@ -269,13 +269,13 @@ public class DocValuesField extends AbstractField implements PerDocFieldValues {field.stringValue());valField.setBytes(ref, type);break;- case PACKED_INTS:+ case INTS:valField.setInt(Long.parseLong(field.stringValue()));break;- case SIMPLE_FLOAT_4BYTE:+ case FLOAT_32:valField.setFloat(Float.parseFloat(field.stringValue()));break;- case SIMPLE_FLOAT_8BYTE:+ case FLOAT_64:valField.setFloat(Double.parseDouble(field.stringValue()));break;default:diff --git a/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java b/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.javaindex bb7da337247..deba256feda 100644--- a/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java+++ b/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java@@ -54,7 +54,7 @@ final class DocFieldProcessor extends DocConsumer {fieldInfo.setDocValues(values.type());if(fieldsConsumer == null) {- /* nocommit -- this is a hack and only works since DocValuesCodec supports initializing the FieldsConsumer twice.+ /* TODO (close to no commit) -- this is a hack and only works since DocValuesCodec supports initializing the FieldsConsumer twice.* we need to find a way that allows us to obtain a FieldsConsumer per DocumentsWriter. Currently some codecs rely on* the SegmentsWriteState passed in right at the moment when the segment is flushed (doccount etc) but we need the consumer earlier* to support docvalues and later on stored fields too.@@ -64,7 +64,6 @@ final class DocFieldProcessor extends DocConsumer {}valuesConsumer = fieldsConsumer.addValuesField(fieldInfo);docValues.put(name, valuesConsumer);-}return valuesConsumer;diff --git a/lucene/src/java/org/apache/lucene/index/DocFieldProcessorPerThread.java b/lucene/src/java/org/apache/lucene/index/DocFieldProcessorPerThread.javaindex 90b96ca061a..86d8aafbd26 100644--- a/lucene/src/java/org/apache/lucene/index/DocFieldProcessorPerThread.java+++ b/lucene/src/java/org/apache/lucene/index/DocFieldProcessorPerThread.java@@ -23,7 +23,6 @@ import java.util.HashSet;import java.util.List;import java.io.IOException;-import org.apache.lucene.document.AbstractField;import org.apache.lucene.document.Document;import org.apache.lucene.document.Fieldable;import org.apache.lucene.index.codecs.docvalues.DocValuesConsumer;@@ -253,11 +252,7 @@ final class DocFieldProcessorPerThread extends DocConsumerPerThread {final DocFieldProcessorPerField perField = fields[i];final Fieldable fieldable = perField.fields[0];perField.consumer.processFields(perField.fields, perField.fieldCount);-- if (!(fieldable instanceof AbstractField)) {- continue;- }- final PerDocFieldValues docValues = ((AbstractField)fieldable).getDocValues();+ final PerDocFieldValues docValues = fieldable.getDocValues();if (docValues == null) {continue;}diff --git a/lucene/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/src/java/org/apache/lucene/index/FieldInfos.javaindex 70efdc407ba..47d21177f58 100644--- a/lucene/src/java/org/apache/lucene/index/FieldInfos.java+++ b/lucene/src/java/org/apache/lucene/index/FieldInfos.java@@ -326,13 +326,13 @@ public final class FieldInfos {b = 0;} else {switch(fi.docValues) {- case PACKED_INTS:+ case INTS:b = 1;break;- case SIMPLE_FLOAT_4BYTE:+ case FLOAT_32:b = 2;break;- case SIMPLE_FLOAT_8BYTE:+ case FLOAT_64:b = 3;break;case BYTES_FIXED_STRAIGHT:@@ -393,13 +393,13 @@ public final class FieldInfos {docValuesType = null;break;case 1:- docValuesType = Type.PACKED_INTS;+ docValuesType = Type.INTS;break;case 2:- docValuesType = Type.SIMPLE_FLOAT_4BYTE;+ docValuesType = Type.FLOAT_32;break;case 3:- docValuesType = Type.SIMPLE_FLOAT_8BYTE;+ docValuesType = Type.FLOAT_64;break;case 4:docValuesType = Type.BYTES_FIXED_STRAIGHT;diff --git a/lucene/src/java/org/apache/lucene/index/codecs/CodecProvider.java b/lucene/src/java/org/apache/lucene/index/codecs/CodecProvider.javaindex c249116eb09..31b0c230bc5 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/CodecProvider.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/CodecProvider.java@@ -22,6 +22,7 @@ import java.util.HashMap;import java.util.HashSet;import java.util.Map;import java.util.Set;+import java.util.Map.Entry;import org.apache.lucene.index.codecs.preflex.PreFlexCodec;import org.apache.lucene.index.codecs.pulsing.PulsingCodec;@@ -163,6 +164,26 @@ public class CodecProvider {public synchronized void setDefaultFieldCodec(String codec) {defaultFieldCodec = codec;}++ /**+ * Registers all codecs from the given provider including the field to codec+ * mapping and the default field codec.+ * <p>+ * NOTE: This method will pass any codec from the given codec to+ * {@link #register(Codec)} and sets fiels codecs via+ * {@link #setFieldCodec(String, String)}.+ */+ public void copyFrom(CodecProvider other) {+ final Collection<Codec> values = other.codecs.values();+ for (Codec codec : values) {+ register(codec);+ }+ final Set<Entry<String, String>> entrySet = other.perFieldMap.entrySet();+ for (Entry<String, String> entry : entrySet) {+ setFieldCodec(entry.getKey(), entry.getValue());+ }+ setDefaultFieldCodec(other.getDefaultFieldCodec());+ }}class DefaultCodecProvider extends CodecProvider {diff --git a/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesCodec.java b/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesCodec.javaindex abe247d4936..3fe8bfeda5b 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesCodec.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesCodec.java@@ -49,7 +49,7 @@ public class DocValuesCodec extends Codec {private final Comparator<BytesRef> comparator;public DocValuesCodec(Codec other, Comparator<BytesRef> comparator) {- this.name = "docvalues_" + other.name;+ this.name = other.name;this.other = other;this.comparator = comparator;}diff --git a/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesCodecProvider.java b/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesCodecProvider.javanew file mode 100644index 00000000000..ab54101f0fb--- /dev/null+++ b/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesCodecProvider.java@@ -0,0 +1,34 @@+package org.apache.lucene.index.codecs.docvalues;+/**+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+import org.apache.lucene.index.codecs.Codec;+import org.apache.lucene.index.codecs.CodecProvider;++/**+ * Simple Codec provider that wrapps all registered codecs into a {@link DocValuesCodec}+ */+public class DocValuesCodecProvider extends CodecProvider {++ @Override+ public synchronized void register(Codec codec) {+ if (codec instanceof DocValuesCodec) {+ super.register(codec);+ } else {+ super.register(new DocValuesCodec(codec));+ }+ }+}diff --git a/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesProducerBase.java b/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesProducerBase.javaindex b771a86ba65..914a7e3c738 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesProducerBase.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/docvalues/DocValuesProducerBase.java@@ -111,11 +111,11 @@ public abstract class DocValuesProducerBase extends FieldsProducer {protected DocValues loadDocValues(int docCount, Directory dir, String id,Type type) throws IOException {switch (type) {- case PACKED_INTS:+ case INTS:return Ints.getValues(dir, id, false);- case SIMPLE_FLOAT_4BYTE:+ case FLOAT_32:return Floats.getValues(dir, id, docCount);- case SIMPLE_FLOAT_8BYTE:+ case FLOAT_64:return Floats.getValues(dir, id, docCount);case BYTES_FIXED_STRAIGHT:return Bytes.getValues(dir, id, Bytes.Mode.STRAIGHT, true, docCount);diff --git a/lucene/src/java/org/apache/lucene/index/values/Bytes.java b/lucene/src/java/org/apache/lucene/index/values/Bytes.javaindex d3dedd406a2..a8a7c2d4d3d 100644--- a/lucene/src/java/org/apache/lucene/index/values/Bytes.java+++ b/lucene/src/java/org/apache/lucene/index/values/Bytes.java@@ -54,14 +54,16 @@ import org.apache.lucene.util.PagedBytes;* @lucene.experimental*/public final class Bytes {- //TODO - add bulk copy where possible- private Bytes() { /* don't instantiate! */ }+ // TODO - add bulk copy where possible+ private Bytes() { /* don't instantiate! */+ }/*** Defines the {@link Writer}s store mode. The writer will either store the* bytes sequentially ({@link #STRAIGHT}, dereferenced ({@link #DEREF}) or* sorted ({@link #SORTED})*+ * @lucene.experimental*/public static enum Mode {/**@@ -180,10 +182,10 @@ public final class Bytes {// TODO open up this API?static abstract class BytesBaseSource extends Source {+ private final PagedBytes pagedBytes;protected final IndexInput datIn;protected final IndexInput idxIn;protected final static int PAGED_BYTES_BITS = 15;- private final PagedBytes pagedBytes;protected final PagedBytes.Reader data;protected final long totalLengthInBytes;@@ -204,11 +206,13 @@ public final class Bytes {data.close(); // close data} finally {try {- if (datIn != null)+ if (datIn != null) {datIn.close();+ }} finally {- if (idxIn != null) // if straight - no index needed+ if (idxIn != null) {// if straight - no index neededidxIn.close();+ }}}}@@ -269,18 +273,27 @@ public final class Bytes {return ord == 0 ? null : deref(--ord, bytesRef);}- public void close() throws IOException {+ protected void closeIndexInput() throws IOException {try {- if (datIn != null)+ if (datIn != null) {datIn.close();+ }} finally {- if (idxIn != null) // if straight+ if (idxIn != null) {// if straightidxIn.close();+ }}}+ /**+ * Returns the largest doc id + 1 in this doc values source+ */protected abstract int maxDoc();+ /**+ * Copies the value for the given ord to the given {@link BytesRef} and+ * returns it.+ */protected abstract BytesRef deref(int ord, BytesRef bytesRef);protected LookupResult binarySearch(BytesRef b, BytesRef bytesRef, int low,@@ -328,7 +341,6 @@ public final class Bytes {// TODO: open up this API?!static abstract class BytesWriterBase extends Writer {-private final Directory dir;private final String id;protected IndexOutput idxOut;@@ -347,10 +359,13 @@ public final class Bytes {this.codecName = codecName;this.version = version;this.pool = pool;- if (initData)+ if (initData) {initDataOut();- if (initIndex)+ }++ if (initIndex) {initIndexOut();+ }}private void initDataOut() throws IOException {@@ -365,10 +380,6 @@ public final class Bytes {CodecUtil.writeHeader(idxOut, codecName, version);}- public long ramBytesUsed() {- return bytesUsed.get();- }-/*** Must be called only with increasing docIDs. It's OK for some docIDs to be* skipped; they will be filled with 0 bytes.@@ -448,14 +459,19 @@ public final class Bytes {} else {idxIn = null;}-}+ /**+ * clones and returns the data {@link IndexInput}+ */protected final IndexInput cloneData() {assert datIn != null;return (IndexInput) datIn.clone();}+ /**+ * clones and returns the indexing {@link IndexInput}+ */protected final IndexInput cloneIndex() {assert idxIn != null;return (IndexInput) idxIn.clone();diff --git a/lucene/src/java/org/apache/lucene/index/values/DocValues.java b/lucene/src/java/org/apache/lucene/index/values/DocValues.javaindex 44ae7873e35..c63c3e8da95 100644--- a/lucene/src/java/org/apache/lucene/index/values/DocValues.java+++ b/lucene/src/java/org/apache/lucene/index/values/DocValues.java@@ -28,12 +28,19 @@ import org.apache.lucene.util.BytesRef;/*** TODO+ ** @see FieldsEnum#docValues()* @see Fields#docValues(String)* @lucene.experimental*/public abstract class DocValues implements Closeable {-+ /*+ * TODO: it might be useful to add another Random Access enum for some+ * implementations like packed ints and only return such a random access enum+ * if the impl supports random access. For super large segments it might be+ * useful or even required in certain environements to have disc based random+ * access+ */public static final DocValues[] EMPTY_ARRAY = new DocValues[0];private SourceCache cache = new SourceCache.DirectSourceCache();@@ -141,7 +148,9 @@ public abstract class DocValues implements Closeable {* <p>* Note: All instances previously obtained from {@link #load()} or* {@link #loadSorted(Comparator)} will be closed.- * @throws IllegalArgumentException if the given cache is <code>null</code>+ *+ * @throws IllegalArgumentException+ * if the given cache is <code>null</code>**/public void setCache(SourceCache cache) {@@ -162,6 +171,7 @@ public abstract class DocValues implements Closeable {* {@link Source} defines 3 {@link Type} //TODO finish this*/public static abstract class Source {+ // TODO we might need a close method here to null out the internal used arrays?!protected final MissingValue missingValue = new MissingValue();/**diff --git a/lucene/src/java/org/apache/lucene/index/values/DocValuesEnum.java b/lucene/src/java/org/apache/lucene/index/values/DocValuesEnum.javaindex 60f9d655732..60dc7d539f9 100644--- a/lucene/src/java/org/apache/lucene/index/values/DocValuesEnum.java+++ b/lucene/src/java/org/apache/lucene/index/values/DocValuesEnum.java@@ -37,7 +37,7 @@ import org.apache.lucene.util.LongsRef;* <p>* Note: Only the reference for the enum's type are initialized to non* <code>null</code> ie. {@link #getInt()} will always return <code>null</code>- * if the enum's Type is {@link Type#SIMPLE_FLOAT_4BYTE}.+ * if the enum's Type is {@link Type#FLOAT_32}.** @lucene.experimental*/@@ -71,11 +71,11 @@ public abstract class DocValuesEnum extends DocIdSetIterator {case BYTES_VAR_STRAIGHT:bytesRef = new BytesRef();break;- case PACKED_INTS:+ case INTS:intsRef = new LongsRef(1);break;- case SIMPLE_FLOAT_4BYTE:- case SIMPLE_FLOAT_8BYTE:+ case FLOAT_32:+ case FLOAT_64:floatsRef = new FloatsRef(1);break;}diff --git a/lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.javaindex 108f382b480..47f8f2a6c99 100644--- a/lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java+++ b/lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java@@ -194,6 +194,7 @@ class FixedSortedBytesImpl {this.size = size;this.numValue = numValues;index = PackedInts.getReader(idxIn);+ closeIndexInput();}@Overridediff --git a/lucene/src/java/org/apache/lucene/index/values/Floats.java b/lucene/src/java/org/apache/lucene/index/values/Floats.javaindex 994f45726ee..31272553abf 100644--- a/lucene/src/java/org/apache/lucene/index/values/Floats.java+++ b/lucene/src/java/org/apache/lucene/index/values/Floats.java@@ -297,7 +297,7 @@ public class Floats {public DocValuesEnum getEnum(AttributeSource attrSource)throws IOException {final MissingValue missing = getMissing();- return new SourceEnum(attrSource, Type.SIMPLE_FLOAT_4BYTE, this, maxDoc) {+ return new SourceEnum(attrSource, Type.FLOAT_32, this, maxDoc) {@Overridepublic int advance(int target) throws IOException {if (target >= numDocs)@@ -315,7 +315,7 @@ public class Floats {@Overridepublic Type type() {- return Type.SIMPLE_FLOAT_4BYTE;+ return Type.FLOAT_32;}}@@ -355,7 +355,7 @@ public class Floats {@Overridepublic Type type() {- return Type.SIMPLE_FLOAT_8BYTE;+ return Type.FLOAT_64;}}@@ -377,8 +377,8 @@ public class Floats {@Overridepublic Type type() {- return precisionBytes == 4 ? Type.SIMPLE_FLOAT_4BYTE- : Type.SIMPLE_FLOAT_8BYTE;+ return precisionBytes == 4 ? Type.FLOAT_32+ : Type.FLOAT_64;}}@@ -386,7 +386,7 @@ public class Floats {Floats4Enum(AttributeSource source, IndexInput dataIn, int maxDoc)throws IOException {- super(source, dataIn, 4, maxDoc, Type.SIMPLE_FLOAT_4BYTE);+ super(source, dataIn, 4, maxDoc, Type.FLOAT_32);}@Override@@ -422,7 +422,7 @@ public class Floats {Floats8EnumImpl(AttributeSource source, IndexInput dataIn, int maxDoc)throws IOException {- super(source, dataIn, 8, maxDoc, Type.SIMPLE_FLOAT_8BYTE);+ super(source, dataIn, 8, maxDoc, Type.FLOAT_64);}@Override@@ -464,8 +464,8 @@ public class Floats {FloatsEnumImpl(AttributeSource source, IndexInput dataIn, int precision,int maxDoc, Type type) throws IOException {- super(source, precision == 4 ? Type.SIMPLE_FLOAT_4BYTE- : Type.SIMPLE_FLOAT_8BYTE);+ super(source, precision == 4 ? Type.FLOAT_32+ : Type.FLOAT_64);this.dataIn = dataIn;this.precision = precision;this.maxDoc = maxDoc;diff --git a/lucene/src/java/org/apache/lucene/index/values/PackedIntsImpl.java b/lucene/src/java/org/apache/lucene/index/values/PackedIntsImpl.javaindex 74ec4abe6d5..e2f7642b828 100644--- a/lucene/src/java/org/apache/lucene/index/values/PackedIntsImpl.java+++ b/lucene/src/java/org/apache/lucene/index/values/PackedIntsImpl.java@@ -111,7 +111,7 @@ class PackedIntsImpl {PackedInts.bitsRequired(maxValue - minValue));final int firstDoc = defaultValues.nextSetBit(0);lastDocId++;- if(firstDoc != -1) {+ if (firstDoc != -1) {for (int i = 0; i < firstDoc; i++) {w.add(defaultValue); // fill with defaults until first bit set}@@ -223,7 +223,7 @@ class PackedIntsImpl {@Overridepublic Type type() {- return Type.PACKED_INTS;+ return Type.INTS;}}@@ -240,7 +240,7 @@ class PackedIntsImpl {@Overridepublic Type type() {- return Type.PACKED_INTS;+ return Type.INTS;}}@@ -255,7 +255,7 @@ class PackedIntsImpl {private IntsEnumImpl(AttributeSource source, IndexInput dataIn)throws IOException {- super(source, Type.PACKED_INTS);+ super(source, Type.INTS);intsRef.offset = 0;this.dataIn = dataIn;dataIn.seek(CodecUtil.headerLength(CODEC_NAME));diff --git a/lucene/src/java/org/apache/lucene/index/values/Type.java b/lucene/src/java/org/apache/lucene/index/values/Type.javaindex 446f8a7b810..1d5dd0c2701 100644--- a/lucene/src/java/org/apache/lucene/index/values/Type.java+++ b/lucene/src/java/org/apache/lucene/index/values/Type.java@@ -1,4 +1,5 @@package org.apache.lucene.index.values;+/*** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -16,30 +17,38 @@ package org.apache.lucene.index.values;* limitations under the License.*/+import org.apache.lucene.index.codecs.Codec;+import org.apache.lucene.index.codecs.FieldsConsumer;import org.apache.lucene.index.values.DocValues.SortedSource;/*** {@link Type} specifies the type of the {@link DocValues} for a certain field.- * A {@link Type} can specify the actual data type for a field, used compression- * schemes and high-level data-structures.+ * A {@link Type} only defines the data type for a field while the actual+ * implemenation used to encode and decode the values depends on the field's+ * {@link Codec}. It is up to the {@link Codec} implementing+ * {@link FieldsConsumer#addValuesField(org.apache.lucene.index.FieldInfo)} and+ * using a different low-level implemenations to write the stored values for a+ * field.** @lucene.experimental*/public enum Type {-+ /*+ * TODO: Add INT_32 INT_64 INT_16 & INT_8?!+ *//**- * Integral value is stored as packed ints. The bit precision is fixed across- * the segment, and determined by the min/max values in the field.+ * Integer values.*/- PACKED_INTS,+ INTS,+/**- * 32 bit floating point value stored without modification or compression.+ * 32 bit floating point values.*/- SIMPLE_FLOAT_4BYTE,+ FLOAT_32,/**- * 64 bit floating point value stored without modification or compression.+ * 64 bit floating point values.*/- SIMPLE_FLOAT_8BYTE,+ FLOAT_64,// TODO(simonw): -- shouldn't lucene decide/detect straight vs// deref, as well fixed vs var?diff --git a/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java b/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.javaindex 132a5e4336f..bb9f9be53b6 100644--- a/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java+++ b/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java@@ -98,6 +98,15 @@ class VarDerefBytesImpl {}+ /*+ * TODO: if impls like this are merged we are bound to the amount of memory we+ * can store into a BytesRefHash and therefore how much memory a ByteBlockPool+ * can address. This is currently limited to 2GB. While we could extend that+ * and use 64bit for addressing this still limits us to the existing main+ * memory as all distinct bytes will be loaded up into main memory. We could+ * move the byte[] writing to #finish(int) and store the bytes in sorted+ * order and merge them in a streamed fashion.+ */static class Writer extends BytesWriterBase {private int[] docToAddress;private int address = 1;diff --git a/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.javaindex 9f65b9a86c9..c781c4f2a5d 100644--- a/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java+++ b/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java@@ -186,6 +186,7 @@ class VarSortedBytesImpl {docToOrdIndex = PackedInts.getReader(idxIn);ordToOffsetIndex = PackedInts.getReader(idxIn);valueCount = ordToOffsetIndex.size();+ closeIndexInput();}@Overridediff --git a/lucene/src/java/org/apache/lucene/index/values/Writer.java b/lucene/src/java/org/apache/lucene/index/values/Writer.javaindex aa060cf09fe..15f466f7de4 100644--- a/lucene/src/java/org/apache/lucene/index/values/Writer.java+++ b/lucene/src/java/org/apache/lucene/index/values/Writer.java@@ -197,11 +197,11 @@ public abstract class Writer extends DocValuesConsumer {comp = BytesRef.getUTF8SortedAsUnicodeComparator();}switch (type) {- case PACKED_INTS:+ case INTS:return Ints.getWriter(directory, id, true, bytesUsed);- case SIMPLE_FLOAT_4BYTE:+ case FLOAT_32:return Floats.getWriter(directory, id, 4, bytesUsed);- case SIMPLE_FLOAT_8BYTE:+ case FLOAT_64:return Floats.getWriter(directory, id, 8, bytesUsed);case BYTES_FIXED_STRAIGHT:return Bytes.getWriter(directory, id, Bytes.Mode.STRAIGHT, comp, true,diff --git a/lucene/src/java/org/apache/lucene/search/FieldComparator.java b/lucene/src/java/org/apache/lucene/search/FieldComparator.javaindex 3f9bade3350..27d10aecd41 100644--- a/lucene/src/java/org/apache/lucene/search/FieldComparator.java+++ b/lucene/src/java/org/apache/lucene/search/FieldComparator.java@@ -332,13 +332,13 @@ public abstract class FieldComparator {}/** Uses float index values to sort by ascending value */- public static final class FloatIndexValuesComparator extends FieldComparator {+ public static final class FloatDocValuesComparator extends FieldComparator {private final double[] values;private Source currentReaderValues;private final String field;private double bottom;- FloatIndexValuesComparator(int numHits, String field) {+ FloatDocValuesComparator(int numHits, String field) {values = new double[numHits];this.field = field;}@@ -599,13 +599,13 @@ public abstract class FieldComparator {}/** Loads int index values and sorts by ascending value. */- public static final class IntIndexValuesComparator extends FieldComparator {+ public static final class IntDocValuesComparator extends FieldComparator {private final long[] values;private Source currentReaderValues;private final String field;private long bottom;- IntIndexValuesComparator(int numHits, String field) {+ IntDocValuesComparator(int numHits, String field) {values = new long[numHits];this.field = field;}diff --git a/lucene/src/java/org/apache/lucene/search/SortField.java b/lucene/src/java/org/apache/lucene/search/SortField.javaindex 316b097165f..a5bfc761cef 100644--- a/lucene/src/java/org/apache/lucene/search/SortField.java+++ b/lucene/src/java/org/apache/lucene/search/SortField.java@@ -493,14 +493,14 @@ implements Serializable {case SortField.INT:if (useIndexValues) {- return new FieldComparator.IntIndexValuesComparator(numHits, field);+ return new FieldComparator.IntDocValuesComparator(numHits, field);} else {return new FieldComparator.IntComparator(numHits, (IntValuesCreator)creator, (Integer) missingValue);}case SortField.FLOAT:if (useIndexValues) {- return new FieldComparator.FloatIndexValuesComparator(numHits, field);+ return new FieldComparator.FloatDocValuesComparator(numHits, field);} else {return new FieldComparator.FloatComparator(numHits, (FloatValuesCreator) creator, (Float) missingValue);}diff --git a/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java b/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.javaindex 32ad59b7132..1883958eb03 100644--- a/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java+++ b/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java@@ -43,7 +43,7 @@ import org.apache.lucene.index.MergePolicy;import org.apache.lucene.index.MultiFields;import org.apache.lucene.index.Term;import org.apache.lucene.index.codecs.CodecProvider;-import org.apache.lucene.index.codecs.docvalues.DocValuesCodec;+import org.apache.lucene.index.codecs.docvalues.DocValuesCodecProvider;import org.apache.lucene.index.values.DocValues.MissingValue;import org.apache.lucene.index.values.DocValues.Source;import org.apache.lucene.queryParser.ParseException;@@ -79,19 +79,13 @@ public class TestDocValuesIndexing extends LuceneTestCase {**/- private DocValuesCodec docValuesCodec;private CodecProvider provider;@Beforepublic void setUp() throws Exception {super.setUp();- String defaultFieldCodec = CodecProvider.getDefault()- .getDefaultFieldCodec();- provider = new CodecProvider();- docValuesCodec = new DocValuesCodec(CodecProvider.getDefault().lookup(- defaultFieldCodec));- provider.register(docValuesCodec);- provider.setDefaultFieldCodec(docValuesCodec.name);+ provider = new DocValuesCodecProvider();+ provider.copyFrom(CodecProvider.getDefault());}/*@@ -278,7 +272,7 @@ public class TestDocValuesIndexing extends LuceneTestCase {final int numRemainingValues = (int) (numValues - deleted.cardinality());final int base = r.numDocs() - numRemainingValues;switch (val) {- case PACKED_INTS: {+ case INTS: {DocValues intsReader = getDocValues(r, val.name());assertNotNull(intsReader);@@ -309,8 +303,8 @@ public class TestDocValuesIndexing extends LuceneTestCase {}}break;- case SIMPLE_FLOAT_4BYTE:- case SIMPLE_FLOAT_8BYTE: {+ case FLOAT_32:+ case FLOAT_64: {DocValues floatReader = getDocValues(r, val.name());assertNotNull(floatReader);Source floats = getSource(floatReader);@@ -515,8 +509,8 @@ public class TestDocValuesIndexing extends LuceneTestCase {Type.BYTES_FIXED_SORTED, Type.BYTES_FIXED_STRAIGHT, Type.BYTES_VAR_DEREF,Type.BYTES_VAR_SORTED, Type.BYTES_VAR_STRAIGHT);- private static EnumSet<Type> NUMERICS = EnumSet.of(Type.PACKED_INTS,- Type.SIMPLE_FLOAT_4BYTE, Type.SIMPLE_FLOAT_8BYTE);+ private static EnumSet<Type> NUMERICS = EnumSet.of(Type.INTS,+ Type.FLOAT_32, Type.FLOAT_64);private static Index[] IDX_VALUES = new Index[] { Index.ANALYZED,Index.ANALYZED_NO_NORMS, Index.NOT_ANALYZED, Index.NOT_ANALYZED_NO_NORMS,@@ -547,11 +541,11 @@ public class TestDocValuesIndexing extends LuceneTestCase {for (int i = 0; i < numValues; i++) {if (isNumeric) {switch (value) {- case PACKED_INTS:+ case INTS:valField.setInt(i);break;- case SIMPLE_FLOAT_4BYTE:- case SIMPLE_FLOAT_8BYTE:+ case FLOAT_32:+ case FLOAT_64:valField.setFloat(2.0f * i);break;default: