diff --git a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java index 9b632c5c7dd..b0b47705f72 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java @@ -18,7 +18,6 @@ package org.apache.lucene.codecs; */ import java.io.IOException; -import org.apache.lucene.codecs.lucene40.values.Writer; import org.apache.lucene.document.DocValuesField; import org.apache.lucene.document.Field; import org.apache.lucene.index.DocValues.Source; @@ -155,7 +154,7 @@ public abstract class DocValuesConsumer { *
* All documents IDs between the given ID and the previously given ID or * 0 if the method is call the first time are filled with default - * values depending on the {@link Writer} implementation. The given document + * values depending on the implementation. The given document * ID must always be greater than the previous ID or 0 if called the * first time. */ diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesConsumer.java index 39f7b5804a4..6ffaec48d1e 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesConsumer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesConsumer.java @@ -20,7 +20,7 @@ package org.apache.lucene.codecs.lucene40; import java.io.IOException; import java.util.Set; -import org.apache.lucene.codecs.DocValuesWriterBase; +import org.apache.lucene.codecs.lucene40.values.DocValuesWriterBase; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.IndexFileNames; diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesProducer.java index 2162095fd35..67521f64e62 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesProducer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesProducer.java @@ -24,7 +24,7 @@ import java.util.Collection; import java.util.Map; import java.util.TreeMap; -import org.apache.lucene.codecs.DocValuesReaderBase; +import org.apache.lucene.codecs.lucene40.values.DocValuesReaderBase; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentReadState; diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java index eefd72bfe81..06bf58e5e40 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java @@ -64,7 +64,7 @@ import org.apache.lucene.util.packed.PackedInts; * * @lucene.experimental */ -public final class Bytes { +final class Bytes { static final String DV_SEGMENT_SUFFIX = "dv"; @@ -256,7 +256,7 @@ public final class Bytes { boolean success = false; try { datOut = dir.createOutput(IndexFileNames.segmentFileName(id, DV_SEGMENT_SUFFIX, - DATA_EXTENSION), context); + DocValuesWriterBase.DATA_EXTENSION), context); CodecUtil.writeHeader(datOut, codecName, version); success = true; } finally { @@ -281,7 +281,7 @@ public final class Bytes { try { if (idxOut == null) { idxOut = dir.createOutput(IndexFileNames.segmentFileName(id, DV_SEGMENT_SUFFIX, - INDEX_EXTENSION), context); + DocValuesWriterBase.INDEX_EXTENSION), context); CodecUtil.writeHeader(idxOut, codecName, version); } success = true; @@ -331,11 +331,11 @@ public final class Bytes { boolean success = false; try { dataIn = dir.openInput(IndexFileNames.segmentFileName(id, DV_SEGMENT_SUFFIX, - Writer.DATA_EXTENSION), context); + DocValuesWriterBase.DATA_EXTENSION), context); version = CodecUtil.checkHeader(dataIn, codecName, maxVersion, maxVersion); if (doIndex) { indexIn = dir.openInput(IndexFileNames.segmentFileName(id, DV_SEGMENT_SUFFIX, - Writer.INDEX_EXTENSION), context); + DocValuesWriterBase.INDEX_EXTENSION), context); final int version2 = CodecUtil.checkHeader(indexIn, codecName, maxVersion, maxVersion); assert version == version2; diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/BytesRefUtils.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/BytesRefUtils.java index 885d2f87149..4d4e7eae957 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/BytesRefUtils.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/BytesRefUtils.java @@ -25,7 +25,7 @@ import org.apache.lucene.util.BytesRef; * * @lucene.internal */ -public final class BytesRefUtils { +final class BytesRefUtils { private BytesRefUtils() { } diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DirectSource.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DirectSource.java index d26b72d9cc7..5f38e3cf352 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DirectSource.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DirectSource.java @@ -19,7 +19,6 @@ package org.apache.lucene.codecs.lucene40.values; import java.io.IOException; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.store.IndexInput; @@ -29,7 +28,7 @@ import org.apache.lucene.util.BytesRef; * Base class for disk resident source implementations * @lucene.internal */ -public abstract class DirectSource extends Source { +abstract class DirectSource extends Source { protected final IndexInput data; private final ToNumeric toNumeric; diff --git a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesReaderBase.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DocValuesReaderBase.java similarity index 98% rename from lucene/core/src/java/org/apache/lucene/codecs/DocValuesReaderBase.java rename to lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DocValuesReaderBase.java index 40239a97c6f..71fb02f0387 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesReaderBase.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DocValuesReaderBase.java @@ -1,4 +1,4 @@ -package org.apache.lucene.codecs; +package org.apache.lucene.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -24,6 +24,7 @@ import java.util.Comparator; import java.util.Map; import java.util.TreeMap; +import org.apache.lucene.codecs.PerDocProducer; import org.apache.lucene.codecs.lucene40.values.Bytes; import org.apache.lucene.codecs.lucene40.values.Floats; import org.apache.lucene.codecs.lucene40.values.Ints; @@ -39,7 +40,6 @@ import org.apache.lucene.util.BytesRef; * Abstract base class for PerDocProducer implementations * @lucene.experimental */ -// TODO: this needs to go under lucene40 codec (its specific to its impl) public abstract class DocValuesReaderBase extends PerDocProducer { protected abstract void closeInternal(Collection extends Closeable> closeables) throws IOException; diff --git a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesWriterBase.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DocValuesWriterBase.java similarity index 89% rename from lucene/core/src/java/org/apache/lucene/codecs/DocValuesWriterBase.java rename to lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DocValuesWriterBase.java index d6fae8b0aa0..7b8483f2c37 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesWriterBase.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/DocValuesWriterBase.java @@ -1,4 +1,4 @@ -package org.apache.lucene.codecs; +package org.apache.lucene.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -20,6 +20,8 @@ package org.apache.lucene.codecs; import java.io.IOException; import java.util.Comparator; +import org.apache.lucene.codecs.DocValuesConsumer; +import org.apache.lucene.codecs.PerDocConsumer; import org.apache.lucene.codecs.lucene40.values.Writer; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.PerDocWriteState; @@ -34,13 +36,22 @@ import org.apache.lucene.util.Counter; * * @lucene.experimental */ -//TODO: this needs to go under lucene40 codec (its specific to its impl) public abstract class DocValuesWriterBase extends PerDocConsumer { protected final String segmentName; private final Counter bytesUsed; protected final IOContext context; private final boolean fasterButMoreRam; + /** + * Filename extension for index files + */ + public static final String INDEX_EXTENSION = "idx"; + + /** + * Filename extension for data files. + */ + public static final String DATA_EXTENSION = "dat"; + /** * @param state The state to initiate a {@link PerDocConsumer} instance */ diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java index e96334c9b76..8a2d073c9c8 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java @@ -39,7 +39,7 @@ import org.apache.lucene.util.IOUtils; * * @lucene.experimental */ -public class Floats { +class Floats { protected static final String CODEC_NAME = "Floats"; protected static final int VERSION_START = 0; diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java index 066bb4a7ddc..a9ba6c3e069 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java @@ -36,7 +36,7 @@ import org.apache.lucene.util.IOUtils; * * @lucene.experimental */ -public final class Ints { +final class Ints { protected static final String CODEC_NAME = "Ints"; protected static final int VERSION_START = 0; protected static final int VERSION_CURRENT = VERSION_START; diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java index 106321f7d99..eb2acf70b05 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java @@ -169,7 +169,7 @@ class PackedIntValues { protected PackedIntsReader(Directory dir, String id, int numDocs, IOContext context) throws IOException { datIn = dir.openInput( - IndexFileNames.segmentFileName(id, Bytes.DV_SEGMENT_SUFFIX, Writer.DATA_EXTENSION), + IndexFileNames.segmentFileName(id, Bytes.DV_SEGMENT_SUFFIX, DocValuesWriterBase.DATA_EXTENSION), context); this.numDocs = numDocs; boolean success = false; diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Writer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Writer.java index a7f621b0d57..13529d3d487 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Writer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Writer.java @@ -38,7 +38,7 @@ import org.apache.lucene.util.Counter; * * @lucene.experimental */ -public abstract class Writer extends DocValuesConsumer { +abstract class Writer extends DocValuesConsumer { protected final Counter bytesUsed; /** @@ -53,16 +53,6 @@ public abstract class Writer extends DocValuesConsumer { this.bytesUsed = bytesUsed; } - /** - * Filename extension for index files - */ - public static final String INDEX_EXTENSION = "idx"; - - /** - * Filename extension for data files. - */ - public static final String DATA_EXTENSION = "dat"; - /** * Factory method to create a {@link Writer} instance for a given type. This * method returns default implementations for each of the different types diff --git a/lucene/core/src/java/org/apache/lucene/codecs/sep/SepDocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/sep/SepDocValuesConsumer.java index 682c2c65137..5a8472b9e48 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/sep/SepDocValuesConsumer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/sep/SepDocValuesConsumer.java @@ -21,8 +21,7 @@ import java.io.IOException; import java.util.HashSet; import java.util.Set; -import org.apache.lucene.codecs.DocValuesWriterBase; -import org.apache.lucene.codecs.lucene40.values.Writer; +import org.apache.lucene.codecs.lucene40.values.DocValuesWriterBase; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.IndexFileNames; @@ -67,10 +66,10 @@ public class SepDocValuesConsumer extends DocValuesWriterBase { case BYTES_FIXED_SORTED: case BYTES_VAR_SORTED: files.add(IndexFileNames.segmentFileName(filename, "", - Writer.INDEX_EXTENSION)); + INDEX_EXTENSION)); try { assert dir.fileExists(IndexFileNames.segmentFileName(filename, "", - Writer.INDEX_EXTENSION)); + INDEX_EXTENSION)); } catch (IOException e) { // don't throw checked exception - dir is only used in assert throw new RuntimeException(e); @@ -85,10 +84,10 @@ public class SepDocValuesConsumer extends DocValuesWriterBase { case FIXED_INTS_64: case FIXED_INTS_8: files.add(IndexFileNames.segmentFileName(filename, "", - Writer.DATA_EXTENSION)); + DATA_EXTENSION)); try { assert dir.fileExists(IndexFileNames.segmentFileName(filename, "", - Writer.DATA_EXTENSION)); + DATA_EXTENSION)); } catch (IOException e) { // don't throw checked exception - dir is only used in assert throw new RuntimeException(e); diff --git a/lucene/core/src/java/org/apache/lucene/codecs/sep/SepDocValuesProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/sep/SepDocValuesProducer.java index c752825ffb1..6cfb2f6b620 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/sep/SepDocValuesProducer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/sep/SepDocValuesProducer.java @@ -22,7 +22,7 @@ import java.util.Collection; import java.util.Map; import java.util.TreeMap; -import org.apache.lucene.codecs.DocValuesReaderBase; +import org.apache.lucene.codecs.lucene40.values.DocValuesReaderBase; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.util.IOUtils; diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestDocValues.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene40/values/TestDocValues.java similarity index 99% rename from lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestDocValues.java rename to lucene/core/src/test/org/apache/lucene/codecs/lucene40/values/TestDocValues.java index c72a1e21ea8..54574830926 100644 --- a/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestDocValues.java +++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene40/values/TestDocValues.java @@ -1,4 +1,4 @@ -package org.apache.lucene.codecs.lucene40; +package org.apache.lucene.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTypePromotion.java b/lucene/core/src/test/org/apache/lucene/index/TestTypePromotion.java index b88405c2ee4..8223ad65ae6 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestTypePromotion.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestTypePromotion.java @@ -23,13 +23,13 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.codecs.Codec; -import org.apache.lucene.codecs.lucene40.values.BytesRefUtils; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.DocValuesField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; +import org.apache.lucene.store.ByteArrayDataOutput; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; @@ -135,13 +135,17 @@ public class TestTypePromotion extends LuceneTestCase { value = bytes.bytes[bytes.offset]; break; case 2: - value = BytesRefUtils.asShort(bytes); + value = ((bytes.bytes[bytes.offset] & 0xFF) << 8) | (bytes.bytes[bytes.offset+1] & 0xFF); break; case 4: - value = BytesRefUtils.asInt(bytes); + value = ((bytes.bytes[bytes.offset] & 0xFF) << 24) | ((bytes.bytes[bytes.offset+1] & 0xFF) << 16) + | ((bytes.bytes[bytes.offset+2] & 0xFF) << 8) | (bytes.bytes[bytes.offset+3] & 0xFF); break; case 8: - value = BytesRefUtils.asLong(bytes); + value = (((long)(bytes.bytes[bytes.offset] & 0xff) << 56) | ((long)(bytes.bytes[bytes.offset+1] & 0xff) << 48) | + ((long)(bytes.bytes[bytes.offset+2] & 0xff) << 40) | ((long)(bytes.bytes[bytes.offset+3] & 0xff) << 32) | + ((long)(bytes.bytes[bytes.offset+4] & 0xff) << 24) | ((long)(bytes.bytes[bytes.offset+5] & 0xff) << 16) | + ((long)(bytes.bytes[bytes.offset+6] & 0xff) << 8) | ((long)(bytes.bytes[bytes.offset+7] & 0xff))); break; default: @@ -243,20 +247,27 @@ public class TestTypePromotion extends LuceneTestCase { case BYTES_FIXED_SORTED: case BYTES_FIXED_STRAIGHT: values[i] = random.nextLong(); - BytesRefUtils.copyLong(ref, values[i]); - valField.setValue(ref); + byte bytes[] = new byte[8]; + ByteArrayDataOutput out = new ByteArrayDataOutput(bytes, 0, 8); + out.writeLong(values[i]); + valField.setValue(new BytesRef(bytes)); break; case BYTES_VAR_DEREF: case BYTES_VAR_SORTED: case BYTES_VAR_STRAIGHT: + byte lbytes[] = new byte[8]; + ByteArrayDataOutput lout = new ByteArrayDataOutput(lbytes, 0, 8); + final int len; if (random.nextBoolean()) { - BytesRefUtils.copyInt(ref, random.nextInt()); - values[i] = BytesRefUtils.asInt(ref); + values[i] = random.nextInt(); + lout.writeInt((int)values[i]); + len = 4; } else { - BytesRefUtils.copyLong(ref, random.nextLong()); - values[i] = BytesRefUtils.asLong(ref); + values[i] = random.nextLong(); + lout.writeLong(values[i]); + len = 8; } - valField.setValue(ref); + valField.setValue(new BytesRef(lbytes, 0, len)); break; default: