lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [1/2] lucenenet git commit: Update for SimpleText Codec from changed to Lucene.Net Core, and updates to Memory codec
Date Mon, 19 Jan 2015 11:58:31 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master a83698970 -> 2d850fd71


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2d850fd7/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs b/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
index 0ebed7f..19d71d2 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
@@ -8,7 +8,7 @@ using Lucene.Net.Util;
 namespace Lucene.Net.Codecs.Memory
 {
 
-	/*
+    /*
 	 * 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.
@@ -25,635 +25,635 @@ namespace Lucene.Net.Codecs.Memory
 	 * limitations under the License.
 	 */
 
-	/// <summary>
-	/// Reader for <seealso cref="DirectDocValuesFormat"/>
-	/// </summary>
-
-	internal class DirectDocValuesProducer : DocValuesProducer
-	{
-	  // metadata maps (just file pointers and minimal stuff)
-	  private readonly IDictionary<int?, NumericEntry> numerics = new Dictionary<int?, NumericEntry>();
-	  private readonly IDictionary<int?, BinaryEntry> binaries = new Dictionary<int?, BinaryEntry>();
-	  private readonly IDictionary<int?, SortedEntry> sorteds = new Dictionary<int?, SortedEntry>();
-	  private readonly IDictionary<int?, SortedSetEntry> sortedSets = new Dictionary<int?, SortedSetEntry>();
-	  private readonly IndexInput data;
-
-	  // ram instances we have already loaded
-	  private readonly IDictionary<int?, NumericDocValues> numericInstances = new Dictionary<int?, NumericDocValues>();
-	  private readonly IDictionary<int?, BinaryDocValues> binaryInstances = new Dictionary<int?, BinaryDocValues>();
-	  private readonly IDictionary<int?, SortedDocValues> sortedInstances = new Dictionary<int?, SortedDocValues>();
-	  private readonly IDictionary<int?, SortedSetRawValues> sortedSetInstances = new Dictionary<int?, SortedSetRawValues>();
-	  private readonly IDictionary<int?, Bits> docsWithFieldInstances = new Dictionary<int?, Bits>();
-
-	  private readonly int maxDoc;
-	  private readonly AtomicLong ramBytesUsed;
-	  private readonly int version;
-
-	  internal const sbyte NUMBER = 0;
-	  internal const sbyte BYTES = 1;
-	  internal const sbyte SORTED = 2;
-	  internal const sbyte SORTED_SET = 3;
-
-	  internal const int VERSION_START = 0;
-	  internal const int VERSION_CHECKSUM = 1;
-	  internal const int VERSION_CURRENT = VERSION_CHECKSUM;
-
-	  internal DirectDocValuesProducer(SegmentReadState state, string dataCodec, string dataExtension, string metaCodec, string metaExtension)
-	  {
-		maxDoc = state.SegmentInfo.DocCount;
-		string metaName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, metaExtension);
-		// read in the entries from the metadata file.
-		ChecksumIndexInput @in = state.Directory.OpenChecksumInput(metaName, state.Context);
-		ramBytesUsed = new AtomicLong(RamUsageEstimator.ShallowSizeOfInstance(this.GetType()));
-		bool success = false;
-		try
-		{
-		  version = CodecUtil.CheckHeader(@in, metaCodec, VERSION_START, VERSION_CURRENT);
-		  ReadFields(@in);
-
-		  if (version >= VERSION_CHECKSUM)
-		  {
-			CodecUtil.CheckFooter(@in);
-		  }
-		  else
-		  {
-			CodecUtil.CheckEOF(@in);
-		  }
-		  success = true;
-		}
-		finally
-		{
-		  if (success)
-		  {
-			IOUtils.Close(@in);
-		  }
-		  else
-		  {
-			IOUtils.CloseWhileHandlingException(@in);
-		  }
-		}
-
-		success = false;
-		try
-		{
-		  string dataName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, dataExtension);
-		  data = state.Directory.OpenInput(dataName, state.Context);
-		  int version2 = CodecUtil.CheckHeader(data, dataCodec, VERSION_START, VERSION_CURRENT);
-		  if (version != version2)
-		  {
-			throw new CorruptIndexException("Format versions mismatch");
-		  }
-
-		  success = true;
-		}
-		finally
-		{
-		  if (!success)
-		  {
-			IOUtils.CloseWhileHandlingException(this.data);
-		  }
-		}
-	  }
-
-	  private static NumericEntry ReadNumericEntry(IndexInput meta)
-	  {
-		var entry = new NumericEntry {offset = meta.ReadLong(), count = meta.ReadInt(), missingOffset = meta.ReadLong()};
-	      if (entry.missingOffset != -1)
-		{
-		  entry.missingBytes = meta.ReadLong();
-		}
-		else
-		{
-		  entry.missingBytes = 0;
-		}
-		entry.byteWidth = meta.ReadByte();
-
-		return entry;
-	  }
-
-	  private BinaryEntry readBinaryEntry(IndexInput meta)
-	  {
-		var entry = new BinaryEntry();
-		entry.offset = meta.ReadLong();
-		entry.numBytes = meta.ReadInt();
-		entry.count = meta.ReadInt();
-		entry.missingOffset = meta.ReadLong();
-		if (entry.missingOffset != -1)
-		{
-		  entry.missingBytes = meta.ReadLong();
-		}
-		else
-		{
-		  entry.missingBytes = 0;
-		}
-
-		return entry;
-	  }
-
-	  private SortedEntry ReadSortedEntry(IndexInput meta)
-	  {
-		var entry = new SortedEntry();
-		entry.docToOrd = ReadNumericEntry(meta);
-		entry.values = ReadBinaryEntry(meta);
-		return entry;
-	  }
-
-	  private SortedSetEntry ReadSortedSetEntry(IndexInput meta)
-	  {
-		var entry = new SortedSetEntry();
-		entry.docToOrdAddress = ReadNumericEntry(meta);
-		entry.ords = ReadNumericEntry(meta);
-		entry.values = readBinaryEntry(meta);
-		return entry;
-	  }
-
-	  private void ReadFields(IndexInput meta)
-	  {
-		int fieldNumber = meta.ReadVInt();
-		while (fieldNumber != -1)
-		{
-		  int fieldType = meta.ReadByte();
-		  if (fieldType == NUMBER)
-		  {
-			numerics[fieldNumber] = ReadNumericEntry(meta);
-		  }
-		  else if (fieldType == BYTES)
-		  {
-			binaries[fieldNumber] = readBinaryEntry(meta);
-		  }
-		  else if (fieldType == SORTED)
-		  {
-			sorteds[fieldNumber] = ReadSortedEntry(meta);
-		  }
-		  else if (fieldType == SORTED_SET)
-		  {
-			sortedSets[fieldNumber] = ReadSortedSetEntry(meta);
-		  }
-		  else
-		  {
-			throw new CorruptIndexException("invalid entry type: " + fieldType + ", input=" + meta);
-		  }
-		  fieldNumber = meta.ReadVInt();
-		}
-	  }
-
-	  public override long RamBytesUsed()
-	  {
-		return ramBytesUsed.Get();
-	  }
-
-	  public override void CheckIntegrity()
-	  {
-		if (version >= VERSION_CHECKSUM)
-		{
-		  CodecUtil.ChecksumEntireFile(data);
-		}
-	  }
-
-	  public override NumericDocValues GetNumeric(FieldInfo field)
-	  {
-		  lock (this)
-		  {
-			var instance = numericInstances[field.Number];
-			if (instance == null)
-			{
-			  // Lazy load
-			  instance = LoadNumeric(numerics[field.Number]);
-			  numericInstances[field.Number] = instance;
-			}
-			return instance;
-		  }
-	  }
-
-	  private NumericDocValues LoadNumeric(NumericEntry entry)
-	  {
-		data.Seek(entry.offset + entry.missingBytes);
-		switch (entry.byteWidth)
-		{
-		case 1:
-		{
-			var values = new byte[entry.count];
-			data.ReadBytes(values, 0, entry.count);
-			ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
-			return new NumericDocValuesAnonymousInnerClassHelper(values);
-		}
-
-		case 2:
-		{
-			var values = new short[entry.count];
-			for (int i = 0;i < entry.count;i++)
-			{
-			  values[i] = data.ReadShort();
-			}
-			ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
-			return new NumericDocValuesAnonymousInnerClassHelper2(this, values);
-		}
-
-		case 4:
-		{
-			var values = new int[entry.count];
-			for (var i = 0;i < entry.count;i++)
-			{
-			  values[i] = data.ReadInt();
-			}
-			ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
-			return new NumericDocValuesAnonymousInnerClassHelper3(values);
-		}
-
-		case 8:
-		{
-			var values = new long[entry.count];
-			for (int i = 0;i < entry.count;i++)
-			{
-			  values[i] = data.ReadLong();
-			}
-			ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
-			return new NumericDocValuesAnonymousInnerClassHelper4(values);
-		}
-
-		default:
-		  throw new AssertionError();
-		}
-	  }
-
-	  private class NumericDocValuesAnonymousInnerClassHelper : NumericDocValues
-	  {
-	      private readonly byte[] values;
-
-		  public NumericDocValuesAnonymousInnerClassHelper(byte[] values)
-		  {
-		      this.values = values;
-		  }
-
-		  public override long Get(int idx)
-		  {
-			return values[idx];
-		  }
-	  }
-
-	  private class NumericDocValuesAnonymousInnerClassHelper2 : NumericDocValues
-	  {
-	      private readonly short[] values;
-
-		  public NumericDocValuesAnonymousInnerClassHelper2(DirectDocValuesProducer outerInstance, short[] values)
-		  {
-		      this.values = values;
-		  }
-
-		  public override long Get(int idx)
-		  {
-			return values[idx];
-		  }
-	  }
-
-	  private class NumericDocValuesAnonymousInnerClassHelper3 : NumericDocValues
-	  {
-	      private readonly int[] values;
-
-		  public NumericDocValuesAnonymousInnerClassHelper3(int[] values)
-		  {
-		      this.values = values;
-		  }
-
-		  public override long Get(int idx)
-		  {
-			return values[idx];
-		  }
-	  }
-
-	  private class NumericDocValuesAnonymousInnerClassHelper4 : NumericDocValues
-	  {
-	      private readonly long[] values;
-
-		  public NumericDocValuesAnonymousInnerClassHelper4(long[] values)
-		  {
-		      this.values = values;
-		  }
-
-		  public override long Get(int idx)
-		  {
-			return values[idx];
-		  }
-	  }
-
-	  public override BinaryDocValues GetBinary(FieldInfo field)
-	  {
-		  lock (this)
-		  {
-			var instance = binaryInstances[field.Number];
-			if (instance == null)
-			{
-			  // Lazy load
-			  instance = LoadBinary(binaries[field.Number]);
-			  binaryInstances[field.Number] = instance;
-			}
-			return instance;
-		  }
-	  }
-
-	  private BinaryDocValues LoadBinary(BinaryEntry entry)
-	  {
-		data.Seek(entry.offset);
-		var bytes = new byte[entry.numBytes];
-		data.ReadBytes(bytes, 0, entry.numBytes);
-		data.Seek(entry.offset + entry.numBytes + entry.missingBytes);
-
-		var address = new int[entry.count + 1];
-		for (int i = 0;i < entry.count;i++)
-		{
-		  address[i] = data.ReadInt();
-		}
-		address[entry.count] = data.ReadInt();
-
-		ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(bytes) + RamUsageEstimator.SizeOf(address));
-
-		return new BinaryDocValuesAnonymousInnerClassHelper(bytes, address);
-	  }
-
-	  private class BinaryDocValuesAnonymousInnerClassHelper : BinaryDocValues
-	  {
-	      private readonly byte[] bytes;
-		  private readonly int[] address;
-
-		  public BinaryDocValuesAnonymousInnerClassHelper(byte[] bytes, int[] address)
-		  {
-		      this.bytes = bytes;
-			  this.address = address;
-		  }
-
-		  public override void Get(int docID, BytesRef result)
-		  {
-			result.Bytes = bytes;
-			result.Offset = address[docID];
-			result.Length = address[docID + 1] - result.Offset;
-		  }
-	  }
-
-	  public override SortedDocValues GetSorted(FieldInfo field)
-	  {
-		  lock (this)
-		  {
-			var instance = sortedInstances[field.Number];
-			if (instance == null)
-			{
-			  // Lazy load
-			  instance = LoadSorted(field);
-			  sortedInstances[field.Number] = instance;
-			}
-			return instance;
-		  }
-	  }
-
-	  private SortedDocValues LoadSorted(FieldInfo field)
-	  {
-		SortedEntry entry = sorteds[field.Number];
-		NumericDocValues docToOrd = LoadNumeric(entry.docToOrd);
-		BinaryDocValues values = LoadBinary(entry.values);
-
-		return new SortedDocValuesAnonymousInnerClassHelper(this, entry, docToOrd, values);
-	  }
-
-	  private class SortedDocValuesAnonymousInnerClassHelper : SortedDocValues
-	  {
-		  private readonly DirectDocValuesProducer outerInstance;
-
-		  private readonly SortedEntry entry;
-		  private readonly NumericDocValues docToOrd;
-		  private readonly BinaryDocValues values;
-
-		  public SortedDocValuesAnonymousInnerClassHelper(DirectDocValuesProducer outerInstance, SortedEntry entry, NumericDocValues docToOrd, BinaryDocValues values)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.entry = entry;
-			  this.docToOrd = docToOrd;
-			  this.values = values;
-		  }
-
-
-		  public override int GetOrd(int docID)
-		  {
-			return (int) docToOrd.Get(docID);
-		  }
-
-		  public override void LookupOrd(int ord, BytesRef result)
-		  {
-			values.Get(ord, result);
-		  }
-
-		  public override int ValueCount
-		  {
-			  get
-			  {
-				return entry.values.count;
-			  }
-		  }
-
-		  // Leave lookupTerm to super's binary search
-
-		  // Leave termsEnum to super
-	  }
-
-	  public override SortedSetDocValues GetSortedSet(FieldInfo field)
-	  {
-		  lock (this)
-		  {
-			var instance = sortedSetInstances[field.Number];
-			var entry = sortedSets[field.Number];
-			if (instance == null)
-			{
-			  // Lazy load
-			  instance = LoadSortedSet(entry);
-			  sortedSetInstances[field.Number] = instance;
-			}
-        
-			var docToOrdAddress = instance.docToOrdAddress;
-			var ords = instance.ords;
-			var values = instance.values;
-        
-			// Must make a new instance since the iterator has state:
-			return new RandomAccessOrdsAnonymousInnerClassHelper(this, entry, docToOrdAddress, ords, values);
-		  }
-	  }
-
-	  private class RandomAccessOrdsAnonymousInnerClassHelper : RandomAccessOrds
-	  {
-	      private readonly SortedSetEntry entry;
-		  private readonly NumericDocValues docToOrdAddress;
-		  private readonly NumericDocValues ords;
-		  private readonly BinaryDocValues values;
-
-		  public RandomAccessOrdsAnonymousInnerClassHelper(DirectDocValuesProducer outerInstance, SortedSetEntry entry, NumericDocValues docToOrdAddress, NumericDocValues ords, BinaryDocValues values)
-		  {
-		      this.entry = entry;
-			  this.docToOrdAddress = docToOrdAddress;
-			  this.ords = ords;
-			  this.values = values;
-		  }
-
-	      private int ordStart;
-	      private int ordUpto;
-	      private int ordLimit;
-
-		  public override long NextOrd()
-		  {
-			if (ordUpto == ordLimit)
-			{
-			  return NO_MORE_ORDS;
-			}
-			else
-			{
-			  return ords.Get(ordUpto++);
-			}
-		  }
-
-		  public override int Document
-		  {
-			  set
-			  {
-				ordStart = ordUpto = (int) docToOrdAddress.Get(value);
-				ordLimit = (int) docToOrdAddress.Get(value+1);
-			  }
-		  }
-
-		  public override void LookupOrd(long ord, BytesRef result)
-		  {
-			values.Get((int) ord, result);
-		  }
-
-		  public override long ValueCount
-		  {
-			  get
-			  {
-				return entry.values.count;
-			  }
-		  }
-
-		  public override long OrdAt(int index)
-		  {
-			return ords.Get(ordStart + index);
-		  }
-
-		  public override int Cardinality()
-		  {
-			return ordLimit - ordStart;
-		  }
-
-		  // Leave lookupTerm to super's binary search
-
-		  // Leave termsEnum to super
-	  }
-
-	  private SortedSetRawValues LoadSortedSet(SortedSetEntry entry)
-	  {
-		var instance = new SortedSetRawValues();
-		instance.docToOrdAddress = LoadNumeric(entry.docToOrdAddress);
-		instance.ords = LoadNumeric(entry.ords);
-		instance.values = LoadBinary(entry.values);
-		return instance;
-	  }
-
-	  private Bits GetMissingBits(int fieldNumber, long offset, long length)
-	  {
-		if (offset == -1)
-		{
-		  return new Bits_MatchAllBits(maxDoc);
-		}
-		else
-		{
-		  Bits instance;
-		  lock (this)
-		  {
-			instance = docsWithFieldInstances[fieldNumber];
-			if (instance == null)
-			{
-			  var data = (IndexInput)this.data.Clone();
-			  data.Seek(offset);
-			  Debug.Assert(length % 8 == 0);
-			  var bits = new long[(int) length >> 3];
-			  for (var i = 0; i < bits.Length; i++)
-			  {
-				bits[i] = data.ReadLong();
-			  }
-			  instance = new FixedBitSet(bits, maxDoc);
-			  docsWithFieldInstances[fieldNumber] = instance;
-			}
-		  }
-		  return instance;
-		}
-	  }
-
-	  public override Bits GetDocsWithField(FieldInfo field)
-	  {
-		switch (field.DocValuesType)
-		{
-		  case SORTED_SET:
-			return DocValues.DocsWithValue(GetSortedSet(field), maxDoc);
-		  case SORTED:
-			return DocValues.DocsWithValue(GetSorted(field), maxDoc);
-		  case BINARY:
-			BinaryEntry be = binaries[field.Number];
-			return GetMissingBits(field.Number, be.missingOffset, be.missingBytes);
-		  case NUMERIC:
-			NumericEntry ne = numerics[field.Number];
-			return GetMissingBits(field.Number, ne.missingOffset, ne.missingBytes);
-		  default:
-			throw new AssertionError();
-		}
-	  }
-
-	    protected override void Dispose(bool disposing)
-	    {
-	        if (disposing)
-	            data.Dispose();
-	    }
-
-	    internal class SortedSetRawValues
-	  {
-		internal NumericDocValues docToOrdAddress;
-		internal NumericDocValues ords;
-		internal BinaryDocValues values;
-	  }
-
-	  internal class NumericEntry
-	  {
-		internal long offset;
-		internal int count;
-		internal long missingOffset;
-		internal long missingBytes;
-		internal byte byteWidth;
-		internal int packedIntsVersion;
-	  }
-
-	  internal class BinaryEntry
-	  {
-		internal long offset;
-		internal long missingOffset;
-		internal long missingBytes;
-		internal int count;
-		internal int numBytes;
-		internal int minLength;
-		internal int maxLength;
-		internal int packedIntsVersion;
-		internal int blockSize;
-	  }
-
-	  internal class SortedEntry
-	  {
-		internal NumericEntry docToOrd;
-		internal BinaryEntry values;
-	  }
-
-	  internal class SortedSetEntry
-	  {
-		internal NumericEntry docToOrdAddress;
-		internal NumericEntry ords;
-		internal BinaryEntry values;
-	  }
-
-	  internal class FSTEntry
-	  {
-		internal long offset;
-		internal long numOrds;
-	  }
-	}
+    /// <summary>
+    /// Reader for <seealso cref="DirectDocValuesFormat"/>
+    /// </summary>
+
+    internal class DirectDocValuesProducer : DocValuesProducer
+    {
+        // metadata maps (just file pointers and minimal stuff)
+        private readonly IDictionary<int?, NumericEntry> numerics = new Dictionary<int?, NumericEntry>();
+        private readonly IDictionary<int?, BinaryEntry> binaries = new Dictionary<int?, BinaryEntry>();
+        private readonly IDictionary<int?, SortedEntry> sorteds = new Dictionary<int?, SortedEntry>();
+        private readonly IDictionary<int?, SortedSetEntry> sortedSets = new Dictionary<int?, SortedSetEntry>();
+        private readonly IndexInput data;
+
+        // ram instances we have already loaded
+        private readonly IDictionary<int?, NumericDocValues> numericInstances = new Dictionary<int?, NumericDocValues>();
+        private readonly IDictionary<int?, BinaryDocValues> binaryInstances = new Dictionary<int?, BinaryDocValues>();
+        private readonly IDictionary<int?, SortedDocValues> sortedInstances = new Dictionary<int?, SortedDocValues>();
+        private readonly IDictionary<int?, SortedSetRawValues> sortedSetInstances = new Dictionary<int?, SortedSetRawValues>();
+        private readonly IDictionary<int?, Bits> docsWithFieldInstances = new Dictionary<int?, Bits>();
+
+        private readonly int maxDoc;
+        private readonly AtomicLong ramBytesUsed;
+        private readonly int version;
+
+        internal const sbyte NUMBER = 0;
+        internal const sbyte BYTES = 1;
+        internal const sbyte SORTED = 2;
+        internal const sbyte SORTED_SET = 3;
+
+        internal const int VERSION_START = 0;
+        internal const int VERSION_CHECKSUM = 1;
+        internal const int VERSION_CURRENT = VERSION_CHECKSUM;
+
+        internal DirectDocValuesProducer(SegmentReadState state, string dataCodec, string dataExtension, string metaCodec, string metaExtension)
+        {
+            maxDoc = state.SegmentInfo.DocCount;
+            string metaName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, metaExtension);
+            // read in the entries from the metadata file.
+            ChecksumIndexInput @in = state.Directory.OpenChecksumInput(metaName, state.Context);
+            ramBytesUsed = new AtomicLong(RamUsageEstimator.ShallowSizeOfInstance(this.GetType()));
+            bool success = false;
+            try
+            {
+                version = CodecUtil.CheckHeader(@in, metaCodec, VERSION_START, VERSION_CURRENT);
+                ReadFields(@in);
+
+                if (version >= VERSION_CHECKSUM)
+                {
+                    CodecUtil.CheckFooter(@in);
+                }
+                else
+                {
+                    CodecUtil.CheckEOF(@in);
+                }
+                success = true;
+            }
+            finally
+            {
+                if (success)
+                {
+                    IOUtils.Close(@in);
+                }
+                else
+                {
+                    IOUtils.CloseWhileHandlingException(@in);
+                }
+            }
+
+            success = false;
+            try
+            {
+                string dataName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, dataExtension);
+                data = state.Directory.OpenInput(dataName, state.Context);
+                int version2 = CodecUtil.CheckHeader(data, dataCodec, VERSION_START, VERSION_CURRENT);
+                if (version != version2)
+                {
+                    throw new CorruptIndexException("Format versions mismatch");
+                }
+
+                success = true;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    IOUtils.CloseWhileHandlingException(this.data);
+                }
+            }
+        }
+
+        private static NumericEntry ReadNumericEntry(IndexInput meta)
+        {
+            var entry = new NumericEntry { offset = meta.ReadLong(), count = meta.ReadInt(), missingOffset = meta.ReadLong() };
+            if (entry.missingOffset != -1)
+            {
+                entry.missingBytes = meta.ReadLong();
+            }
+            else
+            {
+                entry.missingBytes = 0;
+            }
+            entry.byteWidth = meta.ReadByte();
+
+            return entry;
+        }
+
+        private BinaryEntry ReadBinaryEntry(IndexInput meta)
+        {
+            var entry = new BinaryEntry();
+            entry.offset = meta.ReadLong();
+            entry.numBytes = meta.ReadInt();
+            entry.count = meta.ReadInt();
+            entry.missingOffset = meta.ReadLong();
+            if (entry.missingOffset != -1)
+            {
+                entry.missingBytes = meta.ReadLong();
+            }
+            else
+            {
+                entry.missingBytes = 0;
+            }
+
+            return entry;
+        }
+
+        private SortedEntry ReadSortedEntry(IndexInput meta)
+        {
+            var entry = new SortedEntry();
+            entry.docToOrd = ReadNumericEntry(meta);
+            entry.values = ReadBinaryEntry(meta);
+            return entry;
+        }
+
+        private SortedSetEntry ReadSortedSetEntry(IndexInput meta)
+        {
+            var entry = new SortedSetEntry();
+            entry.docToOrdAddress = ReadNumericEntry(meta);
+            entry.ords = ReadNumericEntry(meta);
+            entry.values = ReadBinaryEntry(meta);
+            return entry;
+        }
+
+        private void ReadFields(IndexInput meta)
+        {
+            int fieldNumber = meta.ReadVInt();
+            while (fieldNumber != -1)
+            {
+                int fieldType = meta.ReadByte();
+                if (fieldType == NUMBER)
+                {
+                    numerics[fieldNumber] = ReadNumericEntry(meta);
+                }
+                else if (fieldType == BYTES)
+                {
+                    binaries[fieldNumber] = ReadBinaryEntry(meta);
+                }
+                else if (fieldType == SORTED)
+                {
+                    sorteds[fieldNumber] = ReadSortedEntry(meta);
+                }
+                else if (fieldType == SORTED_SET)
+                {
+                    sortedSets[fieldNumber] = ReadSortedSetEntry(meta);
+                }
+                else
+                {
+                    throw new CorruptIndexException("invalid entry type: " + fieldType + ", input=" + meta);
+                }
+                fieldNumber = meta.ReadVInt();
+            }
+        }
+
+        public override long RamBytesUsed()
+        {
+            return ramBytesUsed.Get();
+        }
+
+        public override void CheckIntegrity()
+        {
+            if (version >= VERSION_CHECKSUM)
+            {
+                CodecUtil.ChecksumEntireFile(data);
+            }
+        }
+
+        public override NumericDocValues GetNumeric(FieldInfo field)
+        {
+            lock (this)
+            {
+                var instance = numericInstances[field.Number];
+                if (instance == null)
+                {
+                    // Lazy load
+                    instance = LoadNumeric(numerics[field.Number]);
+                    numericInstances[field.Number] = instance;
+                }
+                return instance;
+            }
+        }
+
+        private NumericDocValues LoadNumeric(NumericEntry entry)
+        {
+            data.Seek(entry.offset + entry.missingBytes);
+            switch (entry.byteWidth)
+            {
+                case 1:
+                    {
+                        var values = new byte[entry.count];
+                        data.ReadBytes(values, 0, entry.count);
+                        ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
+                        return new NumericDocValuesAnonymousInnerClassHelper(values);
+                    }
+
+                case 2:
+                    {
+                        var values = new short[entry.count];
+                        for (int i = 0; i < entry.count; i++)
+                        {
+                            values[i] = data.ReadShort();
+                        }
+                        ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
+                        return new NumericDocValuesAnonymousInnerClassHelper2(this, values);
+                    }
+
+                case 4:
+                    {
+                        var values = new int[entry.count];
+                        for (var i = 0; i < entry.count; i++)
+                        {
+                            values[i] = data.ReadInt();
+                        }
+                        ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
+                        return new NumericDocValuesAnonymousInnerClassHelper3(values);
+                    }
+
+                case 8:
+                    {
+                        var values = new long[entry.count];
+                        for (int i = 0; i < entry.count; i++)
+                        {
+                            values[i] = data.ReadLong();
+                        }
+                        ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(values));
+                        return new NumericDocValuesAnonymousInnerClassHelper4(values);
+                    }
+
+                default:
+                    throw new System.InvalidOperationException();
+            }
+        }
+
+        private class NumericDocValuesAnonymousInnerClassHelper : NumericDocValues
+        {
+            private readonly byte[] values;
+
+            public NumericDocValuesAnonymousInnerClassHelper(byte[] values)
+            {
+                this.values = values;
+            }
+
+            public override long Get(int idx)
+            {
+                return values[idx];
+            }
+        }
+
+        private class NumericDocValuesAnonymousInnerClassHelper2 : NumericDocValues
+        {
+            private readonly short[] values;
+
+            public NumericDocValuesAnonymousInnerClassHelper2(DirectDocValuesProducer outerInstance, short[] values)
+            {
+                this.values = values;
+            }
+
+            public override long Get(int idx)
+            {
+                return values[idx];
+            }
+        }
+
+        private class NumericDocValuesAnonymousInnerClassHelper3 : NumericDocValues
+        {
+            private readonly int[] values;
+
+            public NumericDocValuesAnonymousInnerClassHelper3(int[] values)
+            {
+                this.values = values;
+            }
+
+            public override long Get(int idx)
+            {
+                return values[idx];
+            }
+        }
+
+        private class NumericDocValuesAnonymousInnerClassHelper4 : NumericDocValues
+        {
+            private readonly long[] values;
+
+            public NumericDocValuesAnonymousInnerClassHelper4(long[] values)
+            {
+                this.values = values;
+            }
+
+            public override long Get(int idx)
+            {
+                return values[idx];
+            }
+        }
+
+        public override BinaryDocValues GetBinary(FieldInfo field)
+        {
+            lock (this)
+            {
+                var instance = binaryInstances[field.Number];
+                if (instance == null)
+                {
+                    // Lazy load
+                    instance = LoadBinary(binaries[field.Number]);
+                    binaryInstances[field.Number] = instance;
+                }
+                return instance;
+            }
+        }
+
+        private BinaryDocValues LoadBinary(BinaryEntry entry)
+        {
+            data.Seek(entry.offset);
+            var bytes = new byte[entry.numBytes];
+            data.ReadBytes(bytes, 0, entry.numBytes);
+            data.Seek(entry.offset + entry.numBytes + entry.missingBytes);
+
+            var address = new int[entry.count + 1];
+            for (int i = 0; i < entry.count; i++)
+            {
+                address[i] = data.ReadInt();
+            }
+            address[entry.count] = data.ReadInt();
+
+            ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(bytes) + RamUsageEstimator.SizeOf(address));
+
+            return new BinaryDocValuesAnonymousInnerClassHelper(bytes, address);
+        }
+
+        private class BinaryDocValuesAnonymousInnerClassHelper : BinaryDocValues
+        {
+            private readonly byte[] bytes;
+            private readonly int[] address;
+
+            public BinaryDocValuesAnonymousInnerClassHelper(byte[] bytes, int[] address)
+            {
+                this.bytes = bytes;
+                this.address = address;
+            }
+
+            public override void Get(int docID, BytesRef result)
+            {
+                result.Bytes = bytes;
+                result.Offset = address[docID];
+                result.Length = address[docID + 1] - result.Offset;
+            }
+        }
+
+        public override SortedDocValues GetSorted(FieldInfo field)
+        {
+            lock (this)
+            {
+                var instance = sortedInstances[field.Number];
+                if (instance == null)
+                {
+                    // Lazy load
+                    instance = LoadSorted(field);
+                    sortedInstances[field.Number] = instance;
+                }
+                return instance;
+            }
+        }
+
+        private SortedDocValues LoadSorted(FieldInfo field)
+        {
+            SortedEntry entry = sorteds[field.Number];
+            NumericDocValues docToOrd = LoadNumeric(entry.docToOrd);
+            BinaryDocValues values = LoadBinary(entry.values);
+
+            return new SortedDocValuesAnonymousInnerClassHelper(this, entry, docToOrd, values);
+        }
+
+        private class SortedDocValuesAnonymousInnerClassHelper : SortedDocValues
+        {
+            private readonly DirectDocValuesProducer outerInstance;
+
+            private readonly SortedEntry entry;
+            private readonly NumericDocValues docToOrd;
+            private readonly BinaryDocValues values;
+
+            public SortedDocValuesAnonymousInnerClassHelper(DirectDocValuesProducer outerInstance, SortedEntry entry, NumericDocValues docToOrd, BinaryDocValues values)
+            {
+                this.outerInstance = outerInstance;
+                this.entry = entry;
+                this.docToOrd = docToOrd;
+                this.values = values;
+            }
+
+
+            public override int GetOrd(int docID)
+            {
+                return (int)docToOrd.Get(docID);
+            }
+
+            public override void LookupOrd(int ord, BytesRef result)
+            {
+                values.Get(ord, result);
+            }
+
+            public override int ValueCount
+            {
+                get
+                {
+                    return entry.values.count;
+                }
+            }
+
+            // Leave lookupTerm to super's binary search
+
+            // Leave termsEnum to super
+        }
+
+        public override SortedSetDocValues GetSortedSet(FieldInfo field)
+        {
+            lock (this)
+            {
+                var instance = sortedSetInstances[field.Number];
+                var entry = sortedSets[field.Number];
+                if (instance == null)
+                {
+                    // Lazy load
+                    instance = LoadSortedSet(entry);
+                    sortedSetInstances[field.Number] = instance;
+                }
+
+                var docToOrdAddress = instance.docToOrdAddress;
+                var ords = instance.ords;
+                var values = instance.values;
+
+                // Must make a new instance since the iterator has state:
+                return new RandomAccessOrdsAnonymousInnerClassHelper(this, entry, docToOrdAddress, ords, values);
+            }
+        }
+
+        private class RandomAccessOrdsAnonymousInnerClassHelper : RandomAccessOrds
+        {
+            private readonly SortedSetEntry entry;
+            private readonly NumericDocValues docToOrdAddress;
+            private readonly NumericDocValues ords;
+            private readonly BinaryDocValues values;
+
+            public RandomAccessOrdsAnonymousInnerClassHelper(DirectDocValuesProducer outerInstance, SortedSetEntry entry, NumericDocValues docToOrdAddress, NumericDocValues ords, BinaryDocValues values)
+            {
+                this.entry = entry;
+                this.docToOrdAddress = docToOrdAddress;
+                this.ords = ords;
+                this.values = values;
+            }
+
+            private int ordStart;
+            private int ordUpto;
+            private int ordLimit;
+
+            public override long NextOrd()
+            {
+                if (ordUpto == ordLimit)
+                {
+                    return NO_MORE_ORDS;
+                }
+                else
+                {
+                    return ords.Get(ordUpto++);
+                }
+            }
+
+            public override int Document
+            {
+                set
+                {
+                    ordStart = ordUpto = (int)docToOrdAddress.Get(value);
+                    ordLimit = (int)docToOrdAddress.Get(value + 1);
+                }
+            }
+
+            public override void LookupOrd(long ord, BytesRef result)
+            {
+                values.Get((int)ord, result);
+            }
+
+            public override long ValueCount
+            {
+                get
+                {
+                    return entry.values.count;
+                }
+            }
+
+            public override long OrdAt(int index)
+            {
+                return ords.Get(ordStart + index);
+            }
+
+            public override int Cardinality()
+            {
+                return ordLimit - ordStart;
+            }
+
+            // Leave lookupTerm to super's binary search
+
+            // Leave termsEnum to super
+        }
+
+        private SortedSetRawValues LoadSortedSet(SortedSetEntry entry)
+        {
+            var instance = new SortedSetRawValues();
+            instance.docToOrdAddress = LoadNumeric(entry.docToOrdAddress);
+            instance.ords = LoadNumeric(entry.ords);
+            instance.values = LoadBinary(entry.values);
+            return instance;
+        }
+
+        private Bits GetMissingBits(int fieldNumber, long offset, long length)
+        {
+            if (offset == -1)
+            {
+                return new Bits_MatchAllBits(maxDoc);
+            }
+            else
+            {
+                Bits instance;
+                lock (this)
+                {
+                    instance = docsWithFieldInstances[fieldNumber];
+                    if (instance == null)
+                    {
+                        var data = (IndexInput)this.data.Clone();
+                        data.Seek(offset);
+                        Debug.Assert(length % 8 == 0);
+                        var bits = new long[(int)length >> 3];
+                        for (var i = 0; i < bits.Length; i++)
+                        {
+                            bits[i] = data.ReadLong();
+                        }
+                        instance = new FixedBitSet(bits, maxDoc);
+                        docsWithFieldInstances[fieldNumber] = instance;
+                    }
+                }
+                return instance;
+            }
+        }
+
+        public override Bits GetDocsWithField(FieldInfo field)
+        {
+            switch (field.DocValuesType)
+            {
+                case FieldInfo.DocValuesType_e.SORTED_SET:
+                    return DocValues.DocsWithValue(GetSortedSet(field), maxDoc);
+                case FieldInfo.DocValuesType_e.SORTED:
+                    return DocValues.DocsWithValue(GetSorted(field), maxDoc);
+                case FieldInfo.DocValuesType_e.BINARY:
+                    BinaryEntry be = binaries[field.Number];
+                    return GetMissingBits(field.Number, be.missingOffset, be.missingBytes);
+                case FieldInfo.DocValuesType_e.NUMERIC:
+                    NumericEntry ne = numerics[field.Number];
+                    return GetMissingBits(field.Number, ne.missingOffset, ne.missingBytes);
+                default:
+                    throw new System.ArgumentOutOfRangeException();
+            }
+        }
+
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing)
+                data.Dispose();
+        }
+
+        internal class SortedSetRawValues
+        {
+            internal NumericDocValues docToOrdAddress;
+            internal NumericDocValues ords;
+            internal BinaryDocValues values;
+        }
+
+        internal class NumericEntry
+        {
+            internal long offset;
+            internal int count;
+            internal long missingOffset;
+            internal long missingBytes;
+            internal byte byteWidth;
+            internal int packedIntsVersion;
+        }
+
+        internal class BinaryEntry
+        {
+            internal long offset;
+            internal long missingOffset;
+            internal long missingBytes;
+            internal int count;
+            internal int numBytes;
+            internal int minLength;
+            internal int maxLength;
+            internal int packedIntsVersion;
+            internal int blockSize;
+        }
+
+        internal class SortedEntry
+        {
+            internal NumericEntry docToOrd;
+            internal BinaryEntry values;
+        }
+
+        internal class SortedSetEntry
+        {
+            internal NumericEntry docToOrdAddress;
+            internal NumericEntry ords;
+            internal BinaryEntry values;
+        }
+
+        internal class FSTEntry
+        {
+            internal long offset;
+            internal long numOrds;
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2d850fd7/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
index 58edcc5..a358e65 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
@@ -546,7 +546,7 @@ namespace Lucene.Net.Codecs.Memory
                             {
 //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
 //ORIGINAL LINE: final int freq = docsEnum2.freq();
-                                int freq = docsEnum2.freq();
+                                int freq = docsEnum2.Freq();
                                 freqs[upto] = freq;
                                 if (hasPos)
                                 {
@@ -569,23 +569,23 @@ namespace Lucene.Net.Codecs.Memory
                                     int posUpto = 0;
                                     for (int pos = 0; pos < freq; pos++)
                                     {
-                                        positions[upto][posUpto] = docsAndPositionsEnum.nextPosition();
+                                        positions[upto][posUpto] = docsAndPositionsEnum.NextPosition();
                                         if (hasPayloads_Renamed)
                                         {
                                             BytesRef payload = docsAndPositionsEnum.Payload;
                                             if (payload != null)
                                             {
-                                                sbyte[] payloadBytes = new sbyte[payload.length];
-                                                Array.Copy(payload.bytes, payload.offset, payloadBytes, 0,
-                                                    payload.length);
+                                                sbyte[] payloadBytes = new sbyte[payload.Length];
+                                                Array.Copy(payload.Bytes, payload.Offset, payloadBytes, 0,
+                                                    payload.Length);
                                                 payloads[upto][pos] = payloadBytes;
                                             }
                                         }
                                         posUpto++;
                                         if (hasOffsets_Renamed)
                                         {
-                                            positions[upto][posUpto++] = docsAndPositionsEnum.startOffset();
-                                            positions[upto][posUpto++] = docsAndPositionsEnum.endOffset();
+                                            positions[upto][posUpto++] = docsAndPositionsEnum.StartOffset();
+                                            positions[upto][posUpto++] = docsAndPositionsEnum.EndOffset();
                                         }
                                     }
                                 }
@@ -605,7 +605,7 @@ namespace Lucene.Net.Codecs.Memory
                 // End sentinel:
                 termOffsets[count] = termOffset;
 
-                finishSkips();
+                FinishSkips();
 
                 //System.out.println(skipCount + " skips: " + field);
 
@@ -694,17 +694,14 @@ namespace Lucene.Net.Codecs.Memory
 
                 if (sameCounts.Length < termLength)
                 {
-                    sameCounts = ArrayUtil.grow(sameCounts, termLength);
+                    sameCounts = ArrayUtil.Grow(sameCounts, termLength);
                 }
 
                 // Update skip pointers:
                 if (termOrd > 0)
                 {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int lastTermLength = termOffsets[termOrd] - termOffsets[termOrd-1];
+
                     int lastTermLength = termOffsets[termOrd] - termOffsets[termOrd - 1];
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int limit = Math.min(termLength, lastTermLength);
                     int limit = Math.Min(termLength, lastTermLength);
 
                     int lastTermOffset = termOffsets[termOrd - 1];
@@ -724,7 +721,7 @@ namespace Lucene.Net.Codecs.Memory
                                 if (sameCounts[i] >= minSkipCount)
                                 {
                                     // Go back and add a skip pointer:
-                                    saveSkip(termOrd, sameCounts[i]);
+                                    SaveSkip(termOrd, sameCounts[i]);
                                 }
                                 sameCounts[i] = 1;
                             }
@@ -737,7 +734,7 @@ namespace Lucene.Net.Codecs.Memory
                         if (sameCounts[i] >= minSkipCount)
                         {
                             // Go back and add a skip pointer:
-                            saveSkip(termOrd, sameCounts[i]);
+                            SaveSkip(termOrd, sameCounts[i]);
                         }
                         sameCounts[i] = 0;
                     }
@@ -755,7 +752,7 @@ namespace Lucene.Net.Codecs.Memory
                 }
             }
 
