lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [62/72] [abbrv] lucenenet git commit: Lucene.Net.TestFramework: Renamed Codecs\lucene42\ to Codecs\Lucene42\
Date Sun, 26 Feb 2017 23:37:50 GMT
Lucene.Net.TestFramework: Renamed Codecs\lucene42\ to Codecs\Lucene42\


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/9e2f4c5b
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/9e2f4c5b
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/9e2f4c5b

Branch: refs/heads/api-work
Commit: 9e2f4c5b96e5d3c4cce0e38da1609f7b03a3dedb
Parents: 9138d1b
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Feb 26 03:17:42 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Mon Feb 27 06:17:58 2017 +0700

----------------------------------------------------------------------
 .../Lucene42/Lucene42DocValuesConsumer.cs       | 469 +++++++++++++++++++
 .../Codecs/Lucene42/Lucene42FieldInfosWriter.cs | 145 ++++++
 .../Codecs/Lucene42/Lucene42RWCodec.cs          |  99 ++++
 .../Lucene42/Lucene42RWDocValuesFormat.cs       |  67 +++
 .../lucene42/Lucene42DocValuesConsumer.cs       | 469 -------------------
 .../Codecs/lucene42/Lucene42FieldInfosWriter.cs | 145 ------
 .../Codecs/lucene42/Lucene42RWCodec.cs          |  99 ----
 .../lucene42/Lucene42RWDocValuesFormat.cs       |  67 ---
 .../Lucene.Net.TestFramework.csproj             |   8 +-
 9 files changed, 784 insertions(+), 784 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9e2f4c5b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs
