lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [04/23] lucenenet git commit: Lucene.Net.Codecs.BlockTerms: Re-ported FixedGapTermsIndexReader, FixedGapTermsIndexWriter, VariableGapTermsIndexReader, VariableGapTermsIndexWriter to ensure all variables are using correct scope
Date Sun, 19 Mar 2017 23:19:59 GMT
Lucene.Net.Codecs.BlockTerms: Re-ported FixedGapTermsIndexReader, FixedGapTermsIndexWriter, VariableGapTermsIndexReader, VariableGapTermsIndexWriter to ensure all variables are using correct scope


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

Branch: refs/heads/api-work
Commit: d21561d3ce7bd700976e6f962fefffd03bd63aaf
Parents: 1246d5c
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Mar 19 20:35:40 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Mar 19 22:41:05 2017 +0700

----------------------------------------------------------------------
 .../BlockTerms/FixedGapTermsIndexReader.cs      | 334 +++++++++----------
 .../BlockTerms/FixedGapTermsIndexWriter.cs      |  58 ++--
 .../BlockTerms/VariableGapTermsIndexReader.cs   | 151 +++++----
 .../BlockTerms/VariableGapTermsIndexWriter.cs   | 133 ++++----
 .../Codecs/Lucene3x/TermInfosReader.cs          |   2 +-
 .../Util/DoubleBarrelLRUCache.cs                |   2 +-
 .../Util/TestDoubleBarrelLRUCache.cs            |   4 +-
 7 files changed, 331 insertions(+), 353 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d21561d3/src/Lucene.Net.Codecs/BlockTerms/FixedGapTermsIndexReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/BlockTerms/FixedGapTermsIndexReader.cs b/src/Lucene.Net.Codecs/BlockTerms/FixedGapTermsIndexReader.cs