-            internal void finishSkips()
+            internal void FinishSkips()
             {
                 Debug.Assert(count == terms.Length);
                 int lastTermOffset = termOffsets[count - 1];
@@ -766,7 +763,7 @@ namespace Lucene.Net.Codecs.Memory
                     if (sameCounts[i] >= minSkipCount)
                     {
                         // Go back and add a skip pointer:
-                        saveSkip(count, sameCounts[i]);
+                        SaveSkip(count, sameCounts[i]);
                     }
                 }
 
@@ -778,12 +775,8 @@ namespace Lucene.Net.Codecs.Memory
                     {
                         for (int pos = 0; pos < term.skips.Length/2; pos++)
                         {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int otherPos = term.skips.length-pos-1;
                             int otherPos = term.skips.Length - pos - 1;
 
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int temp = term.skips[pos];
                             int temp = term.skips[pos];
                             term.skips[pos] = term.skips[otherPos];
                             term.skips[otherPos] = temp;
@@ -792,10 +785,8 @@ namespace Lucene.Net.Codecs.Memory
                 }
             }
 
-            internal void saveSkip(int ord, int backCount)
+            internal void SaveSkip(int ord, int backCount)
             {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final TermAndSkip term = terms[ord - backCount];
                 TermAndSkip term = terms[ord - backCount];
                 skipCount++;
                 if (term.skips == null)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2d850fd7/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs
index 4613d28..6858b71 100644
--- a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs
+++ b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs
@@ -1,51 +1,48 @@
-	/*
-	 * 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 System;
-using System.Collections;
-using System.Diagnostics;
-using System.Collections.Generic;
-using Lucene.Net.Codecs.Memory;
-using Lucene.Net.Index;
-using Lucene.Net.Util.Fst;
+/*
+ * 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.
+ */
 
 namespace Lucene.Net.Codecs.Memory
 {
 
-
+    using Lucene.Net.Util.Fst;
+    using System;
+    using System.Collections;
+    using System.Collections.Generic;
+    using System.Diagnostics;
+    using System.Linq;
+    using ArrayUtil = Util.ArrayUtil;
+    using BlockPackedWriter = Util.Packed.BlockPackedWriter;
+    using ByteArrayDataOutput = Store.ByteArrayDataOutput;
+    using BytesRef = Util.BytesRef;
     using FieldInfo = Index.FieldInfo;
+    using FormatAndBits = Util.Packed.PackedInts.FormatAndBits;
+    using FST = Util.Fst.FST;
     using IndexFileNames = Index.IndexFileNames;
-    using SegmentWriteState = Index.SegmentWriteState;
-    using ByteArrayDataOutput = Store.ByteArrayDataOutput;
     using IndexOutput = Store.IndexOutput;
-    using ArrayUtil = Util.ArrayUtil;
-    using BytesRef = Util.BytesRef;
-    using IOUtils = Util.IOUtils;
+    using INPUT_TYPE = Util.Fst.FST.INPUT_TYPE;
     using IntsRef = Util.IntsRef;
+    using IOUtils = Util.IOUtils;
     using MathUtil = Util.MathUtil;
-    using Builder = Util.Fst.Builder;
-    using INPUT_TYPE = Util.Fst.FST.INPUT_TYPE;
-    using FST = Util.Fst.FST;
-    using PositiveIntOutputs = Util.Fst.PositiveIntOutputs;
-    using Util = Util.Fst.Util;
-    using BlockPackedWriter = Util.Packed.BlockPackedWriter;
     using MonotonicBlockPackedWriter = Util.Packed.MonotonicBlockPackedWriter;
-    using FormatAndBits = Util.Packed.PackedInts.FormatAndBits;
     using PackedInts = Util.Packed.PackedInts;
+    using PositiveIntOutputs = Util.Fst.PositiveIntOutputs;
+    using SegmentWriteState = Index.SegmentWriteState;
+    using Util = Util.Fst.Util;
+
 
     /// <summary>
     /// Writer for <seealso cref="MemoryDocValuesFormat"/>
@@ -82,12 +79,12 @@ namespace Lucene.Net.Codecs.Memory
             }
         }
 