new file mode 100644
index 0000000..7441346
--- /dev/null
+++ b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs
@@ -0,0 +1,469 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+
+namespace Lucene.Net.Codecs.Lucene42
+{
+    using Lucene.Net.Util.Fst;
+    using ArrayUtil = Lucene.Net.Util.ArrayUtil;
+    using BlockPackedWriter = Lucene.Net.Util.Packed.BlockPackedWriter;
+    using ByteArrayDataOutput = Lucene.Net.Store.ByteArrayDataOutput;
+    using BytesRef = Lucene.Net.Util.BytesRef;
+
+    /*
+         * 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.
+         */
+
+    using FieldInfo = Lucene.Net.Index.FieldInfo;
+    using FormatAndBits = Lucene.Net.Util.Packed.PackedInt32s.FormatAndBits;
+    using IndexFileNames = Lucene.Net.Index.IndexFileNames;
+    using IndexOutput = Lucene.Net.Store.IndexOutput;
+    using INPUT_TYPE = Lucene.Net.Util.Fst.FST.INPUT_TYPE;
+    using Int32sRef = Lucene.Net.Util.Int32sRef;
+    using IOUtils = Lucene.Net.Util.IOUtils;
+    using MathUtil = Lucene.Net.Util.MathUtil;
+    using MonotonicBlockPackedWriter = Lucene.Net.Util.Packed.MonotonicBlockPackedWriter;
+    using PackedInt32s = Lucene.Net.Util.Packed.PackedInt32s;
+    using PositiveInt32Outputs = Lucene.Net.Util.Fst.PositiveInt32Outputs;
+    using SegmentWriteState = Lucene.Net.Index.SegmentWriteState;
+    using Util = Lucene.Net.Util.Fst.Util;
+
+    //   Constants use Lucene42DocValuesProducer.
+
+    /// <summary>
+    /// Writer for <seealso cref="Lucene42DocValuesFormat"/>
+    /// </summary>
+#pragma warning disable 612, 618
+    internal class Lucene42DocValuesConsumer : DocValuesConsumer
+    {
+        internal readonly IndexOutput Data, Meta;
+        internal readonly int MaxDoc;
+        internal readonly float AcceptableOverheadRatio;
+
+        internal Lucene42DocValuesConsumer(SegmentWriteState state, string dataCodec, string dataExtension, string metaCodec, string metaExtension, float acceptableOverheadRatio)
+        {
+            this.AcceptableOverheadRatio = acceptableOverheadRatio;
+            MaxDoc = state.SegmentInfo.DocCount;
+            bool success = false;
+            try
+            {
+                string dataName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, dataExtension);
+                Data = state.Directory.CreateOutput(dataName, state.Context);
+                // this writer writes the format 4.2 did!
+                CodecUtil.WriteHeader(Data, dataCodec, Lucene42DocValuesProducer.VERSION_GCD_COMPRESSION);
+                string metaName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, metaExtension);
+                Meta = state.Directory.CreateOutput(metaName, state.Context);
+                CodecUtil.WriteHeader(Meta, metaCodec, Lucene42DocValuesProducer.VERSION_GCD_COMPRESSION);
+                success = true;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    IOUtils.CloseWhileHandlingException(this);
+                }
+            }
+        }
+
+        public override void AddNumericField(FieldInfo field, IEnumerable<long?> values)
+        {
+            AddNumericField(field, values, true);
+        }
+
+        internal virtual void AddNumericField(FieldInfo field, IEnumerable<long?> values, bool optimizeStorage)
+        {
+            Meta.WriteVInt32(field.Number);
+            Meta.WriteByte((byte)Lucene42DocValuesProducer.NUMBER);
+            Meta.WriteInt64(Data.FilePointer);
+            long minValue = long.MaxValue;
+            long maxValue = long.MinValue;
+            long gcd = 0;
+            // TODO: more efficient?
+            HashSet<long> uniqueValues = null;
+            if (optimizeStorage)
+            {
+                uniqueValues = new HashSet<long>();
+
+                long count = 0;
+                foreach (long? nv in values)
+                {
+                    // TODO: support this as MemoryDVFormat (and be smart about missing maybe)
+                    long v = nv == null ? 0 : (long)nv;
+
+                    if (gcd != 1)
+                    {
+                        if (v < long.MinValue / 2 || v > long.MaxValue / 2)
+                        {
+                            // in that case v - minValue might overflow and make the GCD computation return
+                            // wrong results. Since these extreme values are unlikely, we just discard
+                            // GCD computation for them
+                            gcd = 1;
+                        } // minValue needs to be set first
+                        else if (count != 0)
+                        {
+                            gcd = MathUtil.Gcd(gcd, v - minValue);
+                        }
+                    }
+
+                    minValue = Math.Min(minValue, v);
+                    maxValue = Math.Max(maxValue, v);
+
+                    if (uniqueValues != null)
+                    {
+                        if (uniqueValues.Add(v))
+                        {
+                            if (uniqueValues.Count > 256)
+                            {
+                                uniqueValues = null;
+                            }
+                        }
+                    }
+
+                    ++count;
+                }
+                Debug.Assert(count == MaxDoc);
+            }
+
+            if (uniqueValues != null)
+            {
+                // small number of unique values
+                int bitsPerValue = PackedInt32s.BitsRequired(uniqueValues.Count - 1);
+                FormatAndBits formatAndBits = PackedInt32s.FastestFormatAndBits(MaxDoc, bitsPerValue, AcceptableOverheadRatio);
+                if (formatAndBits.BitsPerValue == 8 && minValue >= sbyte.MinValue && maxValue <= sbyte.MaxValue)
+                {
+                    Meta.WriteByte((byte)Lucene42DocValuesProducer.UNCOMPRESSED); // uncompressed
+                    foreach (long? nv in values)
+                    {
+                        Data.WriteByte(nv == null ? (byte)0 : (byte)nv);
+                    }
+                }
+                else
+                {
+                    Meta.WriteByte((byte)Lucene42DocValuesProducer.TABLE_COMPRESSED); // table-compressed
+                    long[] decode = uniqueValues.ToArray(/*new long?[uniqueValues.Count]*/);
+                    var encode = new Dictionary<long, int>();
+                    Data.WriteVInt32(decode.Length);
+                    for (int i = 0; i < decode.Length; i++)
+                    {
+                        Data.WriteInt64(decode[i]);
+                        encode[decode[i]] = i;
+                    }
+
+                    Meta.WriteVInt32(PackedInt32s.VERSION_CURRENT);
+                    Data.WriteVInt32(formatAndBits.Format.Id);
+                    Data.WriteVInt32(formatAndBits.BitsPerValue);
+
+                    PackedInt32s.Writer writer = PackedInt32s.GetWriterNoHeader(Data, formatAndBits.Format, MaxDoc, formatAndBits.BitsPerValue, PackedInt32s.DEFAULT_BUFFER_SIZE);
+                    foreach (long? nv in values)
+                    {
+                        writer.Add(encode[nv == null ? 0 : (long)nv]);
+                    }
+                    writer.Finish();
+                }
+            }
+            else if (gcd != 0 && gcd != 1)
+            {
+                Meta.WriteByte((byte)Lucene42DocValuesProducer.GCD_COMPRESSED);
+                Meta.WriteVInt32(PackedInt32s.VERSION_CURRENT);
+                Data.WriteInt64(minValue);
+                Data.WriteInt64(gcd);
+                Data.WriteVInt32(Lucene42DocValuesProducer.BLOCK_SIZE);
+
+                BlockPackedWriter writer = new BlockPackedWriter(Data, Lucene42DocValuesProducer.BLOCK_SIZE);
+                foreach (long? nv in values)
+                {
+                    long value = nv == null ? 0 : (long)nv;
+                    writer.Add((value - minValue) / gcd);
+                }
+                writer.Finish();
+            }
+            else
+            {
+                Meta.WriteByte((byte)Lucene42DocValuesProducer.DELTA_COMPRESSED); // delta-compressed
+
+                Meta.WriteVInt32(PackedInt32s.VERSION_CURRENT);
+                Data.WriteVInt32(Lucene42DocValuesProducer.BLOCK_SIZE);
+
+                BlockPackedWriter writer = new BlockPackedWriter(Data, Lucene42DocValuesProducer.BLOCK_SIZE);
+                foreach (long? nv in values)
+                {
+                    writer.Add(nv == null ? 0 : (long)nv);
+                }
+                writer.Finish();
+            }
+        }
+
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing)
+            {
+                bool success = false;
+                try
+                {
+                    if (Meta != null)
+                    {
+                        Meta.WriteVInt32(-1); // write EOF marker
+                    }
+                    success = true;
+                }
+                finally
+                {
+                    if (success)
+                    {
+                        IOUtils.Close(Data, Meta);
+                    }
+                    else
+                    {
+                        IOUtils.CloseWhileHandlingException(Data, Meta);
+                    }
+                }
+            }
+        }
+
+        public override void AddBinaryField(FieldInfo field, IEnumerable<BytesRef> values)
+        {
+            // write the byte[] data
+            Meta.WriteVInt32(field.Number);
+            Meta.WriteByte((byte)Lucene42DocValuesProducer.BYTES);
+            int minLength = int.MaxValue;
+            int maxLength = int.MinValue;
+            long startFP = Data.FilePointer;
+            foreach (BytesRef v in values)
+            {
+                int length = v == null ? 0 : v.Length;
+                if (length > Lucene42DocValuesFormat.MAX_BINARY_FIELD_LENGTH)
+                {
+                    throw new System.ArgumentException("DocValuesField \"" + field.Name + "\" is too large, must be <= " + Lucene42DocValuesFormat.MAX_BINARY_FIELD_LENGTH);
+                }
+                minLength = Math.Min(minLength, length);
+                maxLength = Math.Max(maxLength, length);
+                if (v != null)
+                {
+                    Data.WriteBytes(v.Bytes, v.Offset, v.Length);
+                }
+            }
+            Meta.WriteInt64(startFP);
+            Meta.WriteInt64(Data.FilePointer - startFP);
+            Meta.WriteVInt32(minLength);
+            Meta.WriteVInt32(maxLength);
+
+            // if minLength == maxLength, its a fixed-length byte[], we are done (the addresses are implicit)
+            // otherwise, we need to record the length fields...
+            if (minLength != maxLength)
+            {
+                Meta.WriteVInt32(PackedInt32s.VERSION_CURRENT);
+                Meta.WriteVInt32(Lucene42DocValuesProducer.BLOCK_SIZE);
+
+                MonotonicBlockPackedWriter writer = new MonotonicBlockPackedWriter(Data, Lucene42DocValuesProducer.BLOCK_SIZE);
+                long addr = 0;
+                foreach (BytesRef v in values)
+                {
+                    if (v != null)
+                    {
+                        addr += v.Length;
+                    }
+                    writer.Add(addr);
+                }
+                writer.Finish();
+            }
+        }
+
+        private void WriteFST(FieldInfo field, IEnumerable<BytesRef> values)
+        {
+            Meta.WriteVInt32(field.Number);
+            Meta.WriteByte((byte)Lucene42DocValuesProducer.FST);
+            Meta.WriteInt64(Data.FilePointer);
+            PositiveInt32Outputs outputs = PositiveInt32Outputs.Singleton;
+            Builder<long?> builder = new Builder<long?>(INPUT_TYPE.BYTE1, outputs);
+            Int32sRef scratch = new Int32sRef();
+            long ord = 0;
+            foreach (BytesRef v in values)
+            {
+                builder.Add(Util.ToInt32sRef(v, scratch), ord);
+                ord++;
+            }
+
+            var fst = builder.Finish();
+            if (fst != null)
+            {
+                fst.Save(Data);
+            }
+            Meta.WriteVInt64(ord);
+        }
+
+        public override void AddSortedField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<long?> docToOrd)
+        {
+            // three cases for simulating the old writer:
+            // 1. no missing
+            // 2. missing (and empty string in use): remap ord=-1 -> ord=0
+            // 3. missing (and empty string not in use): remap all ords +1, insert empty string into values
+            bool anyMissing = false;
+            foreach (long? n in docToOrd)
+            {
+                if (n.Value == -1)
+                {
+                    anyMissing = true;
+                    break;
+                }
+            }
+
+            bool hasEmptyString = false;
+            foreach (BytesRef b in values)
+            {
+                hasEmptyString = b.Length == 0;
+                break;
+            }
+
+            if (!anyMissing)
+            {
+                // nothing to do
+            }
+            else if (hasEmptyString)
+            {
+                docToOrd = MissingOrdRemapper.MapMissingToOrd0(docToOrd);
+            }
+            else
+            {
+                docToOrd = MissingOrdRemapper.MapAllOrds(docToOrd);
+                values = MissingOrdRemapper.InsertEmptyValue(values);
+            }
+
+            // write the ordinals as numerics
+            AddNumericField(field, docToOrd, false);
+
+            // write the values as FST
+            WriteFST(field, values);
+        }
+
+        // note: this might not be the most efficient... but its fairly simple
+        public override void AddSortedSetField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<long?> docToOrdCount, IEnumerable<long?> ords)
+        {
+            // write the ordinals as a binary field
+            AddBinaryField(field, new IterableAnonymousInnerClassHelper(this, docToOrdCount, ords));
+
+            // write the values as FST
+            WriteFST(field, values);
+        }
+
+        private class IterableAnonymousInnerClassHelper : IEnumerable<BytesRef>
+        {
+            private readonly Lucene42DocValuesConsumer OuterInstance;
+
+            private IEnumerable<long?> DocToOrdCount;
+            private IEnumerable<long?> Ords;
+
+            public IterableAnonymousInnerClassHelper(Lucene42DocValuesConsumer outerInstance, IEnumerable<long?> docToOrdCount, IEnumerable<long?> ords)
+            {
+                this.OuterInstance = outerInstance;
+                this.DocToOrdCount = docToOrdCount;
+                this.Ords = ords;
+            }
+
+            public IEnumerator<BytesRef> GetEnumerator()
+            {
+                return new SortedSetIterator(DocToOrdCount.GetEnumerator(), Ords.GetEnumerator());
+            }
+
+            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+            {
+                return GetEnumerator();
+            }
+        }
+
+        // per-document vint-encoded byte[]
+        internal class SortedSetIterator : IEnumerator<BytesRef>
+        {
+            internal byte[] Buffer = new byte[10];
+            internal ByteArrayDataOutput @out = new ByteArrayDataOutput();
+            internal BytesRef @ref = new BytesRef();
+
+            internal readonly IEnumerator<long?> Counts;
+            internal readonly IEnumerator<long?> Ords;
+
+            internal SortedSetIterator(IEnumerator<long?> counts, IEnumerator<long?> ords)
+            {
+                this.Counts = counts;
+                this.Ords = ords;
+            }
+
+            public bool MoveNext()
+            {
+                if (!Counts.MoveNext())
+                {
+                    return false;
+                }
+
+                int count = (int)Counts.Current;
+                int maxSize = count * 9; //worst case
+                if (maxSize > Buffer.Length)
+                {
+                    Buffer = ArrayUtil.Grow(Buffer, maxSize);
+                }
+
+                try
+                {
+                    EncodeValues(count);
+                }
+                catch (IOException bogus)
+                {
+                    throw new Exception(bogus.Message, bogus);
+                }
+
+                @ref.Bytes = Buffer;
+                @ref.Offset = 0;
+                @ref.Length = @out.Position;
+
+                return true;
+            }
+
+            public BytesRef Current
+            {
+                get { return @ref; }
+            }
+
+            object System.Collections.IEnumerator.Current
+            {
+                get { return Current; }
+            }
+
+            // encodes count values to buffer
+            internal virtual void EncodeValues(int count)
+            {
+                @out.Reset(Buffer);
+                long lastOrd = 0;
+                for (int i = 0; i < count; i++)
+                {
+                    Ords.MoveNext();
+                    long ord = Ords.Current.Value;
+                    @out.WriteVInt64(ord - lastOrd);
+                    lastOrd = ord;
+                }
+            }
+
+            public void Reset()
+            {
+                throw new NotImplementedException();
+            }
+
+            public void Dispose()
+            {
+            }
+        }
+    }
+#pragma warning restore 612, 618
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9e2f4c5b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42FieldInfosWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42FieldInfosWriter.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42FieldInfosWriter.cs
new file mode 100644
index 0000000..acdae7b
--- /dev/null
+++ b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42FieldInfosWriter.cs
@@ -0,0 +1,145 @@
+using System;
+using System.Diagnostics;
+
+namespace Lucene.Net.Codecs.Lucene42
+{
+    using Directory = Lucene.Net.Store.Directory;
+
+    /*
+         * 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.
+         */
+
+    using DocValuesType = Lucene.Net.Index.DocValuesType;
+    using FieldInfo = Lucene.Net.Index.FieldInfo;
+    using FieldInfos = Lucene.Net.Index.FieldInfos;
+    using IndexFileNames = Lucene.Net.Index.IndexFileNames;
+    using IndexOutput = Lucene.Net.Store.IndexOutput;
+    using IndexOptions = Lucene.Net.Index.IndexOptions;
+    using IOContext = Lucene.Net.Store.IOContext;
+    using IOUtils = Lucene.Net.Util.IOUtils;
+
+    /// <summary>
+    /// Lucene 4.2 FieldInfos writer.
+    /// </summary>
+    /// <seealso> cref= Lucene42FieldInfosFormat
+    /// @lucene.experimental </seealso>
+    [Obsolete]
+    public sealed class Lucene42FieldInfosWriter : FieldInfosWriter
+    {
+        /// <summary>
+        /// Sole constructor. </summary>
+        public Lucene42FieldInfosWriter()
+        {
+        }
+
+        public override void Write(Directory directory, string segmentName, string segmentSuffix, FieldInfos infos, IOContext context)
+        {
+            string fileName = IndexFileNames.SegmentFileName(segmentName, "", Lucene42FieldInfosFormat.EXTENSION);
+            IndexOutput output = directory.CreateOutput(fileName, context);
+            bool success = false;
+            try
+            {
+                CodecUtil.WriteHeader(output, Lucene42FieldInfosFormat.CODEC_NAME, Lucene42FieldInfosFormat.FORMAT_CURRENT);
+                output.WriteVInt32(infos.Count);
+                foreach (FieldInfo fi in infos)
+                {
+                    IndexOptions? indexOptions = fi.IndexOptions;
+                    sbyte bits = 0x0;
+                    if (fi.HasVectors)
+                    {
+                        bits |= Lucene42FieldInfosFormat.STORE_TERMVECTOR;
+                    }
+                    if (fi.OmitsNorms)
+                    {
+                        bits |= Lucene42FieldInfosFormat.OMIT_NORMS;
+                    }
+                    if (fi.HasPayloads)
+                    {
+                        bits |= Lucene42FieldInfosFormat.STORE_PAYLOADS;
+                    }
+                    if (fi.IsIndexed)
+                    {
+                        bits |= Lucene42FieldInfosFormat.IS_INDEXED;
+                        Debug.Assert(indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !fi.HasPayloads);
+                        if (indexOptions == IndexOptions.DOCS_ONLY)
+                        {
+                            bits |= Lucene42FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS;
+                        }
+                        else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS)
+                        {
+                            bits |= Lucene42FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS;
+                        }
+                        else if (indexOptions == IndexOptions.DOCS_AND_FREQS)
+                        {
+                            bits |= Lucene42FieldInfosFormat.OMIT_POSITIONS;
+                        }
+                    }
+                    output.WriteString(fi.Name);
+                    output.WriteVInt32(fi.Number);
+                    output.WriteByte((byte)bits);
+
+                    // pack the DV types in one byte
+                    var dv = DocValuesByte(fi.DocValuesType);
+                    var nrm = DocValuesByte(fi.NormType);
+                    Debug.Assert((dv & (~0xF)) == 0 && (nrm & (~0x0F)) == 0);
+                    var val = unchecked((sbyte)(0xff & ((nrm << 4) | dv)));
+                    output.WriteByte((byte)val);
+                    output.WriteStringStringMap(fi.Attributes);
+                }
+                success = true;
+            }
+            finally
+            {
+                if (success)
+                {
+                    output.Dispose();
+                }
+                else
+                {
+                    IOUtils.CloseWhileHandlingException(output);
+                }
+            }
+        }
+
+        private static sbyte DocValuesByte(DocValuesType? type)
+        {
+            if (type == null)
+            {
+                return 0;
+            }
+            else if (type == DocValuesType.NUMERIC)
+            {
+                return 1;
+            }
+            else if (type == DocValuesType.BINARY)
+            {
+                return 2;
+            }
+            else if (type == DocValuesType.SORTED)
+            {
+                return 3;
+            }
+            else if (type == DocValuesType.SORTED_SET)
+            {
+                return 4;
+            }
+            else
+            {
+                throw new InvalidOperationException();
+            }
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9e2f4c5b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42RWCodec.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42RWCodec.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42RWCodec.cs
new file mode 100644
index 0000000..39e3b66
--- /dev/null
+++ b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42RWCodec.cs
@@ -0,0 +1,99 @@
+namespace Lucene.Net.Codecs.Lucene42
+{
+    /*
+     * 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.
+     */
+
+    using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+
+    /// <summary>
+    /// Read-write version of <seealso cref="Lucene42Codec"/> for testing.
+    /// </summary>
+#pragma warning disable 612, 618
+    public class Lucene42RWCodec : Lucene42Codec
+    {
+        private readonly DocValuesFormat Dv;
+        private readonly NormsFormat Norms = new Lucene42NormsFormat();
+        private readonly FieldInfosFormat fieldInfosFormat;
+
+        /// <summary>
+        /// LUCENENET specific
+        /// Creates the codec with OldFormatImpersonationIsActive = true.
+        /// </summary>
+        /// <remarks>
+        /// Added so that SPIClassIterator can locate this Codec.  The iterator
+        /// only recognises classes that have empty constructors.
+        /// </remarks>
+        public Lucene42RWCodec()
+            : this(true)
+        { }
+
+        /// <param name="oldFormatImpersonationIsActive">
+        /// LUCENENET specific
+        /// Added to remove dependency on then-static <see cref="LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE"/> 
+        /// </param>
+        public Lucene42RWCodec(bool oldFormatImpersonationIsActive) : base()
+        {
+            Dv = new Lucene42RWDocValuesFormat(oldFormatImpersonationIsActive);
+            fieldInfosFormat = new Lucene42FieldInfosFormatAnonymousInnerClassHelper(oldFormatImpersonationIsActive);
+        }
+
+        private class Lucene42FieldInfosFormatAnonymousInnerClassHelper : Lucene42FieldInfosFormat
+        {
+            private readonly bool _oldFormatImpersonationIsActive;
+
+            /// <param name="oldFormatImpersonationIsActive">
+            /// LUCENENET specific
+            /// Added to remove dependency on then-static <see cref="LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE"/> 
+            /// </param>
+            public Lucene42FieldInfosFormatAnonymousInnerClassHelper(bool oldFormatImpersonationIsActive) : base()
+            {
+                _oldFormatImpersonationIsActive = oldFormatImpersonationIsActive;
+            }
+
+            public override FieldInfosWriter FieldInfosWriter
+            {
+                get
+                {
+                    if (!_oldFormatImpersonationIsActive)
+                    {
+                        return base.FieldInfosWriter;
+                    }
+                    else
+                    {
+                        return new Lucene42FieldInfosWriter();
+                    }
+                }
+            }
+        }
+
+        public override DocValuesFormat GetDocValuesFormatForField(string field)
+        {
+            return Dv;
+        }
+
+        public override NormsFormat NormsFormat
+        {
+            get { return Norms; }
+        }
+
+        public override FieldInfosFormat FieldInfosFormat
+        {
+            get { return fieldInfosFormat; }
+        }
+    }
+#pragma warning restore 612, 618
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9e2f4c5b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42RWDocValuesFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42RWDocValuesFormat.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42RWDocValuesFormat.cs
new file mode 100644
index 0000000..1a29fe6
--- /dev/null
+++ b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42RWDocValuesFormat.cs
@@ -0,0 +1,67 @@
+namespace Lucene.Net.Codecs.Lucene42
+{
+    using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+
+    /*
+         * 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.
+         */
+
+    using SegmentWriteState = Lucene.Net.Index.SegmentWriteState;
+
+    /// <summary>
+    /// Read-write version of <seealso cref="Lucene42DocValuesFormat"/> for testing.
+    /// </summary>
+#pragma warning disable 612, 618
+    public class Lucene42RWDocValuesFormat : Lucene42DocValuesFormat
+    {
+        private readonly bool _oldFormatImpersonationIsActive;
+
+        /// <summary>
+        /// LUCENENET specific
+        /// Creates the codec with OldFormatImpersonationIsActive = true.
+        /// </summary>
+        /// <remarks>
+        /// Added so that SPIClassIterator can locate this Codec.  The iterator
+        /// only recognises classes that have empty constructors.
+        /// </remarks>
+        public Lucene42RWDocValuesFormat()
+            : this(true)
+        { }
+
+        /// <param name="oldFormatImpersonationIsActive">
+        /// LUCENENET specific
+        /// Added to remove dependency on then-static <see cref="LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE"/> 
+        /// </param>
+        public Lucene42RWDocValuesFormat(bool oldFormatImpersonationIsActive) : base()
+        {
+            _oldFormatImpersonationIsActive = oldFormatImpersonationIsActive;
+        }
+
+        public override DocValuesConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            if (!_oldFormatImpersonationIsActive)
+            {
+                return base.FieldsConsumer(state);
+            }
+            else
+            {
+                // note: we choose DEFAULT here (its reasonably fast, and for small bpv has tiny waste)
+                return new Lucene42DocValuesConsumer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION, m_acceptableOverheadRatio);
+            }
+        }
+    }
+#pragma warning restore 612, 618
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9e2f4c5b/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42DocValuesConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42DocValuesConsumer.cs b/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42DocValuesConsumer.cs
deleted file mode 100644
index 7441346..0000000
--- a/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42DocValuesConsumer.cs
+++ /dev/null
@@ -1,469 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-
-namespace Lucene.Net.Codecs.Lucene42
-{
-    using Lucene.Net.Util.Fst;
-    using ArrayUtil = Lucene.Net.Util.ArrayUtil;
-    using BlockPackedWriter = Lucene.Net.Util.Packed.BlockPackedWriter;
-    using ByteArrayDataOutput = Lucene.Net.Store.ByteArrayDataOutput;
-    using BytesRef = Lucene.Net.Util.BytesRef;
-
-    /*
-         * 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.
-         */
-
-    using FieldInfo = Lucene.Net.Index.FieldInfo;
-    using FormatAndBits = Lucene.Net.Util.Packed.PackedInt32s.FormatAndBits;
-    using IndexFileNames = Lucene.Net.Index.IndexFileNames;
-    using IndexOutput = Lucene.Net.Store.IndexOutput;
-    using INPUT_TYPE = Lucene.Net.Util.Fst.FST.INPUT_TYPE;
-    using Int32sRef = Lucene.Net.Util.Int32sRef;
-    using IOUtils = Lucene.Net.Util.IOUtils;
-    using MathUtil = Lucene.Net.Util.MathUtil;
-    using MonotonicBlockPackedWriter = Lucene.Net.Util.Packed.MonotonicBlockPackedWriter;
-    using PackedInt32s = Lucene.Net.Util.Packed.PackedInt32s;
-    using PositiveInt32Outputs = Lucene.Net.Util.Fst.PositiveInt32Outputs;
-    using SegmentWriteState = Lucene.Net.Index.SegmentWriteState;
-    using Util = Lucene.Net.Util.Fst.Util;
-
-    //   Constants use Lucene42DocValuesProducer.
-
-    /// <summary>
-    /// Writer for <seealso cref="Lucene42DocValuesFormat"/>
-    /// </summary>
-#pragma warning disable 612, 618
-    internal class Lucene42DocValuesConsumer : DocValuesConsumer
-    {
-        internal readonly IndexOutput Data, Meta;
-        internal readonly int MaxDoc;
-        internal readonly float AcceptableOverheadRatio;
-
-        internal Lucene42DocValuesConsumer(SegmentWriteState state, string dataCodec, string dataExtension, string metaCodec, string metaExtension, float acceptableOverheadRatio)
-        {
-            this.AcceptableOverheadRatio = acceptableOverheadRatio;
-            MaxDoc = state.SegmentInfo.DocCount;
-            bool success = false;
-            try
-            {
-                string dataName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, dataExtension);
-                Data = state.Directory.CreateOutput(dataName, state.Context);
-                // this writer writes the format 4.2 did!
-                CodecUtil.WriteHeader(Data, dataCodec, Lucene42DocValuesProducer.VERSION_GCD_COMPRESSION);
-                string metaName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, metaExtension);
-                Meta = state.Directory.CreateOutput(metaName, state.Context);
-                CodecUtil.WriteHeader(Meta, metaCodec, Lucene42DocValuesProducer.VERSION_GCD_COMPRESSION);
-                success = true;
-            }
-            finally
-            {
-                if (!success)
-                {
-                    IOUtils.CloseWhileHandlingException(this);
-                }
-            }
-        }
-
-        public override void AddNumericField(FieldInfo field, IEnumerable<long?> values)
-        {
-            AddNumericField(field, values, true);
-        }
-
-        internal virtual void AddNumericField(FieldInfo field, IEnumerable<long?> values, bool optimizeStorage)
-        {
-            Meta.WriteVInt32(field.Number);
-            Meta.WriteByte((byte)Lucene42DocValuesProducer.NUMBER);
-            Meta.WriteInt64(Data.FilePointer);
-            long minValue = long.MaxValue;
-            long maxValue = long.MinValue;
-            long gcd = 0;
-            // TODO: more efficient?
-            HashSet<long> uniqueValues = null;
-            if (optimizeStorage)
-            {
-                uniqueValues = new HashSet<long>();
-
-                long count = 0;
-                foreach (long? nv in values)
-                {
-                    // TODO: support this as MemoryDVFormat (and be smart about missing maybe)
-                    long v = nv == null ? 0 : (long)nv;
-
-                    if (gcd != 1)
-                    {
-                        if (v < long.MinValue / 2 || v > long.MaxValue / 2)
-                        {
-                            // in that case v - minValue might overflow and make the GCD computation return
-                            // wrong results. Since these extreme values are unlikely, we just discard
-                            // GCD computation for them
-                            gcd = 1;
-                        } // minValue needs to be set first
-                        else if (count != 0)
-                        {
-                            gcd = MathUtil.Gcd(gcd, v - minValue);
-                        }
-                    }
-
-                    minValue = Math.Min(minValue, v);
-                    maxValue = Math.Max(maxValue, v);
-
-                    if (uniqueValues != null)
-                    {
-                        if (uniqueValues.Add(v))
-                        {
-                            if (uniqueValues.Count > 256)
-                            {
-                                uniqueValues = null;
-                            }
-                        }
-                    }
-
-                    ++count;
-                }
-                Debug.Assert(count == MaxDoc);
-            }
-
-            if (uniqueValues != null)
-            {
-                // small number of unique values
-                int bitsPerValue = PackedInt32s.BitsRequired(uniqueValues.Count - 1);
-                FormatAndBits formatAndBits = PackedInt32s.FastestFormatAndBits(MaxDoc, bitsPerValue, AcceptableOverheadRatio);
-                if (formatAndBits.BitsPerValue == 8 && minValue >= sbyte.MinValue && maxValue <= sbyte.MaxValue)
-                {
-                    Meta.WriteByte((byte)Lucene42DocValuesProducer.UNCOMPRESSED); // uncompressed
-                    foreach (long? nv in values)
-                    {
-                        Data.WriteByte(nv == null ? (byte)0 : (byte)nv);
-                    }
-                }
-                else
-                {
-                    Meta.WriteByte((byte)Lucene42DocValuesProducer.TABLE_COMPRESSED); // table-compressed
-                    long[] decode = uniqueValues.ToArray(/*new long?[uniqueValues.Count]*/);
-                    var encode = new Dictionary<long, int>();
-                    Data.WriteVInt32(decode.Length);
-                    for (int i = 0; i < decode.Length; i++)
-                    {
-                        Data.WriteInt64(decode[i]);
-                        encode[decode[i]] = i;
-                    }
-
-                    Meta.WriteVInt32(PackedInt32s.VERSION_CURRENT);
-                    Data.WriteVInt32(formatAndBits.Format.Id);
-                    Data.WriteVInt32(formatAndBits.BitsPerValue);
-
-                    PackedInt32s.Writer writer = PackedInt32s.GetWriterNoHeader(Data, formatAndBits.Format, MaxDoc, formatAndBits.BitsPerValue, PackedInt32s.DEFAULT_BUFFER_SIZE);
-                    foreach (long? nv in values)
-                    {
-                        writer.Add(encode[nv == null ? 0 : (long)nv]);
-                    }
-                    writer.Finish();
-                }
-            }
-            else if (gcd != 0 && gcd != 1)
-            {
-                Meta.WriteByte((byte)Lucene42DocValuesProducer.GCD_COMPRESSED);
-                Meta.WriteVInt32(PackedInt32s.VERSION_CURRENT);
-                Data.WriteInt64(minValue);
-                Data.WriteInt64(gcd);
-                Data.WriteVInt32(Lucene42DocValuesProducer.BLOCK_SIZE);
-
-                BlockPackedWriter writer = new BlockPackedWriter(Data, Lucene42DocValuesProducer.BLOCK_SIZE);
-                foreach (long? nv in values)
-                {
-                    long value = nv == null ? 0 : (long)nv;
-                    writer.Add((value - minValue) / gcd);
-                }
-                writer.Finish();
-            }
-            else
-            {
-                Meta.WriteByte((byte)Lucene42DocValuesProducer.DELTA_COMPRESSED); // delta-compressed
-
-                Meta.WriteVInt32(PackedInt32s.VERSION_CURRENT);
-                Data.WriteVInt32(Lucene42DocValuesProducer.BLOCK_SIZE);
-
-                BlockPackedWriter writer = new BlockPackedWriter(Data, Lucene42DocValuesProducer.BLOCK_SIZE);
-                foreach (long? nv in values)
-                {
-                    writer.Add(nv == null ? 0 : (long)nv);
-                }
-                writer.Finish();
-            }
-        }
-
-        protected override void Dispose(bool disposing)
-        {
-            if (disposing)
-            {
-                bool success = false;
-                try
-                {
-                    if (Meta != null)
-                    {
-                        Meta.WriteVInt32(-1); // write EOF marker
-                    }
-                    success = true;
-                }
-                finally
-                {
-                    if (success)
-                    {
-                        IOUtils.Close(Data, Meta);
-                    }
-                    else
-                    {
-                        IOUtils.CloseWhileHandlingException(Data, Meta);
-                    }
-                }
-            }
-        }
-
-        public override void AddBinaryField(FieldInfo field, IEnumerable<BytesRef> values)
-        {
-            // write the byte[] data
-            Meta.WriteVInt32(field.Number);
-            Meta.WriteByte((byte)Lucene42DocValuesProducer.BYTES);
-            int minLength = int.MaxValue;
-            int maxLength = int.MinValue;
-            long startFP = Data.FilePointer;
-            foreach (BytesRef v in values)
-            {
-                int length = v == null ? 0 : v.Length;
-                if (length > Lucene42DocValuesFormat.MAX_BINARY_FIELD_LENGTH)
-                {
-                    throw new System.ArgumentException("DocValuesField \"" + field.Name + "\" is too large, must be <= " + Lucene42DocValuesFormat.MAX_BINARY_FIELD_LENGTH);
-                }
-                minLength = Math.Min(minLength, length);
-                maxLength = Math.Max(maxLength, length);
-                if (v != null)
-                {
-                    Data.WriteBytes(v.Bytes, v.Offset, v.Length);
-                }
-            }
-            Meta.WriteInt64(startFP);
-            Meta.WriteInt64(Data.FilePointer - startFP);
-            Meta.WriteVInt32(minLength);
-            Meta.WriteVInt32(maxLength);
-
-            // if minLength == maxLength, its a fixed-length byte[], we are done (the addresses are implicit)
-            // otherwise, we need to record the length fields...
-            if (minLength != maxLength)
-            {
-                Meta.WriteVInt32(PackedInt32s.VERSION_CURRENT);
-                Meta.WriteVInt32(Lucene42DocValuesProducer.BLOCK_SIZE);
-
-                MonotonicBlockPackedWriter writer = new MonotonicBlockPackedWriter(Data, Lucene42DocValuesProducer.BLOCK_SIZE);
-                long addr = 0;
-                foreach (BytesRef v in values)
-                {
-                    if (v != null)
-                    {
-                        addr += v.Length;
-                    }
-                    writer.Add(addr);
-                }
-                writer.Finish();
-            }
-        }
-
-        private void WriteFST(FieldInfo field, IEnumerable<BytesRef> values)
-        {
-            Meta.WriteVInt32(field.Number);
-            Meta.WriteByte((byte)Lucene42DocValuesProducer.FST);
-            Meta.WriteInt64(Data.FilePointer);
-            PositiveInt32Outputs outputs = PositiveInt32Outputs.Singleton;
-            Builder<long?> builder = new Builder<long?>(INPUT_TYPE.BYTE1, outputs);
-            Int32sRef scratch = new Int32sRef();
-            long ord = 0;
-            foreach (BytesRef v in values)
-            {
-                builder.Add(Util.ToInt32sRef(v, scratch), ord);
-                ord++;
-            }
-
-            var fst = builder.Finish();
-            if (fst != null)
-            {
-                fst.Save(Data);
-            }
-            Meta.WriteVInt64(ord);
-        }
-
-        public override void AddSortedField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<long?> docToOrd)
-        {
-            // three cases for simulating the old writer:
-            // 1. no missing
-            // 2. missing (and empty string in use): remap ord=-1 -> ord=0
-            // 3. missing (and empty string not in use): remap all ords +1, insert empty string into values
-            bool anyMissing = false;
-            foreach (long? n in docToOrd)
-            {
-                if (n.Value == -1)
-                {
-                    anyMissing = true;
-                    break;
-                }
-            }
-
-            bool hasEmptyString = false;
-            foreach (BytesRef b in values)
-            {
-                hasEmptyString = b.Length == 0;
-                break;
-            }
-
-            if (!anyMissing)
-            {
-                // nothing to do
-            }
-            else if (hasEmptyString)
-            {
-                docToOrd = MissingOrdRemapper.MapMissingToOrd0(docToOrd);
-            }
-            else
-            {
-                docToOrd = MissingOrdRemapper.MapAllOrds(docToOrd);
-                values = MissingOrdRemapper.InsertEmptyValue(values);
-            }
-
-            // write the ordinals as numerics
-            AddNumericField(field, docToOrd, false);
-
-            // write the values as FST
-            WriteFST(field, values);
-        }
-
-        // note: this might not be the most efficient... but its fairly simple
-        public override void AddSortedSetField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<long?> docToOrdCount, IEnumerable<long?> ords)
-        {
-            // write the ordinals as a binary field
-            AddBinaryField(field, new IterableAnonymousInnerClassHelper(this, docToOrdCount, ords));
-
-            // write the values as FST
-            WriteFST(field, values);
-        }
-
-        private class IterableAnonymousInnerClassHelper : IEnumerable<BytesRef>
-        {
-            private readonly Lucene42DocValuesConsumer OuterInstance;
-
-            private IEnumerable<long?> DocToOrdCount;
-            private IEnumerable<long?> Ords;
-
-            public IterableAnonymousInnerClassHelper(Lucene42DocValuesConsumer outerInstance, IEnumerable<long?> docToOrdCount, IEnumerable<long?> ords)
-            {
-                this.OuterInstance = outerInstance;
-                this.DocToOrdCount = docToOrdCount;
-                this.Ords = ords;
-            }
-
-            public IEnumerator<BytesRef> GetEnumerator()
-            {
-                return new SortedSetIterator(DocToOrdCount.GetEnumerator(), Ords.GetEnumerator());
-            }
-
-            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
-            {
-                return GetEnumerator();
-            }
-        }
-
-        // per-document vint-encoded byte[]
-        internal class SortedSetIterator : IEnumerator<BytesRef>
-        {
-            internal byte[] Buffer = new byte[10];
-            internal ByteArrayDataOutput @out = new ByteArrayDataOutput();
-            internal BytesRef @ref = new BytesRef();
-
-            internal readonly IEnumerator<long?> Counts;
-            internal readonly IEnumerator<long?> Ords;
-
-            internal SortedSetIterator(IEnumerator<long?> counts, IEnumerator<long?> ords)
-            {
-                this.Counts = counts;
-                this.Ords = ords;
-            }
-
-            public bool MoveNext()
-            {
-                if (!Counts.MoveNext())
-                {
-                    return false;
-                }
-
-                int count = (int)Counts.Current;
-                int maxSize = count * 9; //worst case
-                if (maxSize > Buffer.Length)
-                {
-                    Buffer = ArrayUtil.Grow(Buffer, maxSize);
-                }
-
-                try
-                {
-                    EncodeValues(count);
-                }
-                catch (IOException bogus)
-                {
-                    throw new Exception(bogus.Message, bogus);
-                }
-
-                @ref.Bytes = Buffer;
-                @ref.Offset = 0;
-                @ref.Length = @out.Position;
-
-                return true;
-            }
-
-            public BytesRef Current
-            {
-                get { return @ref; }
-            }
-
-            object System.Collections.IEnumerator.Current
-            {
-                get { return Current; }
-            }
-
-            // encodes count values to buffer
-            internal virtual void EncodeValues(int count)
-            {
-                @out.Reset(Buffer);
-                long lastOrd = 0;
-                for (int i = 0; i < count; i++)
-                {
-                    Ords.MoveNext();
-                    long ord = Ords.Current.Value;
-                    @out.WriteVInt64(ord - lastOrd);
-                    lastOrd = ord;
-                }
-            }
-
-            public void Reset()
-            {
-                throw new NotImplementedException();
-            }
-
-            public void Dispose()
-            {
-            }
-        }
-    }
-#pragma warning restore 612, 618
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9e2f4c5b/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42FieldInfosWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42FieldInfosWriter.cs b/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42FieldInfosWriter.cs
deleted file mode 100644
index acdae7b..0000000
--- a/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42FieldInfosWriter.cs
+++ /dev/null
@@ -1,145 +0,0 @@
-using System;
-using System.Diagnostics;
-
-namespace Lucene.Net.Codecs.Lucene42
-{
-    using Directory = Lucene.Net.Store.Directory;
-
-    /*
-         * 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.
-         */
-
-    using DocValuesType = Lucene.Net.Index.DocValuesType;
-    using FieldInfo = Lucene.Net.Index.FieldInfo;
-    using FieldInfos = Lucene.Net.Index.FieldInfos;
-    using IndexFileNames = Lucene.Net.Index.IndexFileNames;
-    using IndexOutput = Lucene.Net.Store.IndexOutput;
-    using IndexOptions = Lucene.Net.Index.IndexOptions;
-    using IOContext = Lucene.Net.Store.IOContext;
-    using IOUtils = Lucene.Net.Util.IOUtils;
-
-    /// <summary>
-    /// Lucene 4.2 FieldInfos writer.
-    /// </summary>
-    /// <seealso> cref= Lucene42FieldInfosFormat
-    /// @lucene.experimental </seealso>
-    [Obsolete]
-    public sealed class Lucene42FieldInfosWriter : FieldInfosWriter
-    {
-        /// <summary>
-        /// Sole constructor. </summary>
-        public Lucene42FieldInfosWriter()
-        {
-        }
-
-        public override void Write(Directory directory, string segmentName, string segmentSuffix, FieldInfos infos, IOContext context)
-        {
-            string fileName = IndexFileNames.SegmentFileName(segmentName, "", Lucene42FieldInfosFormat.EXTENSION);
-            IndexOutput output = directory.CreateOutput(fileName, context);
-            bool success = false;
-            try
-            {
-                CodecUtil.WriteHeader(output, Lucene42FieldInfosFormat.CODEC_NAME, Lucene42FieldInfosFormat.FORMAT_CURRENT);
-                output.WriteVInt32(infos.Count);
-                foreach (FieldInfo fi in infos)
-                {
-                    IndexOptions? indexOptions = fi.IndexOptions;
-                    sbyte bits = 0x0;
-                    if (fi.HasVectors)
-                    {
-                        bits |= Lucene42FieldInfosFormat.STORE_TERMVECTOR;
-                    }
-                    if (fi.OmitsNorms)
-                    {
-                        bits |= Lucene42FieldInfosFormat.OMIT_NORMS;
-                    }
-                    if (fi.HasPayloads)
-                    {
-                        bits |= Lucene42FieldInfosFormat.STORE_PAYLOADS;
-                    }
-                    if (fi.IsIndexed)
-                    {
-                        bits |= Lucene42FieldInfosFormat.IS_INDEXED;
-                        Debug.Assert(indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !fi.HasPayloads);
-                        if (indexOptions == IndexOptions.DOCS_ONLY)
-                        {
-                            bits |= Lucene42FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS;
-                        }
-                        else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS)
-                        {
-                            bits |= Lucene42FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS;
-                        }
-                        else if (indexOptions == IndexOptions.DOCS_AND_FREQS)
-                        {
-                            bits |= Lucene42FieldInfosFormat.OMIT_POSITIONS;
-                        }
-                    }
-                    output.WriteString(fi.Name);
-                    output.WriteVInt32(fi.Number);
-                    output.WriteByte((byte)bits);
-
-                    // pack the DV types in one byte
-                    var dv = DocValuesByte(fi.DocValuesType);
-                    var nrm = DocValuesByte(fi.NormType);
-                    Debug.Assert((dv & (~0xF)) == 0 && (nrm & (~0x0F)) == 0);
-                    var val = unchecked((sbyte)(0xff & ((nrm << 4) | dv)));
-                    output.WriteByte((byte)val);
-                    output.WriteStringStringMap(fi.Attributes);
-                }
-                success = true;
-            }
-            finally
-            {
-                if (success)
-                {
-                    output.Dispose();
-                }
-                else
-                {
-                    IOUtils.CloseWhileHandlingException(output);
-                }
-            }
-        }
-
-        private static sbyte DocValuesByte(DocValuesType? type)
-        {
-            if (type == null)
-            {
-                return 0;
-            }
-            else if (type == DocValuesType.NUMERIC)
-            {
-                return 1;
-            }
-            else if (type == DocValuesType.BINARY)
-            {
-                return 2;
-            }
-            else if (type == DocValuesType.SORTED)
-            {
-                return 3;
-            }
-            else if (type == DocValuesType.SORTED_SET)
-            {
-                return 4;
-            }
-            else
-            {
-                throw new InvalidOperationException();
-            }
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9e2f4c5b/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42RWCodec.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42RWCodec.cs b/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42RWCodec.cs
deleted file mode 100644
index 39e3b66..0000000
--- a/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42RWCodec.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-namespace Lucene.Net.Codecs.Lucene42
-{
-    /*
-     * 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.
-     */
-
-    using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-
-    /// <summary>
-    /// Read-write version of <seealso cref="Lucene42Codec"/> for testing.
-    /// </summary>
-#pragma warning disable 612, 618
-    public class Lucene42RWCodec : Lucene42Codec
-    {
-        private readonly DocValuesFormat Dv;
-        private readonly NormsFormat Norms = new Lucene42NormsFormat();
-        private readonly FieldInfosFormat fieldInfosFormat;
-
-        /// <summary>
-        /// LUCENENET specific
-        /// Creates the codec with OldFormatImpersonationIsActive = true.
-        /// </summary>
-        /// <remarks>
-        /// Added so that SPIClassIterator can locate this Codec.  The iterator
-        /// only recognises classes that have empty constructors.
-        /// </remarks>
-        public Lucene42RWCodec()
-            : this(true)
-        { }
-
-        /// <param name="oldFormatImpersonationIsActive">
-        /// LUCENENET specific
-        /// Added to remove dependency on then-static <see cref="LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE"/> 
-        /// </param>
-        public Lucene42RWCodec(bool oldFormatImpersonationIsActive) : base()
-        {
-            Dv = new Lucene42RWDocValuesFormat(oldFormatImpersonationIsActive);
-            fieldInfosFormat = new Lucene42FieldInfosFormatAnonymousInnerClassHelper(oldFormatImpersonationIsActive);
-        }
-
-        private class Lucene42FieldInfosFormatAnonymousInnerClassHelper : Lucene42FieldInfosFormat
-        {
-            private readonly bool _oldFormatImpersonationIsActive;
-
-            /// <param name="oldFormatImpersonationIsActive">
-            /// LUCENENET specific
-            /// Added to remove dependency on then-static <see cref="LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE"/> 
-            /// </param>
-            public Lucene42FieldInfosFormatAnonymousInnerClassHelper(bool oldFormatImpersonationIsActive) : base()
-            {
-                _oldFormatImpersonationIsActive = oldFormatImpersonationIsActive;
-            }
-
-            public override FieldInfosWriter FieldInfosWriter
-            {
-                get
-                {
-                    if (!_oldFormatImpersonationIsActive)
-                    {
-                        return base.FieldInfosWriter;
-                    }
-                    else
-                    {
-                        return new Lucene42FieldInfosWriter();
-                    }
-                }
-            }
-        }
-
-        public override DocValuesFormat GetDocValuesFormatForField(string field)
-        {
-            return Dv;
-        }
-
-        public override NormsFormat NormsFormat
-        {
-            get { return Norms; }
-        }
-
-        public override FieldInfosFormat FieldInfosFormat
-        {
-            get { return fieldInfosFormat; }
-        }
-    }
-#pragma warning restore 612, 618
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9e2f4c5b/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42RWDocValuesFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42RWDocValuesFormat.cs b/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42RWDocValuesFormat.cs
deleted file mode 100644
index 1a29fe6..0000000
--- a/src/Lucene.Net.TestFramework/Codecs/lucene42/Lucene42RWDocValuesFormat.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-namespace Lucene.Net.Codecs.Lucene42
-{
-    using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-
-    /*
-         * 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.
-         */
-
-    using SegmentWriteState = Lucene.Net.Index.SegmentWriteState;
-
-    /// <summary>
-    /// Read-write version of <seealso cref="Lucene42DocValuesFormat"/> for testing.
-    /// </summary>
-#pragma warning disable 612, 618
-    public class Lucene42RWDocValuesFormat : Lucene42DocValuesFormat
-    {
-        private readonly bool _oldFormatImpersonationIsActive;
-
-        /// <summary>
-        /// LUCENENET specific
-        /// Creates the codec with OldFormatImpersonationIsActive = true.
-        /// </summary>
-        /// <remarks>
-        /// Added so that SPIClassIterator can locate this Codec.  The iterator
-        /// only recognises classes that have empty constructors.
-        /// </remarks>
-        public Lucene42RWDocValuesFormat()
-            : this(true)
-        { }
-
-        /// <param name="oldFormatImpersonationIsActive">
-        /// LUCENENET specific
-        /// Added to remove dependency on then-static <see cref="LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE"/> 
-        /// </param>
-        public Lucene42RWDocValuesFormat(bool oldFormatImpersonationIsActive) : base()
-        {
-            _oldFormatImpersonationIsActive = oldFormatImpersonationIsActive;
-        }
-
-        public override DocValuesConsumer FieldsConsumer(SegmentWriteState state)
-        {
-            if (!_oldFormatImpersonationIsActive)
-            {
-                return base.FieldsConsumer(state);
-            }
-            else
-            {
-                // note: we choose DEFAULT here (its reasonably fast, and for small bpv has tiny waste)
-                return new Lucene42DocValuesConsumer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION, m_acceptableOverheadRatio);
-            }
-        }
-    }
-#pragma warning restore 612, 618
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9e2f4c5b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
index 64cf3e5..c7ac221 100644
--- a/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
+++ b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
@@ -232,16 +232,16 @@
     <Compile Include="Codecs\Lucene41\Lucene41RWCodec.cs">
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="Codecs\lucene42\Lucene42DocValuesConsumer.cs">
+    <Compile Include="Codecs\Lucene42\Lucene42DocValuesConsumer.cs">
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="Codecs\lucene42\Lucene42FieldInfosWriter.cs">
+    <Compile Include="Codecs\Lucene42\Lucene42FieldInfosWriter.cs">
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="Codecs\lucene42\Lucene42RWCodec.cs">
+    <Compile Include="Codecs\Lucene42\Lucene42RWCodec.cs">
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="Codecs\lucene42\Lucene42RWDocValuesFormat.cs">
+    <Compile Include="Codecs\Lucene42\Lucene42RWDocValuesFormat.cs">
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="Codecs\lucene45\Lucene45RWCodec.cs">


Mime
View raw message