index aeb1ba0..50a9e1f 100644
--- a/src/Lucene.Net.Codecs/BlockTerms/FixedGapTermsIndexReader.cs
+++ b/src/Lucene.Net.Codecs/BlockTerms/FixedGapTermsIndexReader.cs
@@ -36,7 +36,6 @@ namespace Lucene.Net.Codecs.BlockTerms
     /// </summary>
     public class FixedGapTermsIndexReader : TermsIndexReaderBase
     {
-
         // NOTE: long is overkill here, since this number is 128
         // by default and only indexDivisor * 128 if you change
         // the indexDivisor at search time.  But, we use this in a
@@ -44,111 +43,98 @@ namespace Lucene.Net.Codecs.BlockTerms
         // will overflow int during those multiplies.  So to avoid
         // having to upgrade each multiple to long in multiple
         // places (error prone), we use long here:
-        private readonly long _totalIndexInterval;
+        private long totalIndexInterval;
 
-        private int _indexDivisor;
+        private int indexDivisor;
         private readonly int indexInterval;
 
         // Closed if indexLoaded is true:
-        private readonly IndexInput _input;
-        private volatile bool _indexLoaded;
+        private IndexInput input;
+        private volatile bool indexLoaded;
 
-        private readonly IComparer<BytesRef> _termComp;
+        private readonly IComparer<BytesRef> termComp;
 
-        private const int PAGED_BYTES_BITS = 15;
+        private readonly static int PAGED_BYTES_BITS = 15;
 
         // all fields share this single logical byte[]
-        private readonly PagedBytes _termBytes = new PagedBytes(PAGED_BYTES_BITS);
-        private readonly PagedBytes.Reader _termBytesReader;
+        private readonly PagedBytes termBytes = new PagedBytes(PAGED_BYTES_BITS);
+        private PagedBytes.Reader termBytesReader;
 
-        private readonly Dictionary<FieldInfo, FieldIndexData> _fields = new Dictionary<FieldInfo, FieldIndexData>();
+        readonly IDictionary<FieldInfo, FieldIndexData> fields = new Dictionary<FieldInfo, FieldIndexData>();
 
         // start of the field info data
-        private long _dirOffset;
+        private long dirOffset;
 
-        private readonly int _version;
+        private readonly int version;
 
         public FixedGapTermsIndexReader(Directory dir, FieldInfos fieldInfos, string segment, int indexDivisor,
             IComparer<BytesRef> termComp, string segmentSuffix, IOContext context)
         {
-            _termComp = termComp;
+            this.termComp = termComp;
 
             Debug.Assert(indexDivisor == -1 || indexDivisor > 0);
 
-            _input =
-                dir.OpenInput(
-                    IndexFileNames.SegmentFileName(segment, segmentSuffix,
-                        FixedGapTermsIndexWriter.TERMS_INDEX_EXTENSION),
-                    context);
+            input = dir.OpenInput(IndexFileNames.SegmentFileName(segment, segmentSuffix, FixedGapTermsIndexWriter.TERMS_INDEX_EXTENSION), context);
 
             bool success = false;
 
             try
             {
-                _version = ReadHeader(_input);
+                version = ReadHeader(input);
 
-                if (_version >= FixedGapTermsIndexWriter.VERSION_CHECKSUM)
-                    CodecUtil.ChecksumEntireFile(_input);
-                
-                indexInterval = _input.ReadInt32();
-                
-                if (indexInterval < 1)
+                if (version >= FixedGapTermsIndexWriter.VERSION_CHECKSUM)
                 {
-                    throw new CorruptIndexException(string.Format("Invalid indexInterval: {0}, Resource: {1}",
-                        indexInterval, _input));
+                    CodecUtil.ChecksumEntireFile(input);
                 }
 
-                _indexDivisor = indexDivisor;
+                indexInterval = input.ReadInt32();
+                if (indexInterval < 1)
+                {
+                    throw new CorruptIndexException("invalid indexInterval: " + indexInterval + " (resource=" + input + ")");
+                }
+                this.indexDivisor = indexDivisor;
 
                 if (indexDivisor < 0)
                 {
-                    _totalIndexInterval = indexInterval;
+                    totalIndexInterval = indexInterval;
                 }
                 else
                 {
                     // In case terms index gets loaded, later, on demand
-                    _totalIndexInterval = indexInterval * indexDivisor;
+                    totalIndexInterval = indexInterval * indexDivisor;
                 }
+                Debug.Assert(totalIndexInterval > 0);
 
-                Debug.Assert(_totalIndexInterval > 0);
-
-                SeekDir(_input, _dirOffset);
+                SeekDir(input, dirOffset);
 
                 // Read directory
-                int numFields = _input.ReadVInt32();
-
+                int numFields = input.ReadVInt32();
                 if (numFields < 0)
-                    throw new CorruptIndexException(string.Format("Invalid numFields: {0}, Resource: {1}", numFields,
-                        _input));
-
+                {
+                    throw new CorruptIndexException("invalid numFields: " + numFields + " (resource=" + input + ")");
+                }
+                //System.out.println("FGR: init seg=" + segment + " div=" + indexDivisor + " nF=" + numFields);
                 for (int i = 0; i < numFields; i++)
                 {
-                    int field = _input.ReadVInt32();
-                    int numIndexTerms = _input.ReadVInt32();
+                    int field = input.ReadVInt32();
+                    int numIndexTerms = input.ReadVInt32();
                     if (numIndexTerms < 0)
-                        throw new CorruptIndexException(string.Format("Invalid numIndexTerms: {0}, Resource: {1}",
-                            numIndexTerms,
-                            _input));
-
-                    long termsStart = _input.ReadVInt64();
-                    long indexStart = _input.ReadVInt64();
-                    long packedIndexStart = _input.ReadVInt64();
-                    long packedOffsetsStart = _input.ReadVInt64();
-
+                    {
+                        throw new CorruptIndexException("invalid numIndexTerms: " + numIndexTerms + " (resource=" + input + ")");
+                    }
+                    long termsStart = input.ReadVInt64();
+                    long indexStart = input.ReadVInt64();
+                    long packedIndexStart = input.ReadVInt64();
+                    long packedOffsetsStart = input.ReadVInt64();
                     if (packedIndexStart < indexStart)
-                        throw new CorruptIndexException(
-                            string.Format(
-                                "Invalid packedIndexStart: {0}, IndexStart: {1}, NumIndexTerms: {2}, Resource: {3}",
-                                packedIndexStart,
-                                indexStart, numIndexTerms, _input));
-
+                    {
+                        throw new CorruptIndexException("invalid packedIndexStart: " + packedIndexStart + " indexStart: " + indexStart + "numIndexTerms: " + numIndexTerms + " (resource=" + input + ")");
+                    }
                     FieldInfo fieldInfo = fieldInfos.FieldInfo(field);
-                    FieldIndexData previous = _fields.Put(
-                        fieldInfo,
-                        new FieldIndexData(this, fieldInfo, numIndexTerms, indexStart, termsStart, packedIndexStart, packedOffsetsStart));
+                    FieldIndexData previous = fields.Put(fieldInfo, new FieldIndexData(this, fieldInfo, numIndexTerms, indexStart, termsStart, packedIndexStart, packedOffsetsStart));
                     if (previous != null)
                     {
-                        throw new CorruptIndexException("duplicate field: " + fieldInfo.Name + " (resource=" + _input +")");
+                        throw new CorruptIndexException("duplicate field: " + fieldInfo.Name + " (resource=" + input + ")");
                     }
                 }
                 success = true;
@@ -157,37 +143,34 @@ namespace Lucene.Net.Codecs.BlockTerms
             {
                 if (!success)
                 {
-                    IOUtils.CloseWhileHandlingException(_input);
+                    IOUtils.CloseWhileHandlingException(input);
                 }
                 if (indexDivisor > 0)
                 {
-                    _input.Dispose();
-                    _input = null;
+                    input.Dispose();
+                    input = null;
                     if (success)
                     {
-                        _indexLoaded = true;
+                        indexLoaded = true;
                     }
-
-                    _termBytesReader = _termBytes.Freeze(true);
+                    termBytesReader = termBytes.Freeze(true);
                 }
             }
         }
 
         public override int Divisor
         {
-            get { return _indexDivisor; }
+            get { return indexDivisor; }
         }
 
         private int ReadHeader(DataInput input)
         {
             int version = CodecUtil.CheckHeader(input, FixedGapTermsIndexWriter.CODEC_NAME,
                 FixedGapTermsIndexWriter.VERSION_START, FixedGapTermsIndexWriter.VERSION_CURRENT);
-
             if (version < FixedGapTermsIndexWriter.VERSION_APPEND_ONLY)
             {
-                _dirOffset = input.ReadInt64();
+                dirOffset = input.ReadInt64();
             }
-
             return version;
         }
 
@@ -196,37 +179,33 @@ namespace Lucene.Net.Codecs.BlockTerms
             // Outer intstance
             private readonly FixedGapTermsIndexReader outerInstance;
 
-            private readonly FieldIndexData.CoreFieldIndex _fieldIndex;
+            private readonly FieldIndexData.CoreFieldIndex fieldIndex;
             private readonly BytesRef term = new BytesRef();
             private long ord;
 
             public IndexEnum(FixedGapTermsIndexReader outerInstance, FieldIndexData.CoreFieldIndex fieldIndex)
             {
                 this.outerInstance = outerInstance;
-                _fieldIndex = fieldIndex;
+                this.fieldIndex = fieldIndex;
             }
 
             public override sealed BytesRef Term { get { return term; } }
 
             public override long Seek(BytesRef target)
             {
-                var lo = 0; // binary search
-                var hi = _fieldIndex.NumIndexTerms - 1;
-
-                Debug.Assert(outerInstance._totalIndexInterval > 0,
-                    string.Format("TotalIndexInterval: {0}", outerInstance._totalIndexInterval));
+                int lo = 0;          // binary search
+                int hi = fieldIndex.numIndexTerms - 1;
+                Debug.Assert(outerInstance.totalIndexInterval > 0, "totalIndexInterval=" + outerInstance.totalIndexInterval);
 
-                long offset;
-                int length;
                 while (hi >= lo)
                 {
-                    var mid = (int)((uint)(lo + hi) >> 1);
+                    int mid = (int)(((uint)(lo + hi)) >> 1);
 
-                    offset = _fieldIndex.TermOffsets.Get(mid);
-                    length = (int)(_fieldIndex.TermOffsets.Get(1 + mid) - offset);
-                    outerInstance._termBytesReader.FillSlice(term, _fieldIndex.TermBytesStart + offset, length);
+                    long offset2 = fieldIndex.termOffsets.Get(mid);
+                    int length2 = (int)(fieldIndex.termOffsets.Get(1 + mid) - offset2);
+                    outerInstance.termBytesReader.FillSlice(term, fieldIndex.termBytesStart + offset2, length2);
 
-                    int delta = outerInstance._termComp.Compare(target, term);
+                    int delta = outerInstance.termComp.Compare(target, term);
                     if (delta < 0)
                     {
                         hi = mid - 1;
@@ -238,8 +217,8 @@ namespace Lucene.Net.Codecs.BlockTerms
                     else
                     {
                         Debug.Assert(mid >= 0);
-                        ord = mid * outerInstance._totalIndexInterval;
-                        return _fieldIndex.TermsStart + _fieldIndex.TermsDictOffsets.Get(mid);
+                        ord = mid * outerInstance.totalIndexInterval;
+                        return fieldIndex.termsStart + fieldIndex.termsDictOffsets.Get(mid);
                     }
                 }
 
@@ -249,44 +228,41 @@ namespace Lucene.Net.Codecs.BlockTerms
                     hi = 0;
                 }
 
-                offset = _fieldIndex.TermOffsets.Get(hi);
-                length = (int)(_fieldIndex.TermOffsets.Get(1 + hi) - offset);
-                outerInstance._termBytesReader.FillSlice(term, _fieldIndex.TermBytesStart + offset, length);
+                long offset = fieldIndex.termOffsets.Get(hi);
+                int length = (int)(fieldIndex.termOffsets.Get(1 + hi) - offset);
+                outerInstance.termBytesReader.FillSlice(term, fieldIndex.termBytesStart + offset, length);
 
-                ord = hi * outerInstance._totalIndexInterval;
-                return _fieldIndex.TermsStart + _fieldIndex.TermsDictOffsets.Get(hi);
+                ord = hi * outerInstance.totalIndexInterval;
+                return fieldIndex.termsStart + fieldIndex.termsDictOffsets.Get(hi);
             }
 
             public override long Next()
             {
-                int idx = 1 + (int)(ord / outerInstance._totalIndexInterval);
-                if (idx >= _fieldIndex.NumIndexTerms)
+                int idx = 1 + (int)(ord / outerInstance.totalIndexInterval);
+                if (idx >= fieldIndex.numIndexTerms)
                 {
                     return -1;
                 }
+                ord += outerInstance.totalIndexInterval;
 
-                ord += outerInstance._totalIndexInterval;
-
-                long offset = _fieldIndex.TermOffsets.Get(idx);
-                int length = (int)(_fieldIndex.TermOffsets.Get(1 + idx) - offset);
-                outerInstance._termBytesReader.FillSlice(term, _fieldIndex.TermBytesStart + offset, length);
-                return _fieldIndex.TermsStart + _fieldIndex.TermsDictOffsets.Get(idx);
+                long offset = fieldIndex.termOffsets.Get(idx);
+                int length = (int)(fieldIndex.termOffsets.Get(1 + idx) - offset);
+                outerInstance.termBytesReader.FillSlice(term, fieldIndex.termBytesStart + offset, length);
+                return fieldIndex.termsStart + fieldIndex.termsDictOffsets.Get(idx);
             }
 
             public override long Ord { get { return ord; } }
 
             public override long Seek(long ord)
             {
-                int idx = (int)(ord / outerInstance._totalIndexInterval);
-
+                int idx = (int)(ord / outerInstance.totalIndexInterval);
                 // caller must ensure ord is in bounds
-                Debug.Assert(idx < _fieldIndex.NumIndexTerms);
-
-                long offset = _fieldIndex.TermOffsets.Get(idx);
-                int length = (int)(_fieldIndex.TermOffsets.Get(1 + idx) - offset);
-                outerInstance._termBytesReader.FillSlice(term, _fieldIndex.TermBytesStart + offset, length);
-                this.ord = idx * outerInstance._totalIndexInterval;
-                return _fieldIndex.TermsStart + _fieldIndex.TermsDictOffsets.Get(idx);
+                Debug.Assert(idx < fieldIndex.numIndexTerms);
+                long offset = fieldIndex.termOffsets.Get(idx);
+                int length = (int)(fieldIndex.termOffsets.Get(1 + idx) - offset);
+                outerInstance.termBytesReader.FillSlice(term, fieldIndex.termBytesStart + offset, length);
+                this.ord = idx * outerInstance.totalIndexInterval;
+                return fieldIndex.termsStart + fieldIndex.termsDictOffsets.Get(idx);
             }
         }
 
@@ -301,24 +277,25 @@ namespace Lucene.Net.Codecs.BlockTerms
 
             internal volatile CoreFieldIndex coreIndex;
 
-            private readonly long _indexStart;
-            private readonly long _termsStart;
-            private readonly long _packedIndexStart;
-            private readonly long _packedOffsetsStart;
+            private readonly long indexStart;
+            private readonly long termsStart;
+            private readonly long packedIndexStart;
+            private readonly long packedOffsetsStart;
+
+            private readonly int numIndexTerms;
 
-            private readonly int _numIndexTerms;
-            
             public FieldIndexData(FixedGapTermsIndexReader outerInstance, FieldInfo fieldInfo, int numIndexTerms, long indexStart, long termsStart,
                 long packedIndexStart, long packedOffsetsStart)
             {
                 this.outerInstance = outerInstance;
-                _termsStart = termsStart;
-                _indexStart = indexStart;
-                _packedIndexStart = packedIndexStart;
-                _packedOffsetsStart = packedOffsetsStart;
-                _numIndexTerms = numIndexTerms;
 
-                if (this.outerInstance._indexDivisor > 0)
+                this.termsStart = termsStart;
+                this.indexStart = indexStart;
+                this.packedIndexStart = packedIndexStart;
+                this.packedOffsetsStart = packedOffsetsStart;
+                this.numIndexTerms = numIndexTerms;
+
+                if (outerInstance.indexDivisor > 0)
                 {
                     LoadTermsIndex();
                 }
@@ -328,66 +305,59 @@ namespace Lucene.Net.Codecs.BlockTerms
             {
                 if (coreIndex == null)
                 {
-                    coreIndex = new CoreFieldIndex(outerInstance,
-                        _indexStart, _termsStart, _packedIndexStart, _packedOffsetsStart, _numIndexTerms);
+                    coreIndex = new CoreFieldIndex(this, indexStart, termsStart, packedIndexStart, packedOffsetsStart, numIndexTerms);
                 }
             }
 
             internal sealed class CoreFieldIndex
             {
-                /// <summary>
-                /// Where this fields term begin in the packed byte[] data
-                /// </summary>
-                internal long TermBytesStart { get; private set; }
+                // where this field's terms begin in the packed byte[]
+                // data
+                internal readonly long termBytesStart;
 
-                /// <summary>
-                /// Offset into index TermBytes
-                /// </summary>
-                internal PackedInt32s.Reader TermOffsets { get; private set; }
+                // offset into index termBytes
+                internal readonly PackedInt32s.Reader termOffsets;
 
-                /// <summary>
-                /// Index pointers into main terms dict
-                /// </summary>
-                internal PackedInt32s.Reader TermsDictOffsets { get; private set; }
+                // index pointers into main terms dict
+                internal readonly PackedInt32s.Reader termsDictOffsets;
 
-                internal int NumIndexTerms { get; private set; }
-                internal long TermsStart { get; private set; }
+                internal readonly int numIndexTerms;
+                internal readonly long termsStart;
 
-                public CoreFieldIndex(FixedGapTermsIndexReader outerInstance, long indexStart, long termsStart, long packedIndexStart, long packedOffsetsStart,
+                public CoreFieldIndex(FieldIndexData outerInstance, long indexStart, long termsStart, long packedIndexStart, long packedOffsetsStart,
                     int numIndexTerms)
                 {
-                    TermsStart = termsStart;
-                    TermBytesStart = outerInstance._termBytes.Pointer;
+                    this.termsStart = termsStart;
+                    termBytesStart = outerInstance.outerInstance.termBytes.Pointer;
 
-                    IndexInput clone = (IndexInput)outerInstance._input.Clone();
+                    IndexInput clone = (IndexInput)outerInstance.outerInstance.input.Clone();
                     clone.Seek(indexStart);
 
                     // -1 is passed to mean "don't load term index", but
                     // if we are then later loaded it's overwritten with
                     // a real value
-                    Debug.Assert(outerInstance._indexDivisor > 0);
+                    Debug.Assert(outerInstance.outerInstance.indexDivisor > 0);
 
-                    NumIndexTerms = 1 + (numIndexTerms - 1) / outerInstance._indexDivisor;
+                    this.numIndexTerms = 1 + (numIndexTerms - 1) / outerInstance.outerInstance.indexDivisor;
 
-                    Debug.Assert(NumIndexTerms > 0,
-                        string.Format("NumIndexTerms: {0}, IndexDivisor: {1}", NumIndexTerms, outerInstance._indexDivisor));
+                    Debug.Assert(this.numIndexTerms > 0, "numIndexTerms=" + numIndexTerms + " indexDivisor=" + outerInstance.outerInstance.indexDivisor);
 
-                    if (outerInstance._indexDivisor == 1)
+                    if (outerInstance.outerInstance.indexDivisor == 1)
                     {
                         // Default (load all index terms) is fast -- slurp in the images from disk:
 
                         try
                         {
                             long numTermBytes = packedIndexStart - indexStart;
-                            outerInstance._termBytes.Copy(clone, numTermBytes);
+                            outerInstance.outerInstance.termBytes.Copy(clone, numTermBytes);
 
                             // records offsets into main terms dict file
-                            TermsDictOffsets = PackedInt32s.GetReader(clone);
-                            Debug.Assert(TermsDictOffsets.Count == numIndexTerms);
+                            termsDictOffsets = PackedInt32s.GetReader(clone);
+                            Debug.Assert(termsDictOffsets.Count == numIndexTerms);
 
                             // records offsets into byte[] term data
-                            TermOffsets = PackedInt32s.GetReader(clone);
-                            Debug.Assert(TermOffsets.Count == 1 + numIndexTerms);
+                            termOffsets = PackedInt32s.GetReader(clone);
+                            Debug.Assert(termOffsets.Count == 1 + numIndexTerms);
                         }
                         finally
                         {
@@ -397,38 +367,34 @@ namespace Lucene.Net.Codecs.BlockTerms
                     else
                     {
                         // Get packed iterators
-                        IndexInput clone1 = (IndexInput)outerInstance._input.Clone();
-                        IndexInput clone2 = (IndexInput)outerInstance._input.Clone();
+                        IndexInput clone1 = (IndexInput)outerInstance.outerInstance.input.Clone();
+                        IndexInput clone2 = (IndexInput)outerInstance.outerInstance.input.Clone();
 
                         try
                         {
                             // Subsample the index terms
                             clone1.Seek(packedIndexStart);
-                            PackedInt32s.IReaderIterator termsDictOffsetsIter = PackedInt32s.GetReaderIterator(clone1,
-                                PackedInt32s.DEFAULT_BUFFER_SIZE);
+                            PackedInt32s.IReaderIterator termsDictOffsetsIter = PackedInt32s.GetReaderIterator(clone1, PackedInt32s.DEFAULT_BUFFER_SIZE);
 
                             clone2.Seek(packedOffsetsStart);
-                            PackedInt32s.IReaderIterator termOffsetsIter = PackedInt32s.GetReaderIterator(clone2,
-                                PackedInt32s.DEFAULT_BUFFER_SIZE);
+                            PackedInt32s.IReaderIterator termOffsetsIter = PackedInt32s.GetReaderIterator(clone2, PackedInt32s.DEFAULT_BUFFER_SIZE);
 
                             // TODO: often we can get by w/ fewer bits per
                             // value, below.. .but this'd be more complex:
                             // we'd have to try @ fewer bits and then grow
                             // if we overflowed it.
 
-                            PackedInt32s.Mutable termsDictOffsetsM = PackedInt32s.GetMutable(NumIndexTerms,
-                                termsDictOffsetsIter.BitsPerValue, PackedInt32s.DEFAULT);
-                            PackedInt32s.Mutable termOffsetsM = PackedInt32s.GetMutable(NumIndexTerms + 1,
-                                termOffsetsIter.BitsPerValue, PackedInt32s.DEFAULT);
+                            PackedInt32s.Mutable termsDictOffsetsM = PackedInt32s.GetMutable(this.numIndexTerms, termsDictOffsetsIter.BitsPerValue, PackedInt32s.DEFAULT);
+                            PackedInt32s.Mutable termOffsetsM = PackedInt32s.GetMutable(this.numIndexTerms + 1, termOffsetsIter.BitsPerValue, PackedInt32s.DEFAULT);
 
-                            TermsDictOffsets = termsDictOffsetsM;
-                            TermOffsets = termOffsetsM;
+                            termsDictOffsets = termsDictOffsetsM;
+                            termOffsets = termOffsetsM;
 
                             int upto = 0;
 
                             long termOffsetUpto = 0;
 
-                            while (upto < this.NumIndexTerms)
+                            while (upto < this.numIndexTerms)
                             {
                                 // main file offset copies straight over
                                 termsDictOffsetsM.Set(upto, termsDictOffsetsIter.Next());
@@ -437,28 +403,24 @@ namespace Lucene.Net.Codecs.BlockTerms
 
                                 long termOffset = termOffsetsIter.Next();
                                 long nextTermOffset = termOffsetsIter.Next();
-                                int numTermBytes = (int) (nextTermOffset - termOffset);
+                                int numTermBytes = (int)(nextTermOffset - termOffset);
 
                                 clone.Seek(indexStart + termOffset);
-                                
-                                Debug.Assert(indexStart + termOffset < clone.Length,
-                                    string.Format("IndexStart: {0}, TermOffset: {1}, Len: {2}", indexStart, termOffset,
-                                        clone.Length));
-                                
+                                Debug.Assert(indexStart + termOffset < clone.Length, "indexStart=" + indexStart + " termOffset=" + termOffset + " len=" + clone.Length);
                                 Debug.Assert(indexStart + termOffset + numTermBytes < clone.Length);
 
-                                outerInstance._termBytes.Copy(clone, numTermBytes);
+                                outerInstance.outerInstance.termBytes.Copy(clone, numTermBytes);
                                 termOffsetUpto += numTermBytes;
 
                                 upto++;
-                                if (upto == NumIndexTerms)
+                                if (upto == this.numIndexTerms)
                                 {
                                     break;
                                 }
-                                
+
                                 // skip terms:
                                 termsDictOffsetsIter.Next();
-                                for (int i = 0; i < outerInstance._indexDivisor - 2; i++)
+                                for (int i = 0; i < outerInstance.outerInstance.indexDivisor - 2; i++)
                                 {
                                     termOffsetsIter.Next();
                                     termsDictOffsetsIter.Next();
@@ -479,8 +441,8 @@ namespace Lucene.Net.Codecs.BlockTerms
                 /// <summary>Returns approximate RAM bytes Used</summary>
                 public long RamBytesUsed()
                 {
-                    return ((TermOffsets != null) ? TermOffsets.RamBytesUsed() : 0) +
-                            ((TermsDictOffsets != null) ? TermsDictOffsets.RamBytesUsed() : 0);
+                    return ((termOffsets != null) ? termOffsets.RamBytesUsed() : 0) +
+                        ((termsDictOffsets != null) ? termsDictOffsets.RamBytesUsed() : 0);
                 }
             }
         }
@@ -488,32 +450,32 @@ namespace Lucene.Net.Codecs.BlockTerms
         public override FieldIndexEnum GetFieldEnum(FieldInfo fieldInfo)
         {
             FieldIndexData fieldData;
-            if (!_fields.TryGetValue(fieldInfo, out fieldData) || fieldData == null)
+            if (!fields.TryGetValue(fieldInfo, out fieldData) || fieldData == null)
             {
                 return null;
             }
             else
-            { 
+            {
                 return new IndexEnum(this, fieldData.coreIndex);
             }
         }
 
         public override void Dispose()
         {
-            if (_input != null && !_indexLoaded)
+            if (input != null && !indexLoaded)
             {
-                _input.Dispose();
+                input.Dispose();
             }
         }
 
         private void SeekDir(IndexInput input, long dirOffset)
         {
-            if (_version >= FixedGapTermsIndexWriter.VERSION_CHECKSUM)
+            if (version >= FixedGapTermsIndexWriter.VERSION_CHECKSUM)
             {
                 input.Seek(input.Length - CodecUtil.FooterLength() - 8);
                 dirOffset = input.ReadInt64();
             }
-            else if (_version >= FixedGapTermsIndexWriter.VERSION_APPEND_ONLY)
+            else if (version >= FixedGapTermsIndexWriter.VERSION_APPEND_ONLY)
             {
                 input.Seek(input.Length - 8);
                 dirOffset = input.ReadInt64();
@@ -523,11 +485,13 @@ namespace Lucene.Net.Codecs.BlockTerms
 
         public override long RamBytesUsed()
         {
-            long sizeInBytes = ((_termBytes != null) ? _termBytes.RamBytesUsed() : 0) +
-                                ((_termBytesReader != null) ? _termBytesReader.RamBytesUsed() : 0);
-
-            return _fields.Values.Aggregate(sizeInBytes,
-                (current, entry) => (current + entry.coreIndex.RamBytesUsed()));
+            long sizeInBytes = ((termBytes != null) ? termBytes.RamBytesUsed() : 0) +
+                ((termBytesReader != null) ? termBytesReader.RamBytesUsed() : 0);
+            foreach (FieldIndexData entry in fields.Values)
+            {
+                sizeInBytes += entry.coreIndex.RamBytesUsed();
+            }
+            return sizeInBytes;
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d21561d3/src/Lucene.Net.Codecs/BlockTerms/FixedGapTermsIndexWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/BlockTerms/FixedGapTermsIndexWriter.cs b/src/Lucene.Net.Codecs/BlockTerms/FixedGapTermsIndexWriter.cs
index 1751f83..a96b432 100644
--- a/src/Lucene.Net.Codecs/BlockTerms/FixedGapTermsIndexWriter.cs
+++ b/src/Lucene.Net.Codecs/BlockTerms/FixedGapTermsIndexWriter.cs
@@ -39,31 +39,30 @@ namespace Lucene.Net.Codecs.BlockTerms
         protected IndexOutput m_output;
 
         /// <summary>Extension of terms index file</summary>
-        internal const string TERMS_INDEX_EXTENSION = "tii";
-        internal const string CODEC_NAME = "SIMPLE_STANDARD_TERMS_INDEX";
-        internal const int VERSION_START = 0;
-        internal const int VERSION_APPEND_ONLY = 1;
-        internal const int VERSION_CHECKSUM = 1000; // 4.x "skipped" trunk's monotonic addressing: give any user a nice exception
-        internal const int VERSION_CURRENT = VERSION_CHECKSUM;
+        internal readonly static string TERMS_INDEX_EXTENSION = "tii";
+        internal readonly static string CODEC_NAME = "SIMPLE_STANDARD_TERMS_INDEX";
+        internal readonly static int VERSION_START = 0;
+        internal readonly static int VERSION_APPEND_ONLY = 1;
+        internal readonly static int VERSION_CHECKSUM = 1000; // 4.x "skipped" trunk's monotonic addressing: give any user a nice exception
+        internal readonly static int VERSION_CURRENT = VERSION_CHECKSUM;
 
-        private readonly int _termIndexInterval;
+        private readonly int termIndexInterval;
 
-        private readonly List<SimpleFieldWriter> _fields = new List<SimpleFieldWriter>();
+        private readonly IList<SimpleFieldWriter> fields = new List<SimpleFieldWriter>();
 
-        private readonly FieldInfos _fieldInfos; // unread
+        private readonly FieldInfos fieldInfos; // unread
 
         public FixedGapTermsIndexWriter(SegmentWriteState state)
         {
-            string indexFileName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix,
-                TERMS_INDEX_EXTENSION);
-            _termIndexInterval = state.TermIndexInterval;
+            string indexFileName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, TERMS_INDEX_EXTENSION);
+            termIndexInterval = state.TermIndexInterval;
             m_output = state.Directory.CreateOutput(indexFileName, state.Context);
             bool success = false;
             try
             {
-                _fieldInfos = state.FieldInfos;
+                fieldInfos = state.FieldInfos;
                 WriteHeader(m_output);
-                m_output.WriteInt32(_termIndexInterval);
+                m_output.WriteInt32(termIndexInterval);
                 success = true;
             }
             finally
@@ -84,7 +83,7 @@ namespace Lucene.Net.Codecs.BlockTerms
         {
             //System.out.println("FGW: addFfield=" + field.name);
             SimpleFieldWriter writer = new SimpleFieldWriter(this, field, termsFilePointer);
-            _fields.Add(writer);
+            fields.Add(writer);
             return writer;
         }
 
@@ -148,18 +147,20 @@ namespace Lucene.Net.Codecs.BlockTerms
             {
                 // First term is first indexed term:
                 //System.output.println("FGW: checkIndexTerm text=" + text.utf8ToString());
-                if (0 == (numTerms++ % outerInstance._termIndexInterval))
+                if (0 == (numTerms++ % outerInstance.termIndexInterval))
                 {
                     return true;
                 }
-                // save last term just before next index term so we
-                // can compute wasted suffix
-                else if (0 == numTerms % outerInstance._termIndexInterval)
+                else
                 {
-                    lastTerm.CopyBytes(text);
+                    if (0 == numTerms % outerInstance.termIndexInterval)
+                    {
+                        // save last term just before next index term so we
+                        // can compute wasted suffix
+                        lastTerm.CopyBytes(text);
+                    }
+                    return false;
                 }
-
-                return false;
             }
 
             public override void Add(BytesRef text, TermStats stats, long termsFilePointer)
@@ -198,9 +199,7 @@ namespace Lucene.Net.Codecs.BlockTerms
                 // write primary terms dict offsets
                 packedIndexStart = outerInstance.m_output.FilePointer;
 
-                PackedInt32s.Writer w = PackedInt32s.GetWriter(outerInstance.m_output, numIndexTerms,
-                    PackedInt32s.BitsRequired(termsFilePointer),
-                    PackedInt32s.DEFAULT);
+                PackedInt32s.Writer w = PackedInt32s.GetWriter(outerInstance.m_output, numIndexTerms, PackedInt32s.BitsRequired(termsFilePointer), PackedInt32s.DEFAULT);
 
                 // relative to our indexStart
                 long upto = 0;
@@ -214,8 +213,7 @@ namespace Lucene.Net.Codecs.BlockTerms
                 packedOffsetsStart = outerInstance.m_output.FilePointer;
 
                 // write offsets into the byte[] terms
-                w = PackedInt32s.GetWriter(outerInstance.m_output, 1 + numIndexTerms, PackedInt32s.BitsRequired(totTermLength),
-                    PackedInt32s.DEFAULT);
+                w = PackedInt32s.GetWriter(outerInstance.m_output, 1 + numIndexTerms, PackedInt32s.BitsRequired(totTermLength), PackedInt32s.DEFAULT);
                 upto = 0;
                 for (int i = 0; i < numIndexTerms; i++)
                 {
@@ -240,12 +238,12 @@ namespace Lucene.Net.Codecs.BlockTerms
                 try
                 {
                     long dirStart = m_output.FilePointer;
-                    int fieldCount = _fields.Count;
+                    int fieldCount = fields.Count;
 
                     int nonNullFieldCount = 0;
                     for (int i = 0; i < fieldCount; i++)
                     {
-                        SimpleFieldWriter field = _fields[i];
+                        SimpleFieldWriter field = fields[i];
                         if (field.numIndexTerms > 0)
                         {
                             nonNullFieldCount++;
@@ -255,7 +253,7 @@ namespace Lucene.Net.Codecs.BlockTerms
                     m_output.WriteVInt32(nonNullFieldCount);
                     for (int i = 0; i < fieldCount; i++)
                     {
-                        SimpleFieldWriter field = _fields[i];
+                        SimpleFieldWriter field = fields[i];
                         if (field.numIndexTerms > 0)
                         {
                             m_output.WriteVInt32(field.fieldInfo.Number);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d21561d3/src/Lucene.Net.Codecs/BlockTerms/VariableGapTermsIndexReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/BlockTerms/VariableGapTermsIndexReader.cs b/src/Lucene.Net.Codecs/BlockTerms/VariableGapTermsIndexReader.cs
index 340b18e..ae692c6 100644
--- a/src/Lucene.Net.Codecs/BlockTerms/VariableGapTermsIndexReader.cs
+++ b/src/Lucene.Net.Codecs/BlockTerms/VariableGapTermsIndexReader.cs
@@ -6,7 +6,6 @@ using Lucene.Net.Util.Fst;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Linq;
 
 namespace Lucene.Net.Codecs.BlockTerms
 {
@@ -34,59 +33,58 @@ namespace Lucene.Net.Codecs.BlockTerms
     /// </summary>
     public class VariableGapTermsIndexReader : TermsIndexReaderBase
     {
-        private readonly PositiveInt32Outputs _fstOutputs = PositiveInt32Outputs.Singleton;
-        private readonly int _indexDivisor;
+        private readonly PositiveInt32Outputs fstOutputs = PositiveInt32Outputs.Singleton;
+        private int indexDivisor;
 
-        private readonly IndexInput _input;       // Closed if indexLoaded is true:
-        private volatile bool _indexLoaded;
+        // Closed if indexLoaded is true:
+        private IndexInput input;
+        private volatile bool indexLoaded;
 
-        private readonly Dictionary<FieldInfo, FieldIndexData> _fields = new Dictionary<FieldInfo, FieldIndexData>();
+        private readonly IDictionary<FieldInfo, FieldIndexData> fields = new Dictionary<FieldInfo, FieldIndexData>();
 
-        private long _dirOffset;                 // start of the field info data
+        // start of the field info data
+        private long dirOffset;
 
-        private readonly int _version;
+        private readonly int version;
 
         private readonly string segment;
-        
+
         public VariableGapTermsIndexReader(Directory dir, FieldInfos fieldInfos, string segment, int indexDivisor,
             string segmentSuffix, IOContext context)
         {
-            _input =
-                dir.OpenInput(
-                    IndexFileNames.SegmentFileName(segment, segmentSuffix,
-                        VariableGapTermsIndexWriter.TERMS_INDEX_EXTENSION), new IOContext(context, true));
+            input = dir.OpenInput(IndexFileNames.SegmentFileName(segment, segmentSuffix, VariableGapTermsIndexWriter.TERMS_INDEX_EXTENSION), new IOContext(context, true));
             this.segment = segment;
             bool success = false;
             Debug.Assert(indexDivisor == -1 || indexDivisor > 0);
 
             try
             {
-                _version = ReadHeader(_input);
-                _indexDivisor = indexDivisor;
+                version = ReadHeader(input);
+                this.indexDivisor = indexDivisor;
 
-                if (_version >= VariableGapTermsIndexWriter.VERSION_CHECKSUM)
+                if (version >= VariableGapTermsIndexWriter.VERSION_CHECKSUM)
                 {
-                    CodecUtil.ChecksumEntireFile(_input);
+                    CodecUtil.ChecksumEntireFile(input);
                 }
-                
-                SeekDir(_input, _dirOffset);
+
+                SeekDir(input, dirOffset);
 
                 // Read directory
-                int numFields = _input.ReadVInt32();
+                int numFields = input.ReadVInt32();
                 if (numFields < 0)
                 {
-                    throw new CorruptIndexException("invalid numFields: " + numFields + " (resource=" + _input + ")");
+                    throw new CorruptIndexException("invalid numFields: " + numFields + " (resource=" + input + ")");
                 }
 
-                for (var i = 0; i < numFields; i++)
+                for (int i = 0; i < numFields; i++)
                 {
-                    int field = _input.ReadVInt32();
-                    long indexStart = _input.ReadVInt64();
+                    int field = input.ReadVInt32();
+                    long indexStart = input.ReadVInt64();
                     FieldInfo fieldInfo = fieldInfos.FieldInfo(field);
-                    FieldIndexData previous = _fields.Put(fieldInfo, new FieldIndexData(this, fieldInfo, indexStart));
+                    FieldIndexData previous = fields.Put(fieldInfo, new FieldIndexData(this, fieldInfo, indexStart));
                     if (previous != null)
                     {
-                        throw new CorruptIndexException("duplicate field: " + fieldInfo.Name + " (resource=" + _input +")");
+                        throw new CorruptIndexException("duplicate field: " + fieldInfo.Name + " (resource=" + input + ")");
                     }
                 }
                 success = true;
@@ -95,11 +93,11 @@ namespace Lucene.Net.Codecs.BlockTerms
             {
                 if (indexDivisor > 0)
                 {
-                    _input.Dispose();
-                    _input = null;
+                    input.Dispose();
+                    input = null;
                     if (success)
                     {
-                        _indexLoaded = true;
+                        indexLoaded = true;
                     }
                 }
             }
@@ -107,7 +105,7 @@ namespace Lucene.Net.Codecs.BlockTerms
 
         public override int Divisor
         {
-            get { return _indexDivisor; }
+            get { return indexDivisor; }
         }
 
         private int ReadHeader(IndexInput input)
@@ -116,58 +114,76 @@ namespace Lucene.Net.Codecs.BlockTerms
                 VariableGapTermsIndexWriter.VERSION_START, VariableGapTermsIndexWriter.VERSION_CURRENT);
             if (version < VariableGapTermsIndexWriter.VERSION_APPEND_ONLY)
             {
-                _dirOffset = input.ReadInt64();
+                dirOffset = input.ReadInt64();
             }
             return version;
         }
 
         private class IndexEnum : FieldIndexEnum
         {
-            private readonly BytesRefFSTEnum<long?> _fstEnum;
-            private BytesRefFSTEnum.InputOutput<long?> _current;
+            private readonly BytesRefFSTEnum<long?> fstEnum;
+            private BytesRefFSTEnum.InputOutput<long?> current;
 
             public IndexEnum(FST<long?> fst)
             {
-                _fstEnum = new BytesRefFSTEnum<long?>(fst);
+                fstEnum = new BytesRefFSTEnum<long?>(fst);
             }
 
             public override BytesRef Term
             {
-                get { return _current == null ? null : _current.Input; }
+                get
+                {
+                    if (current == null)
+                    {
+                        return null;
+                    }
+                    else
+                    {
+                        return current.Input;
+                    }
+                }
             }
 
             public override long Seek(BytesRef target)
             {
                 //System.out.println("VGR: seek field=" + fieldInfo.name + " target=" + target);
-                _current = _fstEnum.SeekFloor(target);
-                if (_current.Output.HasValue)
+                current = fstEnum.SeekFloor(target);
+                //System.out.println("  got input=" + current.input + " output=" + current.output);
+                if (current.Output.HasValue)
+                {
+                    return current.Output.Value;
+                }
+                else
                 {
-                    //System.out.println("  got input=" + current.input + " output=" + current.output);
-                    return _current.Output.Value;
+                    throw new NullReferenceException("_current.Output is null"); // LUCENENET NOTE: NullReferenceException would be thrown in Java, so doing it here
                 }
-                throw new NullReferenceException("_current.Output is null"); // LUCENENET NOTE: NullReferenceException would be thrown in Java, so doing it here
             }
 
             public override long Next()
             {
                 //System.out.println("VGR: next field=" + fieldInfo.name);
-                _current = _fstEnum.Next();
-                if (_current == null)
+                current = fstEnum.Next();
+                if (current == null)
                 {
                     //System.out.println("  eof");
                     return -1;
                 }
-
-                if (_current.Output.HasValue)
+                else
                 {
-                    return _current.Output.Value;
+                    if (current.Output.HasValue)
+                    {
+                        return current.Output.Value;
+                    }
+                    else
+                    {
+                        throw new NullReferenceException("_current.Output is null"); // LUCENENET NOTE: NullReferenceException would be thrown in Java, so doing it here
+                    }
                 }
-                throw new NullReferenceException("_current.Output is null"); // LUCENENET NOTE: NullReferenceException would be thrown in Java, so doing it here
             }
 
             public override long Ord
             {
-                get { throw new NotSupportedException(); } 
+                get { throw new NotSupportedException(); }
             }
 
             public override long Seek(long ord)
@@ -185,30 +201,31 @@ namespace Lucene.Net.Codecs.BlockTerms
         {
             private readonly VariableGapTermsIndexReader outerInstance;
 
-            private readonly long _indexStart;
+            private readonly long indexStart;
             // Set only if terms index is loaded:
             internal volatile FST<long?> fst;
-            
+
             public FieldIndexData(VariableGapTermsIndexReader outerInstance, FieldInfo fieldInfo, long indexStart)
             {
                 this.outerInstance = outerInstance;
 
-                _indexStart = indexStart;
+                this.indexStart = indexStart;
 
-                if (this.outerInstance._indexDivisor > 0)
+                if (outerInstance.indexDivisor > 0)
                 {
                     LoadTermsIndex();
-                }  
+                }
             }
 
             private void LoadTermsIndex()
             {
                 if (fst == null)
                 {
-                    IndexInput clone = (IndexInput)outerInstance._input.Clone();
-                    clone.Seek(_indexStart);
-                    fst = new FST<long?>(clone, outerInstance._fstOutputs);
-                    clone.Dispose(); // LUCENENET TODO: No using block here is bad...
+                    using (IndexInput clone = (IndexInput)outerInstance.input.Clone())
+                    {
+                        clone.Seek(indexStart);
+                        fst = new FST<long?>(clone, outerInstance.fstOutputs);
+                    } // clone.Dispose();
 
                     /*
                     final String dotFileName = segment + "_" + fieldInfo.name + ".dot";
@@ -218,7 +235,7 @@ namespace Lucene.Net.Codecs.BlockTerms
                     w.close();
                     */
 
-                    if (outerInstance._indexDivisor > 1)
+                    if (outerInstance.indexDivisor > 1)
                     {
                         // subsample
                         Int32sRef scratchIntsRef = new Int32sRef();
@@ -226,10 +243,10 @@ namespace Lucene.Net.Codecs.BlockTerms
                         Builder<long?> builder = new Builder<long?>(FST.INPUT_TYPE.BYTE1, outputs);
                         BytesRefFSTEnum<long?> fstEnum = new BytesRefFSTEnum<long?>(fst);
                         BytesRefFSTEnum.InputOutput<long?> result;
-                        int count = outerInstance._indexDivisor;
+                        int count = outerInstance.indexDivisor;
                         while ((result = fstEnum.Next()) != null)
                         {
-                            if (count == outerInstance._indexDivisor)
+                            if (count == outerInstance.indexDivisor)
                             {
                                 builder.Add(Util.Fst.Util.ToInt32sRef(result.Input, scratchIntsRef), result.Output);
                                 count = 0;
@@ -251,7 +268,7 @@ namespace Lucene.Net.Codecs.BlockTerms
         public override FieldIndexEnum GetFieldEnum(FieldInfo fieldInfo)
         {
             FieldIndexData fieldData;
-            if (!_fields.TryGetValue(fieldInfo, out fieldData) || fieldData == null)
+            if (!fields.TryGetValue(fieldInfo, out fieldData) || fieldData == null || fieldData.fst == null)
             {
                 return null;
             }
@@ -263,20 +280,20 @@ namespace Lucene.Net.Codecs.BlockTerms
 
         public override void Dispose()
         {
-            if (_input != null && !_indexLoaded)
-            { 
-                _input.Dispose(); 
-            } 
+            if (input != null && !indexLoaded)
+            {
+                input.Dispose();
+            }
         }
 
         private void SeekDir(IndexInput input, long dirOffset)
         {
-            if (_version >= VariableGapTermsIndexWriter.VERSION_CHECKSUM)
+            if (version >= VariableGapTermsIndexWriter.VERSION_CHECKSUM)
             {
                 input.Seek(input.Length - CodecUtil.FooterLength() - 8);
                 dirOffset = input.ReadInt64();
             }
-            else if (_version >= VariableGapTermsIndexWriter.VERSION_APPEND_ONLY)
+            else if (version >= VariableGapTermsIndexWriter.VERSION_APPEND_ONLY)
             {
                 input.Seek(input.Length - 8);
                 dirOffset = input.ReadInt64();
@@ -287,7 +304,7 @@ namespace Lucene.Net.Codecs.BlockTerms
         public override long RamBytesUsed()
         {
             long sizeInBytes = 0;
-            foreach (FieldIndexData entry in _fields.Values)
+            foreach (FieldIndexData entry in fields.Values)
             {
                 sizeInBytes += entry.RamBytesUsed();
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d21561d3/src/Lucene.Net.Codecs/BlockTerms/VariableGapTermsIndexWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/BlockTerms/VariableGapTermsIndexWriter.cs b/src/Lucene.Net.Codecs/BlockTerms/VariableGapTermsIndexWriter.cs
index f545666..4b51bc1 100644
--- a/src/Lucene.Net.Codecs/BlockTerms/VariableGapTermsIndexWriter.cs
+++ b/src/Lucene.Net.Codecs/BlockTerms/VariableGapTermsIndexWriter.cs
@@ -39,18 +39,18 @@ namespace Lucene.Net.Codecs.BlockTerms
         protected IndexOutput m_output;
 
         /// <summary>Extension of terms index file</summary>
-        internal const string TERMS_INDEX_EXTENSION = "tiv";
+        internal readonly static string TERMS_INDEX_EXTENSION = "tiv";
 
-        internal const string CODEC_NAME = "VARIABLE_GAP_TERMS_INDEX";
-        internal const int VERSION_START = 0;
-        internal const int VERSION_APPEND_ONLY = 1;
-        internal const int VERSION_CHECKSUM = 2;
-        internal const int VERSION_CURRENT = VERSION_CHECKSUM;
+        internal readonly static string CODEC_NAME = "VARIABLE_GAP_TERMS_INDEX";
+        internal readonly static int VERSION_START = 0;
+        internal readonly static int VERSION_APPEND_ONLY = 1;
+        internal readonly static int VERSION_CHECKSUM = 2;
+        internal readonly static int VERSION_CURRENT = VERSION_CHECKSUM;
 
-        private readonly IList<FstFieldWriter> _fields = new List<FstFieldWriter>();
+        private readonly IList<FSTFieldWriter> fields = new List<FSTFieldWriter>();
 
         private readonly FieldInfos fieldInfos; // unread
-        private readonly IndexTermSelector _policy;
+        private readonly IndexTermSelector policy;
 
         /// <summary>
         /// Hook for selecting which terms should be placed in the terms index
@@ -77,33 +77,33 @@ namespace Lucene.Net.Codecs.BlockTerms
         /// </remarks>
         public sealed class EveryNTermSelector : IndexTermSelector
         {
-            private int _count;
-            private readonly int _interval;
+            private int count;
+            private readonly int interval;
 
             public EveryNTermSelector(int interval)
             {
-                this._interval = interval;
+                this.interval = interval;
                 // First term is first indexed term
-                _count = interval; 
+                count = interval;
             }
 
             public override bool IsIndexTerm(BytesRef term, TermStats stats)
             {
-                if (_count >= _interval)
+                if (count >= interval)
                 {
-                    _count = 1;
+                    count = 1;
                     return true;
                 }
                 else
                 {
-                    _count++;
+                    count++;
                     return false;
                 }
             }
 
             public override void NewField(FieldInfo fieldInfo)
             {
-                _count = _interval;
+                count = interval;
             }
         }
 
@@ -114,36 +114,36 @@ namespace Lucene.Net.Codecs.BlockTerms
         /// </summary>
         public sealed class EveryNOrDocFreqTermSelector : IndexTermSelector
         {
-            private int _count;
-            private readonly int _docFreqThresh;
-            private readonly int _interval;
+            private int count;
+            private readonly int docFreqThresh;
+            private readonly int interval;
 
             public EveryNOrDocFreqTermSelector(int docFreqThresh, int interval)
             {
-                this._interval = interval;
-                this._docFreqThresh = docFreqThresh;
+                this.interval = interval;
+                this.docFreqThresh = docFreqThresh;
 
-                // First term is first indexed term
-                _count = interval; 
+                // First term is first indexed term:
+                count = interval;
             }
 
             public override bool IsIndexTerm(BytesRef term, TermStats stats)
             {
-                if (stats.DocFreq >= _docFreqThresh || _count >= _interval)
+                if (stats.DocFreq >= docFreqThresh || count >= interval)
                 {
-                    _count = 1;
+                    count = 1;
                     return true;
                 }
                 else
                 {
-                    _count++;
+                    count++;
                     return false;
                 }
             }
 
             public override void NewField(FieldInfo fieldInfo)
             {
-                _count = _interval;
+                count = interval;
             }
         }
 
@@ -182,14 +182,13 @@ namespace Lucene.Net.Codecs.BlockTerms
 
         public VariableGapTermsIndexWriter(SegmentWriteState state, IndexTermSelector policy)
         {
-            string indexFileName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix,
-                TERMS_INDEX_EXTENSION);
+            string indexFileName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, TERMS_INDEX_EXTENSION);
             m_output = state.Directory.CreateOutput(indexFileName, state.Context);
             bool success = false;
             try
             {
                 fieldInfos = state.FieldInfos;
-                this._policy = policy;
+                this.policy = policy;
                 WriteHeader(m_output);
                 success = true;
             }
@@ -210,9 +209,9 @@ namespace Lucene.Net.Codecs.BlockTerms
         public override FieldWriter AddField(FieldInfo field, long termsFilePointer)
         {
             ////System.out.println("VGW: field=" + field.name);
-            _policy.NewField(field);
-            FstFieldWriter writer = new FstFieldWriter(this, field, termsFilePointer);
-            _fields.Add(writer);
+            policy.NewField(field);
+            FSTFieldWriter writer = new FSTFieldWriter(this, field, termsFilePointer);
+            fields.Add(writer);
             return writer;
         }
 
@@ -225,7 +224,6 @@ namespace Lucene.Net.Codecs.BlockTerms
             // As long as codec sorts terms in unicode codepoint
             // order, we can safely strip off the non-distinguishing
             // suffix to save RAM in the loaded terms index.
-
             int idxTermOffset = indexedTerm.Offset;
             int priorTermOffset = priorTerm.Offset;
             int limit = Math.Min(priorTerm.Length, indexedTerm.Length);
@@ -236,85 +234,86 @@ namespace Lucene.Net.Codecs.BlockTerms
                     return byteIdx + 1;
                 }
             }
-
             return Math.Min(1 + priorTerm.Length, indexedTerm.Length);
         }
 
-        private class FstFieldWriter : FieldWriter
+        private class FSTFieldWriter : FieldWriter
         {
             private readonly VariableGapTermsIndexWriter outerInstance;
 
-            private readonly Builder<long?> _fstBuilder;
+            private readonly Builder<long?> fstBuilder;
             private readonly PositiveInt32Outputs fstOutputs;
-            private readonly long _startTermsFilePointer;
+            private readonly long startTermsFilePointer;
 
-            internal FieldInfo FieldInfo { get; private set; }
-            internal FST<long?> Fst { get; private set; }
-            internal long IndexStart { get; private set; }
+            internal readonly FieldInfo fieldInfo;
+            internal FST<long?> fst;
+            internal readonly long indexStart;
 
-            private readonly BytesRef _lastTerm = new BytesRef();
-            private bool _first = true;
+            private readonly BytesRef lastTerm = new BytesRef();
+            private bool first = true;
 
-            public FstFieldWriter(VariableGapTermsIndexWriter outerInstance, FieldInfo fieldInfo, long termsFilePointer)
+            public FSTFieldWriter(VariableGapTermsIndexWriter outerInstance, FieldInfo fieldInfo, long termsFilePointer)
             {
                 this.outerInstance = outerInstance;
 
-                this.FieldInfo = fieldInfo;
+                this.fieldInfo = fieldInfo;
                 fstOutputs = PositiveInt32Outputs.Singleton;
-                _fstBuilder = new Builder<long?>(FST.INPUT_TYPE.BYTE1, fstOutputs);
-                IndexStart = this.outerInstance.m_output.FilePointer;
+                fstBuilder = new Builder<long?>(FST.INPUT_TYPE.BYTE1, fstOutputs);
+                indexStart = outerInstance.m_output.FilePointer;
                 ////System.out.println("VGW: field=" + fieldInfo.name);
 
                 // Always put empty string in
-                _fstBuilder.Add(new Int32sRef(), termsFilePointer);
-                _startTermsFilePointer = termsFilePointer;
+                fstBuilder.Add(new Int32sRef(), termsFilePointer);
+                startTermsFilePointer = termsFilePointer;
             }
 
             public override bool CheckIndexTerm(BytesRef text, TermStats stats)
             {
+                //System.out.println("VGW: index term=" + text.utf8ToString());
                 // NOTE: we must force the first term per field to be
                 // indexed, in case policy doesn't:
-                if (outerInstance._policy.IsIndexTerm(text, stats) || _first)
+                if (outerInstance.policy.IsIndexTerm(text, stats) || first)
                 {
-                    _first = false;
+                    first = false;
+                    //System.out.println("  YES");
                     return true;
                 }
                 else
                 {
-                    _lastTerm.CopyBytes(text);
+                    lastTerm.CopyBytes(text);
                     return false;
                 }
             }
 
-            private readonly Int32sRef _scratchIntsRef = new Int32sRef();
+            private readonly Int32sRef scratchIntsRef = new Int32sRef();
 
             public override void Add(BytesRef text, TermStats stats, long termsFilePointer)
             {
                 if (text.Length == 0)
                 {
                     // We already added empty string in ctor
-                    Debug.Assert(termsFilePointer == _startTermsFilePointer);
+                    Debug.Assert(termsFilePointer == startTermsFilePointer);
                     return;
                 }
                 int lengthSave = text.Length;
-                text.Length = outerInstance.IndexedTermPrefixLength(_lastTerm, text);
+                text.Length = outerInstance.IndexedTermPrefixLength(lastTerm, text);
                 try
                 {
-                    _fstBuilder.Add(Util.Fst.Util.ToInt32sRef(text, _scratchIntsRef), termsFilePointer);
+                    fstBuilder.Add(Util.Fst.Util.ToInt32sRef(text, scratchIntsRef), termsFilePointer);
                 }
                 finally
                 {
                     text.Length = lengthSave;
                 }
-                _lastTerm.CopyBytes(text);
+                lastTerm.CopyBytes(text);
             }
 
             public override void Finish(long termsFilePointer)
             {
-                Fst = _fstBuilder.Finish();
-                if (Fst != null)
+                fst = fstBuilder.Finish();
+                if (fst != null)
                 {
-                    Fst.Save(outerInstance.m_output);
+                    fst.Save(outerInstance.m_output);
                 }
             }
         }
@@ -326,13 +325,13 @@ namespace Lucene.Net.Codecs.BlockTerms
                 try
                 {
                     long dirStart = m_output.FilePointer;
-                    int fieldCount = _fields.Count;
+                    int fieldCount = fields.Count;
 
                     int nonNullFieldCount = 0;
                     for (int i = 0; i < fieldCount; i++)
                     {
-                        FstFieldWriter field = _fields[i];
-                        if (field.Fst != null)
+                        FSTFieldWriter field = fields[i];
+                        if (field.fst != null)
                         {
                             nonNullFieldCount++;
                         }
@@ -341,11 +340,11 @@ namespace Lucene.Net.Codecs.BlockTerms
                     m_output.WriteVInt32(nonNullFieldCount);
                     for (int i = 0; i < fieldCount; i++)
                     {
-                        FstFieldWriter field = _fields[i];
-                        if (field.Fst != null)
+                        FSTFieldWriter field = fields[i];
+                        if (field.fst != null)
                         {
-                            m_output.WriteVInt32(field.FieldInfo.Number);
-                            m_output.WriteVInt64(field.IndexStart);
+                            m_output.WriteVInt32(field.fieldInfo.Number);
+                            m_output.WriteVInt64(field.indexStart);
                         }
                     }
                     WriteTrailer(dirStart);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d21561d3/src/Lucene.Net.Core/Codecs/Lucene3x/TermInfosReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/TermInfosReader.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/TermInfosReader.cs
index 1e2c5f5..5af2731 100644
--- a/src/Lucene.Net.Core/Codecs/Lucene3x/TermInfosReader.cs
+++ b/src/Lucene.Net.Core/Codecs/Lucene3x/TermInfosReader.cs
@@ -89,7 +89,7 @@ namespace Lucene.Net.Codecs.Lucene3x
                 return term.GetHashCode();
             }
 
-            public override DoubleBarrelLRUCache.CloneableKey Clone()
+            public override object Clone()
             {
                 return new CloneableTerm(term);
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d21561d3/src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs b/src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs
index 6d1899b..7944090 100644
--- a/src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs
+++ b/src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs
@@ -139,7 +139,7 @@ namespace Lucene.Net.Util
         /// </summary>
         public abstract class CloneableKey
         {
-            public abstract CloneableKey Clone();
+            public abstract object Clone();
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d21561d3/src/Lucene.Net.Tests/Util/TestDoubleBarrelLRUCache.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Util/TestDoubleBarrelLRUCache.cs b/src/Lucene.Net.Tests/Util/TestDoubleBarrelLRUCache.cs
index 5b3f7bb..5a05124 100644
--- a/src/Lucene.Net.Tests/Util/TestDoubleBarrelLRUCache.cs
+++ b/src/Lucene.Net.Tests/Util/TestDoubleBarrelLRUCache.cs
@@ -192,7 +192,7 @@ namespace Lucene.Net.Util
                 return Value.GetHashCode();
             }
 
-            public override DoubleBarrelLRUCache.CloneableKey Clone()
+            public override object Clone()
             {
                 return new CloneableObject(Value);
             }
@@ -217,7 +217,7 @@ namespace Lucene.Net.Util
                 return Value.GetHashCode();
             }
 
-            public override DoubleBarrelLRUCache.CloneableKey Clone()
+            public override object Clone()
             {
                 return new CloneableInteger(Value);
             }


Mime
View raw message