-        public override void AddNumericField(FieldInfo field, IEnumerable<long> values)
+        public override void AddNumericField(FieldInfo field, IEnumerable<long?> values)
         {
             AddNumericField(field, values, true);
         }
 
-        internal virtual void AddNumericField(FieldInfo field, IEnumerable<long> values, bool optimizeStorage)
+        internal virtual void AddNumericField(FieldInfo field, IEnumerable<long?> values, bool optimizeStorage)
         {
             meta.WriteVInt(field.Number);
             meta.WriteByte(MemoryDocValuesProducer.NUMBER);
@@ -100,12 +97,12 @@ namespace Lucene.Net.Codecs.Memory
             HashSet<long?> uniqueValues = null;
             if (optimizeStorage)
             {
-                uniqueValues = new HashSet<>();
+                uniqueValues = new HashSet<long?>();
 
                 long count = 0;
                 foreach (var nv in values)
                 {
-                    long v = nv;
+                    long v = nv.Value;
 
                     if (gcd != 1)
                     {
@@ -165,31 +162,33 @@ namespace Lucene.Net.Codecs.Memory
                     meta.WriteByte(MemoryDocValuesProducer.UNCOMPRESSED); // uncompressed
                     foreach (var nv in values)
                     {
-                        data.WriteByte(nv == null ? 0 : (long) (sbyte) nv);
+                        data.WriteByte(!nv.HasValue ? (byte)0 : (byte)nv.Value);
                     }
                 }
                 else
                 {
                     meta.WriteByte(MemoryDocValuesProducer.TABLE_COMPRESSED); // table-compressed
-                    long?[] decode = uniqueValues.toArray(new long?[uniqueValues.Count]);
+                    long?[] decode = uniqueValues.ToArray();
 
                     var encode = new Dictionary<long?, int?>();
                     data.WriteVInt(decode.Length);
                     for (int i = 0; i < decode.Length; i++)
                     {
-                        data.WriteLong(decode[i]);
+                        data.WriteLong(decode[i].Value);
                         encode[decode[i]] = i;
                     }
 
                     meta.WriteVInt(PackedInts.VERSION_CURRENT);
-                    data.WriteVInt(formatAndBits.format.Id);
+                    data.WriteVInt(formatAndBits.format.id);
                     data.WriteVInt(formatAndBits.bitsPerValue);
 
                     PackedInts.Writer writer = PackedInts.GetWriterNoHeader(data, formatAndBits.format, maxDoc,
                         formatAndBits.bitsPerValue, PackedInts.DEFAULT_BUFFER_SIZE);
-                    foreach (long nv in values)
+                    foreach (var nv in values)
                     {
-                        writer.Add(encode[nv == null ? 0 : (long) nv]);
+                        var v = encode[nv.HasValue ? nv.Value : 0];
+
+                        writer.Add((long)v);
                     }
                     writer.Finish();
                 }
@@ -205,7 +204,7 @@ namespace Lucene.Net.Codecs.Memory
                 var writer = new BlockPackedWriter(data, MemoryDocValuesProducer.BLOCK_SIZE);
                 foreach (var nv in values)
                 {
-                    writer.Add((nv - minValue)/gcd);
+                    writer.Add((nv.Value - minValue)/gcd);
                 }
                 writer.Finish();
             }
@@ -219,7 +218,7 @@ namespace Lucene.Net.Codecs.Memory
                 var writer = new BlockPackedWriter(data, MemoryDocValuesProducer.BLOCK_SIZE);
                 foreach (var nv in values)
                 {
-                    writer.Add(nv);
+                    writer.Add(nv.Value);
                 }
                 writer.Finish();
             }
@@ -332,7 +331,7 @@ namespace Lucene.Net.Codecs.Memory
         private void WriteFST(FieldInfo field, IEnumerable<BytesRef> values)
         {
             meta.WriteVInt(field.Number);
-            meta.WriteByte(FST);
+            meta.WriteByte(MemoryDocValuesProducer.FST);
             meta.WriteLong(data.FilePointer);
             PositiveIntOutputs outputs = PositiveIntOutputs.Singleton;
             var builder = new Builder<long?>(INPUT_TYPE.BYTE1, outputs);
@@ -378,7 +377,7 @@ namespace Lucene.Net.Codecs.Memory
             }
         }
 
-        public override void AddSortedField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<long> docToOrd)
+        public override void AddSortedField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<long?> docToOrd)
         {
             // write the ordinals as numerics
             AddNumericField(field, docToOrd, false);
@@ -389,7 +388,7 @@ namespace Lucene.Net.Codecs.Memory
 
         // 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)
+            IEnumerable<long?> docToOrdCount, IEnumerable<long?> ords)
         {
             // write the ordinals as a binary field
             AddBinaryField(field, new IterableAnonymousInnerClassHelper(this, docToOrdCount, ords));
@@ -400,11 +399,11 @@ namespace Lucene.Net.Codecs.Memory
 
         private class IterableAnonymousInnerClassHelper : IEnumerable<BytesRef>
         {
-            private readonly IEnumerable<long> _docToOrdCount;
-            private readonly IEnumerable<long> _ords;
+            private readonly IEnumerable<long?> _docToOrdCount;
+            private readonly IEnumerable<long?> _ords;
 
             public IterableAnonymousInnerClassHelper(MemoryDocValuesConsumer outerInstance,
-                IEnumerable<long> docToOrdCount, IEnumerable<long> ords)
+                IEnumerable<long?> docToOrdCount, IEnumerable<long?> ords)
             {
                 _docToOrdCount = docToOrdCount;
                 _ords = ords;
@@ -414,40 +413,53 @@ namespace Lucene.Net.Codecs.Memory
             {
                 return new SortedSetIterator(_docToOrdCount.GetEnumerator(), _ords.GetEnumerator());
             }
+
+            IEnumerator IEnumerable.GetEnumerator()
+            {
+                return this.GetEnumerator();
+            }
         }
 
         // per-document vint-encoded byte[]
         internal class SortedSetIterator : IEnumerator<BytesRef>
         {
-            internal sbyte[] buffer = new sbyte[10];
+            internal byte[] buffer = new byte[10];
             internal ByteArrayDataOutput @out = new ByteArrayDataOutput();
-            internal BytesRef @ref = new BytesRef();
+            internal BytesRef _current = new BytesRef();
 
-            internal readonly IEnumerator<long> counts;
-            internal readonly IEnumerator<long> ords;
+            internal readonly IEnumerator<long?> counts;
+            internal readonly IEnumerator<long?> ords;
 
-            internal SortedSetIterator(IEnumerator<long> counts, IEnumerator<long> ords)
+            public BytesRef Current
             {
-                this.counts = counts;
-                this.ords = ords;
+                get
+                {
+                    return _current;
+                }
             }
 
-            public override bool HasNext()
+            object IEnumerator.Current
             {
-//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
-                return counts.hasNext();
+                get
+                {
+                    return this.Current;
+                }
             }
 
-            public override BytesRef Next()
+            internal SortedSetIterator(IEnumerator<long?> counts, IEnumerator<long?> ords)
+            {
+                this.counts = counts;
+                this.ords = ords;
+            }
+
+            public bool MoveNext()
             {
-                if (!HasNext())
-                {
-                    throw new ArgumentOutOfRangeException();
-                }
 
-//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
-                int count = (int) counts.next();
-                int maxSize = count*9; // worst case
+                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);
@@ -456,11 +468,11 @@ namespace Lucene.Net.Codecs.Memory
                 EncodeValues(count);
                 
 
-                @ref.Bytes = buffer;
-                @ref.Offset = 0;
-                @ref.Length = @out.Position;
+                _current.Bytes = buffer;
+                _current.Offset = 0;
+                _current.Length = @out.Position;
 
-                return @ref;
+                return true;
             }
 
             // encodes count values to buffer
@@ -470,16 +482,24 @@ namespace Lucene.Net.Codecs.Memory
                 long lastOrd = 0;
                 for (int i = 0; i < count; i++)
                 {
-//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
-                    long ord = (long) ords.next();
-                    @out.writeVLong(ord - lastOrd);
+                    if (!ords.MoveNext())
+                        break;
+
+                    long ord = ords.Current.Value;
+                    @out.WriteVLong(ord - lastOrd);
                     lastOrd = ord;
                 }
             }
 
-            public override void Remove()
+
+            public void Dispose()
+            {
+                throw new NotImplementedException();
+            }
+
+            public void Reset()
             {
-                throw new NotSupportedException();
+                throw new NotImplementedException();
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2d850fd7/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs
index b083b22..ec82d39 100644
--- a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs
+++ b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs
@@ -46,7 +46,7 @@ namespace Lucene.Net.Codecs.Memory
         // ram instances we have already loaded
         private readonly IDictionary<int?, NumericDocValues> numericInstances = new Dictionary<int?, NumericDocValues>();
         private readonly IDictionary<int?, BinaryDocValues> binaryInstances = new Dictionary<int?, BinaryDocValues>();
-        private readonly IDictionary<int?, FST<long>> fstInstances = new Dictionary<int?, FST<long>>();
+        private readonly IDictionary<int?, FST<long?>> fstInstances = new Dictionary<int?, FST<long?>>();
         private readonly IDictionary<int?, Bits> docsWithFieldInstances = new Dictionary<int?, Bits>();
 
         private readonly int maxDoc;
@@ -55,8 +55,8 @@ namespace Lucene.Net.Codecs.Memory
 
         internal const byte NUMBER = 0;
         internal const byte BYTES = 1;
-        //internal const sbyte org;
-
+        internal const byte FST = 2;
+        
         internal const int BLOCK_SIZE = 4096;
 
         internal const byte DELTA_COMPRESSED = 0;
@@ -275,7 +275,7 @@ namespace Lucene.Net.Codecs.Memory
                     ramBytesUsed.AddAndGet(quotientReader.RamBytesUsed());
                     return new NumericDocValuesAnonymousInnerClassHelper3(this, min, mult, quotientReader);
                 default:
-                    throw new AssertionError();
+                    throw new InvalidOperationException();
             }
         }
 
@@ -422,14 +422,14 @@ namespace Lucene.Net.Codecs.Memory
             {
                 return DocValues.EMPTY_SORTED;
             }
-            FST<long> instance;
+            FST<long?> instance;
             lock (this)
             {
                 instance = fstInstances[field.Number];
                 if (instance == null)
                 {
                     data.Seek(entry.offset);
-                    instance = new FST<long>(data, PositiveIntOutputs.Singleton);
+                    instance = new FST<long?>(data, PositiveIntOutputs.Singleton);
                     ramBytesUsed.AddAndGet(instance.SizeInBytes());
                     fstInstances[field.Number] = instance;
                 }
@@ -439,10 +439,10 @@ namespace Lucene.Net.Codecs.Memory
 
             // per-thread resources
             var @in = fst.BytesReader;
-            var firstArc = new FST.Arc<long>();
-            var scratchArc = new FST.Arc<long>();
+            var firstArc = new FST.Arc<long?>();
+            var scratchArc = new FST.Arc<long?>();
             var scratchInts = new IntsRef();
-            var fstEnum = new BytesRefFSTEnum<long>(fst);
+            var fstEnum = new BytesRefFSTEnum<long?>(fst);
 
             return new SortedDocValuesAnonymousInnerClassHelper(entry, docToOrd, fst, @in, firstArc, scratchArc,
                 scratchInts, fstEnum);
@@ -452,16 +452,16 @@ namespace Lucene.Net.Codecs.Memory
         {
             private readonly MemoryDocValuesProducer.FSTEntry entry;
             private readonly NumericDocValues docToOrd;
-            private readonly FST<long> fst;
+            private readonly FST<long?> fst;
             private readonly FST.BytesReader @in;
-            private readonly FST.Arc<long> firstArc;
-            private readonly FST.Arc<long> scratchArc;
+            private readonly FST.Arc<long?> firstArc;
+            private readonly FST.Arc<long?> scratchArc;
             private readonly IntsRef scratchInts;
-            private readonly BytesRefFSTEnum<long> fstEnum;
+            private readonly BytesRefFSTEnum<long?> fstEnum;
 
             public SortedDocValuesAnonymousInnerClassHelper(FSTEntry fstEntry,
-                NumericDocValues numericDocValues, FST<long> fst1, FST.BytesReader @in, FST.Arc<long> arc, FST.Arc<long> scratchArc1,
-                IntsRef intsRef, BytesRefFSTEnum<long> bytesRefFstEnum)
+                NumericDocValues numericDocValues, FST<long?> fst1, FST.BytesReader @in, FST.Arc<long?> arc, FST.Arc<long?> scratchArc1,
+                IntsRef intsRef, BytesRefFSTEnum<long?> bytesRefFstEnum)
             {
                 entry = fstEntry;
                 docToOrd = numericDocValues;
@@ -492,7 +492,7 @@ namespace Lucene.Net.Codecs.Memory
                 }
                 catch (IOException bogus)
                 {
-                    throw new Exception(bogus);
+                    throw new Exception(bogus.Message, bogus);
                 }
             }
 
@@ -516,7 +516,7 @@ namespace Lucene.Net.Codecs.Memory
                 }
                 catch (IOException bogus)
                 {
-                    throw new Exception(bogus);
+                    throw new Exception(bogus.Message, bogus);
                 }
             }
 
@@ -538,14 +538,14 @@ namespace Lucene.Net.Codecs.Memory
             {
                 return DocValues.EMPTY_SORTED_SET; // empty FST!
             }
-            FST<long> instance;
+            FST<long?> instance;
             lock (this)
             {
                 instance = fstInstances[field.Number];
                 if (instance == null)
                 {
                     data.Seek(entry.offset);
-                    instance = new FST<long>(data, PositiveIntOutputs.Singleton);
+                    instance = new FST<long?>(data, PositiveIntOutputs.Singleton);
                     ramBytesUsed.AddAndGet(instance.SizeInBytes());
                     fstInstances[field.Number] = instance;
                 }
@@ -555,10 +555,10 @@ namespace Lucene.Net.Codecs.Memory
 
             // per-thread resources
             var @in = fst.BytesReader;
-            var firstArc = new FST.Arc<long>();
-            var scratchArc = new FST.Arc<long>();
+            var firstArc = new FST.Arc<long?>();
+            var scratchArc = new FST.Arc<long?>();
             var scratchInts = new IntsRef();
-            var fstEnum = new BytesRefFSTEnum<long>(fst);
+            var fstEnum = new BytesRefFSTEnum<long?>(fst);
             var @ref = new BytesRef();
             var input = new ByteArrayDataInput();
             return new SortedSetDocValuesAnonymousInnerClassHelper(entry, docToOrds, fst, @in, firstArc,
@@ -569,19 +569,19 @@ namespace Lucene.Net.Codecs.Memory
         {
             private readonly MemoryDocValuesProducer.FSTEntry entry;
             private readonly BinaryDocValues docToOrds;
-            private readonly FST<long> fst;
+            private readonly FST<long?> fst;
             private readonly FST.BytesReader @in;
-            private readonly FST.Arc<long> firstArc;
-            private readonly FST.Arc<long> scratchArc;
+            private readonly FST.Arc<long?> firstArc;
+            private readonly FST.Arc<long?> scratchArc;
             private readonly IntsRef scratchInts;
-            private readonly BytesRefFSTEnum<long> fstEnum;
+            private readonly BytesRefFSTEnum<long?> fstEnum;
             private readonly BytesRef @ref;
             private readonly ByteArrayDataInput input;
 
             private long currentOrd;
 
-            public SortedSetDocValuesAnonymousInnerClassHelper(FSTEntry fstEntry, BinaryDocValues binaryDocValues, FST<long> fst1,
-                FST.BytesReader @in, FST.Arc<long> arc, FST.Arc<long> scratchArc1, IntsRef intsRef, BytesRefFSTEnum<long> bytesRefFstEnum,
+            public SortedSetDocValuesAnonymousInnerClassHelper(FSTEntry fstEntry, BinaryDocValues binaryDocValues, FST<long?> fst1,
+                FST.BytesReader @in, FST.Arc<long?> arc, FST.Arc<long?> scratchArc1, IntsRef intsRef, BytesRefFSTEnum<long?> bytesRefFstEnum,
                 BytesRef @ref, ByteArrayDataInput byteArrayDataInput)
             {
                 entry = fstEntry;
@@ -633,7 +633,7 @@ namespace Lucene.Net.Codecs.Memory
                 }
                 catch (IOException bogus)
                 {
-                    throw new Exception(bogus);
+                    throw new Exception(bogus.Message, bogus);
                 }
             }
 
@@ -648,16 +648,16 @@ namespace Lucene.Net.Codecs.Memory
                     }
                     else if (o.Input.Equals(key))
                     {
-                        return o.Output;
+                        return o.Output.Value;
                     }
                     else
                     {
-                        return -o.Output - 1;
+                        return -o.Output.Value - 1;
                     }
                 }
                 catch (IOException bogus)
                 {
-                    throw new Exception(bogus);
+                    throw new Exception(bogus.Message, bogus);
                 }
             }
 
@@ -706,22 +706,22 @@ namespace Lucene.Net.Codecs.Memory
         {
             switch (field.DocValuesType)
             {
-                case SORTED_SET:
+                case FieldInfo.DocValuesType_e.SORTED_SET:
                     return DocValues.DocsWithValue(GetSortedSet(field), maxDoc);
-                case SORTED:
+                case FieldInfo.DocValuesType_e.SORTED:
                     return DocValues.DocsWithValue(GetSorted(field), maxDoc);
-                case BINARY:
+                case FieldInfo.DocValuesType_e.BINARY:
                     var be = binaries[field.Number];
                     return GetMissingBits(field.Number, be.missingOffset, be.missingBytes);
-                case NUMERIC:
+                case FieldInfo.DocValuesType_e.NUMERIC:
                     var ne = numerics[field.Number];
                     return GetMissingBits(field.Number, ne.missingOffset, ne.missingBytes);
                 default:
-                    throw new AssertionError();
+                    throw new InvalidOperationException();
             }
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
             data.Dispose();
             base.Dispose();
@@ -757,27 +757,27 @@ namespace Lucene.Net.Codecs.Memory
         // exposes FSTEnum directly as a TermsEnum: avoids binary-search next()
         internal class FSTTermsEnum : TermsEnum
         {
-            internal readonly BytesRefFSTEnum<long> @in;
+            internal readonly BytesRefFSTEnum<long?> input;
 
             // this is all for the complicated seek(ord)...
             // maybe we should add a FSTEnum that supports this operation?
-            internal readonly FST<long> fst;
+            internal readonly FST<long?> fst;
             internal readonly FST.BytesReader bytesReader;
-            internal readonly FST.Arc<long> firstArc = new FST.Arc<long>();
-            internal readonly FST.Arc<long> scratchArc = new FST.Arc<long>();
+            internal readonly FST.Arc<long?> firstArc = new FST.Arc<long?>();
+            internal readonly FST.Arc<long?> scratchArc = new FST.Arc<long?>();
             internal readonly IntsRef scratchInts = new IntsRef();
             internal readonly BytesRef scratchBytes = new BytesRef();
 
-            internal FSTTermsEnum(FST<long> fst)
+            internal FSTTermsEnum(FST<long?> fst)
             {
                 this.fst = fst;
-                @in = new BytesRefFSTEnum<long>(fst);
+                input = new BytesRefFSTEnum<long?>(fst);
                 bytesReader = fst.BytesReader;
             }
 
             public override BytesRef Next()
             {
-                var io = @in.Next();
+                var io = input.Next();
                 return io == null ? null : io.Input;
             }
 
@@ -788,7 +788,7 @@ namespace Lucene.Net.Codecs.Memory
 
             public override SeekStatus SeekCeil(BytesRef text)
             {
-                if (@in.SeekCeil(text) == null)
+                if (input.SeekCeil(text) == null)
                 {
                     return SeekStatus.END;
                 }
@@ -806,7 +806,7 @@ namespace Lucene.Net.Codecs.Memory
 
             public override bool SeekExact(BytesRef text)
             {
-                return @in.SeekExact(text) != null;
+                return input.SeekExact(text) != null;
             }
 
             public override void SeekExact(long ord)
@@ -821,17 +821,17 @@ namespace Lucene.Net.Codecs.Memory
                 scratchBytes.Length = 0;
                 Util.ToBytesRef(output, scratchBytes);
                 // TODO: we could do this lazily, better to try to push into FSTEnum though?
-                @in.SeekExact(scratchBytes);
+                input.SeekExact(scratchBytes);
             }
 
             public override BytesRef Term()
             {
-                return @in.Current().Input;
+                return input.Current().Input;
             }
 
             public override long Ord()
             {
-                return @in.Current().Output;
+                return input.Current().Output.Value;
             }
 
             public override int DocFreq()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2d850fd7/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
index 6f86bd9..7f19a0f 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
@@ -61,7 +61,7 @@ namespace Lucene.Net.Codecs.SimpleText
             numDocs = state.SegmentInfo.DocCount;
         }
 
-        public override void AddNumericField(FieldInfo field, IEnumerable<long> values)
+        public override void AddNumericField(FieldInfo field, IEnumerable<long?> values)
         {
             Debug.Assert(FieldSeen(field.Name));
             Debug.Assert(field.DocValuesType == FieldInfo.DocValuesType_e.NUMERIC ||
@@ -74,8 +74,8 @@ namespace Lucene.Net.Codecs.SimpleText
             foreach (var n in values)
             {
                 var v = n;
-                minValue = Math.Min(minValue, v);
-                maxValue = Math.Max(maxValue, v);
+                minValue = Math.Min(minValue, v.Value); // Added .Value to account for long?
+                maxValue = Math.Max(maxValue, v.Value); // Added .Value to account for long?
             }
 
             // write our minimum value to the .dat, all entries are deltas from that
@@ -103,8 +103,10 @@ namespace Lucene.Net.Codecs.SimpleText
             int numDocsWritten = 0;
 
             // second pass to write the values
-            foreach (var value in values)
+            foreach (var n in values)
             {
+                long value = n == null ? 0 : n.Value;
+
                 Debug.Assert(value >= minValue);
 
                 var delta = value - minValue;
@@ -180,7 +182,7 @@ namespace Lucene.Net.Codecs.SimpleText
             Debug.Assert(numDocs == numDocsWritten);
         }
 
-        public override void AddSortedField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<long> docToOrd)
+        public override void AddSortedField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<long?> docToOrd)
         {
             Debug.Assert(FieldSeen(field.Name));
             Debug.Assert(field.DocValuesType == FieldInfo.DocValuesType_e.SORTED);
@@ -260,13 +262,13 @@ namespace Lucene.Net.Codecs.SimpleText
 
             foreach (var ord in docToOrd)
             {
-                SimpleTextUtil.Write(data, (ord + 1).ToString(ordEncoderFormat), scratch);
+                SimpleTextUtil.Write(data, (ord + 1).Value.ToString(ordEncoderFormat), scratch);
                 SimpleTextUtil.WriteNewline(data);
             }
         }
 
         public override void AddSortedSetField(FieldInfo field, IEnumerable<BytesRef> values,
-            IEnumerable<long> docToOrdCount, IEnumerable<long> ords)
+            IEnumerable<long?> docToOrdCount, IEnumerable<long?> ords)
         {
             Debug.Assert(FieldSeen(field.Name));
             Debug.Assert(field.DocValuesType == FieldInfo.DocValuesType_e.SORTED_SET);


Mime
View raw message