lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [03/23] lucenenet git commit: Lucene.Net.Codecs.BlockTerms: Re-ported BlockTermsReader and BlockTermsWriter to ensure all of the variables are referring to the correct scope.
Date Sun, 19 Mar 2017 23:19:58 GMT
Lucene.Net.Codecs.BlockTerms: Re-ported BlockTermsReader and BlockTermsWriter to ensure all of the variables are referring to the correct scope.


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

Branch: refs/heads/api-work
Commit: 1246d5c4a2dbc82318a17a8185a689b97bb1a29d
Parents: 0a81284
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Mar 19 19:11:48 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Mar 19 19:11:48 2017 +0700

----------------------------------------------------------------------
 .../BlockTerms/BlockTermsReader.cs              | 545 +++++++++----------
 .../BlockTerms/BlockTermsWriter.cs              | 204 ++++---
 2 files changed, 362 insertions(+), 387 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1246d5c4/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs
index 6c73fea..8348cfb 100644
--- a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs
+++ b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsReader.cs
@@ -42,21 +42,21 @@ namespace Lucene.Net.Codecs.BlockTerms
     public class BlockTermsReader : FieldsProducer
     {
         // Open input to the main terms dict file (_X.tis)
-        private readonly IndexInput _input;
+        private readonly IndexInput input;
 
         // Reads the terms dict entries, to gather state to
         // produce DocsEnum on demand
-        private readonly PostingsReaderBase _postingsReader;
+        private readonly PostingsReaderBase postingsReader;
 
-        private readonly IDictionary<string, FieldReader> _fields = new SortedDictionary<string, FieldReader>(StringComparer.Ordinal);
+        private readonly IDictionary<string, FieldReader> fields = new SortedDictionary<string, FieldReader>(StringComparer.Ordinal);
 
         // Reads the terms index
-        private TermsIndexReaderBase _indexReader;
+        private TermsIndexReaderBase indexReader;
 
         // keeps the dirStart offset
-        private long _dirOffset;
+        private long dirOffset;
 
-        private readonly int _version;
+        private readonly int version;
 
         /// <summary>
         /// Used as a key for the terms cache
@@ -79,10 +79,10 @@ namespace Lucene.Net.Codecs.BlockTerms
             public override bool Equals(object other)
             {
                 var o = (FieldAndTerm)other;
-                return o.Field.Equals(Field) && Term.BytesEquals(o.Term);
+                return o.Field.Equals(Field, StringComparison.Ordinal) && Term.BytesEquals(o.Term);
             }
 
-            public override DoubleBarrelLRUCache.CloneableKey Clone()
+            public override object Clone()
             {
                 return new FieldAndTerm(this);
             }
@@ -99,75 +99,55 @@ namespace Lucene.Net.Codecs.BlockTerms
             PostingsReaderBase postingsReader, IOContext context,
             string segmentSuffix)
         {
-            _postingsReader = postingsReader;
+            this.postingsReader = postingsReader;
 
             // this.segment = segment;
-            _input =
-                dir.OpenInput(
-                    IndexFileNames.SegmentFileName(info.Name, segmentSuffix, BlockTermsWriter.TERMS_EXTENSION),
-                    context);
+            input = dir.OpenInput(IndexFileNames.SegmentFileName(info.Name, segmentSuffix, BlockTermsWriter.TERMS_EXTENSION),
+                               context);
 
             bool success = false;
             try
             {
-                _version = ReadHeader(_input);
+                version = ReadHeader(input);
 
                 // Have PostingsReader init itself
-                postingsReader.Init(_input);
+                postingsReader.Init(input);
 
                 // Read per-field details
-                SeekDir(_input, _dirOffset);
+                SeekDir(input, dirOffset);
 
-                int numFields = _input.ReadVInt32();
+                int numFields = input.ReadVInt32();
                 if (numFields < 0)
                 {
-                    throw new CorruptIndexException(string.Format("Invalid number of fields: {0}, Resource: {1}",
-                        numFields, _input));
+                    throw new CorruptIndexException("invalid number of fields: " + numFields + " (resource=" + input + ")");
                 }
-
-                for (var i = 0; i < numFields; i++)
+                for (int i = 0; i < numFields; i++)
                 {
-                    int field = _input.ReadVInt32();
-                    long numTerms = _input.ReadVInt64();
-
+                    int field = input.ReadVInt32();
+                    long numTerms = input.ReadVInt64();
                     Debug.Assert(numTerms >= 0);
-
-                    long termsStartPointer = _input.ReadVInt64();
+                    long termsStartPointer = input.ReadVInt64();
                     FieldInfo fieldInfo = fieldInfos.FieldInfo(field);
-                    long sumTotalTermFreq = fieldInfo.IndexOptions == IndexOptions.DOCS_ONLY
-                        ? -1
-                        : _input.ReadVInt64();
-                    long sumDocFreq = _input.ReadVInt64();
-                    int docCount = _input.ReadVInt32();
-                    int longsSize = _version >= BlockTermsWriter.VERSION_META_ARRAY ? _input.ReadVInt32() : 0;
-
+                    long sumTotalTermFreq = fieldInfo.IndexOptions == IndexOptions.DOCS_ONLY ? -1 : input.ReadVInt64();
+                    long sumDocFreq = input.ReadVInt64();
+                    int docCount = input.ReadVInt32();
+                    int longsSize = version >= BlockTermsWriter.VERSION_META_ARRAY ? input.ReadVInt32() : 0;
                     if (docCount < 0 || docCount > info.DocCount)
-                    {
-                        // #docs with field must be <= #docs
-                        throw new CorruptIndexException(
-                            string.Format("Invalid DocCount: {0}, MaxDoc: {1}, Resource: {2}", docCount, info.DocCount,
-                                _input));
+                    { // #docs with field must be <= #docs
+                        throw new CorruptIndexException("invalid docCount: " + docCount + " maxDoc: " + info.DocCount + " (resource=" + input + ")");
                     }
-
                     if (sumDocFreq < docCount)
-                    {
-                        // #postings must be >= #docs with field
-                        throw new CorruptIndexException(
-                            string.Format("Invalid sumDocFreq: {0}, DocCount: {1}, Resource: {2}", sumDocFreq, docCount,
-                                _input));
+                    {  // #postings must be >= #docs with field
+                        throw new CorruptIndexException("invalid sumDocFreq: " + sumDocFreq + " docCount: " + docCount + " (resource=" + input + ")");
                     }
-
                     if (sumTotalTermFreq != -1 && sumTotalTermFreq < sumDocFreq)
-                    {
-                        // #positions must be >= #postings
-                        throw new CorruptIndexException(
-                            string.Format("Invalid sumTotalTermFreq: {0}, sumDocFreq: {1}, Resource: {2}",
-                                sumTotalTermFreq, sumDocFreq, _input));
+                    { // #positions must be >= #postings
+                        throw new CorruptIndexException("invalid sumTotalTermFreq: " + sumTotalTermFreq + " sumDocFreq: " + sumDocFreq + " (resource=" + input + ")");
                     }
-                    FieldReader previous = _fields.Put(fieldInfo.Name, new FieldReader(this, fieldInfo, numTerms, termsStartPointer, sumTotalTermFreq, sumDocFreq, docCount, longsSize));
+                    FieldReader previous = fields.Put(fieldInfo.Name, new FieldReader(this, fieldInfo, numTerms, termsStartPointer, sumTotalTermFreq, sumDocFreq, docCount, longsSize));
                     if (previous != null)
                     {
-                        throw new CorruptIndexException("duplicate fields: " + fieldInfo.Name + " (resource=" + _input +")");
+                        throw new CorruptIndexException("duplicate fields: " + fieldInfo.Name + " (resource=" + input + ")");
                     }
                 }
                 success = true;
@@ -176,34 +156,33 @@ namespace Lucene.Net.Codecs.BlockTerms
             {
                 if (!success)
                 {
-                    _input.Dispose();
+                    input.Dispose();
                 }
             }
 
-            _indexReader = indexReader;
+            this.indexReader = indexReader;
         }
 
         private int ReadHeader(DataInput input)
         {
             int version = CodecUtil.CheckHeader(input, BlockTermsWriter.CODEC_NAME,
-                BlockTermsWriter.VERSION_START,
-                BlockTermsWriter.VERSION_CURRENT);
-
+                          BlockTermsWriter.VERSION_START,
+                          BlockTermsWriter.VERSION_CURRENT);
             if (version < BlockTermsWriter.VERSION_APPEND_ONLY)
             {
-                _dirOffset = input.ReadInt64();
+                dirOffset = input.ReadInt64();
             }
             return version;
         }
 
         private void SeekDir(IndexInput input, long dirOffset)
         {
-            if (_version >= BlockTermsWriter.VERSION_CHECKSUM)
+            if (version >= BlockTermsWriter.VERSION_CHECKSUM)
             {
                 input.Seek(input.Length - CodecUtil.FooterLength() - 8);
                 dirOffset = input.ReadInt64();
             }
-            else if (_version >= BlockTermsWriter.VERSION_APPEND_ONLY)
+            else if (version >= BlockTermsWriter.VERSION_APPEND_ONLY)
             {
                 input.Seek(input.Length - 8);
                 dirOffset = input.ReadInt64();
@@ -217,9 +196,9 @@ namespace Lucene.Net.Codecs.BlockTerms
             {
                 try
                 {
-                    if (_indexReader != null)
+                    if (indexReader != null)
                     {
-                        _indexReader.Dispose();
+                        indexReader.Dispose();
                     }
                 }
                 finally
@@ -227,26 +206,25 @@ namespace Lucene.Net.Codecs.BlockTerms
                     // null so if an app hangs on to us (ie, we are not
                     // GCable, despite being closed) we still free most
                     // ram
-                    _indexReader = null;
-                    if (_input != null)
+                    indexReader = null;
+                    if (input != null)
                     {
-                        _input.Dispose();
+                        input.Dispose();
                     }
                 }
             }
             finally
             {
-                if (_postingsReader != null)
+                if (postingsReader != null)
                 {
-                    _postingsReader.Dispose();
+                    postingsReader.Dispose();
                 }
             }
         }
 
         public override IEnumerator<string> GetEnumerator()
         {
-            //return Collections.UnmodifiableSet(_fields.Keys).GetEnumerator();
-            return _fields.Keys.GetEnumerator();
+            return Collections.UnmodifiableSet(fields.Keys).GetEnumerator();
         }
 
         public override Terms GetTerms(string field)
@@ -254,7 +232,7 @@ namespace Lucene.Net.Codecs.BlockTerms
             Debug.Assert(field != null);
 
             FieldReader result;
-            _fields.TryGetValue(field, out result);
+            fields.TryGetValue(field, out result);
             return result;
         }
 
@@ -262,7 +240,7 @@ namespace Lucene.Net.Codecs.BlockTerms
         {
             get
             {
-                return _fields.Count;
+                return fields.Count;
             }
         }
 
@@ -270,13 +248,13 @@ namespace Lucene.Net.Codecs.BlockTerms
         {
             private readonly BlockTermsReader outerInstance;
 
-            private readonly long _numTerms;
-            private readonly FieldInfo _fieldInfo;
-            private readonly long _termsStartPointer;
-            private readonly long _sumTotalTermFreq;
-            private readonly long _sumDocFreq;
-            private readonly int _docCount;
-            private readonly int _longsSize;
+            private readonly long numTerms;
+            private readonly FieldInfo fieldInfo;
+            private readonly long termsStartPointer;
+            private readonly long sumTotalTermFreq;
+            private readonly long sumDocFreq;
+            private readonly int docCount;
+            private readonly int longsSize;
 
             public FieldReader(BlockTermsReader outerInstance, FieldInfo fieldInfo, long numTerms, long termsStartPointer, long sumTotalTermFreq,
                 long sumDocFreq, int docCount, int longsSize)
@@ -285,13 +263,13 @@ namespace Lucene.Net.Codecs.BlockTerms
 
                 this.outerInstance = outerInstance;
 
-                _fieldInfo = fieldInfo;
-                _numTerms = numTerms;
-                _termsStartPointer = termsStartPointer;
-                _sumTotalTermFreq = sumTotalTermFreq;
-                _sumDocFreq = sumDocFreq;
-                _docCount = docCount;
-                _longsSize = longsSize;
+                this.fieldInfo = fieldInfo;
+                this.numTerms = numTerms;
+                this.termsStartPointer = termsStartPointer;
+                this.sumTotalTermFreq = sumTotalTermFreq;
+                this.sumDocFreq = sumDocFreq;
+                this.docCount = docCount;
+                this.longsSize = longsSize;
             }
 
             public override IComparer<BytesRef> Comparer
@@ -306,42 +284,42 @@ namespace Lucene.Net.Codecs.BlockTerms
 
             public override bool HasFreqs
             {
-                get { return _fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; }
+                get { return fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; }
             }
 
             public override bool HasOffsets
             {
-                get { return _fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; }
+                get { return fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0; }
             }
 
             public override bool HasPositions
             {
-                get { return _fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; }
+                get { return fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; }
             }
 
             public override bool HasPayloads
             {
-                get { return _fieldInfo.HasPayloads; }
+                get { return fieldInfo.HasPayloads; }
             }
 
             public override long Count
             {
-                get { return _numTerms; }
+                get { return numTerms; }
             }
 
             public override long SumTotalTermFreq
             {
-                get { return _sumTotalTermFreq; }
+                get { return sumTotalTermFreq; }
             }
 
             public override long SumDocFreq
             {
-                get { return _sumDocFreq; }
+                get { return sumDocFreq; }
             }
 
             public override int DocCount
             {
-                get { return _docCount; }
+                get { return docCount; }
             }
 
             // Iterates through terms in this field
@@ -349,70 +327,70 @@ namespace Lucene.Net.Codecs.BlockTerms
             {
                 private readonly FieldReader outerInstance;
 
-                private readonly IndexInput _input;
-                private readonly BlockTermState _state;
-                private readonly bool _doOrd;
-                private readonly FieldAndTerm _fieldTerm = new FieldAndTerm();
-                private readonly TermsIndexReaderBase.FieldIndexEnum _indexEnum;
-                private readonly BytesRef _term = new BytesRef();
+                private readonly IndexInput input;
+                private readonly BlockTermState state;
+                private readonly bool doOrd;
+                private readonly FieldAndTerm fieldTerm = new FieldAndTerm();
+                private readonly TermsIndexReaderBase.FieldIndexEnum indexEnum;
+                private readonly BytesRef term = new BytesRef();
 
                 /* This is true if indexEnum is "still" seek'd to the index term
                  for the current term. We set it to true on seeking, and then it
                  remains valid until next() is called enough times to load another
                  terms block: */
-                private bool _indexIsCurrent;
+                private bool indexIsCurrent;
 
                 /* True if we've already called .next() on the indexEnum, to "bracket"
                 the current block of terms: */
-                private bool _didIndexNext;
+                private bool didIndexNext;
 
                 /* Next index term, bracketing the current block of terms; this is
                 only valid if didIndexNext is true: */
-                private BytesRef _nextIndexTerm;
+                private BytesRef nextIndexTerm;
 
                 /* True after seekExact(TermState), do defer seeking.  If the app then
                 calls next() (which is not "typical"), then we'll do the real seek */
-                private bool _seekPending;
+                private bool seekPending;
 
                 /* How many blocks we've read since last seek.  Once this
                  is >= indexEnum.getDivisor() we set indexIsCurrent to false (since
                  the index can no long bracket seek-within-block). */
-                private int _blocksSinceSeek;
+                private int blocksSinceSeek;
 
-                private byte[] _termSuffixes;
-                private readonly ByteArrayDataInput _termSuffixesReader = new ByteArrayDataInput();
+                private byte[] termSuffixes;
+                private readonly ByteArrayDataInput termSuffixesReader = new ByteArrayDataInput();
 
                 /* Common prefix used for all terms in this block. */
-                private int _termBlockPrefix;
+                private int termBlockPrefix;
 
                 /* How many terms in current block */
-                private int _blockTermCount;
+                private int blockTermCount;
 
-                private byte[] _docFreqBytes;
-                private readonly ByteArrayDataInput _freqReader = new ByteArrayDataInput();
-                private int _metaDataUpto;
+                private byte[] docFreqBytes;
+                private readonly ByteArrayDataInput freqReader = new ByteArrayDataInput();
+                private int metaDataUpto;
 
-                private readonly long[] _longs;
-                private byte[] _bytes;
-                private ByteArrayDataInput _bytesReader;
+                private readonly long[] longs;
+                private byte[] bytes;
+                private ByteArrayDataInput bytesReader;
 
                 public SegmentTermsEnum(FieldReader outerInstance)
                 {
                     this.outerInstance = outerInstance;
 
-                    _input = (IndexInput)outerInstance.outerInstance._input.Clone();
-                    _input.Seek(this.outerInstance._termsStartPointer);
-                    _indexEnum = outerInstance.outerInstance._indexReader.GetFieldEnum(this.outerInstance._fieldInfo);
-                    _doOrd = outerInstance.outerInstance._indexReader.SupportsOrd;
-                    _fieldTerm.Field = this.outerInstance._fieldInfo.Name;
-                    _state = outerInstance.outerInstance._postingsReader.NewTermState();
-                    _state.TotalTermFreq = -1;
-                    _state.Ord = -1;
-
-                    _termSuffixes = new byte[128];
-                    _docFreqBytes = new byte[64];
+                    input = (IndexInput)outerInstance.outerInstance.input.Clone();
+                    input.Seek(outerInstance.termsStartPointer);
+                    indexEnum = outerInstance.outerInstance.indexReader.GetFieldEnum(outerInstance.fieldInfo);
+                    doOrd = outerInstance.outerInstance.indexReader.SupportsOrd;
+                    fieldTerm.Field = outerInstance.fieldInfo.Name;
+                    state = outerInstance.outerInstance.postingsReader.NewTermState();
+                    state.TotalTermFreq = -1;
+                    state.Ord = -1;
+
+                    termSuffixes = new byte[128];
+                    docFreqBytes = new byte[64];
                     //System.out.println("BTR.enum init this=" + this + " postingsReader=" + postingsReader);
-                    _longs = new long[this.outerInstance._longsSize];
+                    longs = new long[outerInstance.longsSize];
                 }
 
                 public override IComparer<BytesRef> Comparer
@@ -430,15 +408,15 @@ namespace Lucene.Net.Codecs.BlockTerms
                 /// </remarks>
                 public override SeekStatus SeekCeil(BytesRef target)
                 {
-                    if (_indexEnum == null)
+                    if (indexEnum == null)
                     {
                         throw new InvalidOperationException("terms index was not loaded");
                     }
 
                     //System.out.println("BTR.seek seg=" + segment + " target=" + fieldInfo.name + ":" + target.utf8ToString() + " " + target + " current=" + term().utf8ToString() + " " + term() + " indexIsCurrent=" + indexIsCurrent + " didIndexNext=" + didIndexNext + " seekPending=" + seekPending + " divisor=" + indexReader.getDivisor() + " this="  + this);
-                    if (_didIndexNext)
+                    if (didIndexNext)
                     {
-                        if (_nextIndexTerm == null)
+                        if (nextIndexTerm == null)
                         {
                             //System.out.println("  nextIndexTerm=null");
                         }
@@ -452,34 +430,35 @@ namespace Lucene.Net.Codecs.BlockTerms
 
                     // See if we can avoid seeking, because target term
                     // is after current term but before next index term:
-                    if (_indexIsCurrent)
+                    if (indexIsCurrent)
                     {
-                        int cmp = BytesRef.UTF8SortedAsUnicodeComparer.Compare(_term, target);
+
+                        int cmp = BytesRef.UTF8SortedAsUnicodeComparer.Compare(term, target);
 
                         if (cmp == 0)
                         {
                             // Already at the requested term
-                            return SeekStatus.FOUND;     
+                            return SeekStatus.FOUND;
                         }
                         else if (cmp < 0)
                         {
+
                             // Target term is after current term
-                            if (!_didIndexNext)
+                            if (!didIndexNext)
                             {
-                                if (_indexEnum.Next() == -1)
+                                if (indexEnum.Next() == -1)
                                 {
-                                    _nextIndexTerm = null;
+                                    nextIndexTerm = null;
                                 }
                                 else
                                 {
-                                    _nextIndexTerm = _indexEnum.Term;
+                                    nextIndexTerm = indexEnum.Term;
                                 }
                                 //System.out.println("  now do index next() nextIndexTerm=" + (nextIndexTerm == null ? "null" : nextIndexTerm.utf8ToString()));
-                                _didIndexNext = true;
+                                didIndexNext = true;
                             }
 
-                            if (_nextIndexTerm == null ||
-                                BytesRef.UTF8SortedAsUnicodeComparer.Compare(target, _nextIndexTerm) < 0)
+                            if (nextIndexTerm == null || BytesRef.UTF8SortedAsUnicodeComparer.Compare(target, nextIndexTerm) < 0)
                             {
                                 // Optimization: requested term is within the
                                 // same term block we are now in; skip seeking
@@ -496,36 +475,36 @@ namespace Lucene.Net.Codecs.BlockTerms
 
                         // Ask terms index to find biggest indexed term (=
                         // first term in a block) that's <= our text:
-                        _input.Seek(_indexEnum.Seek(target));
+                        input.Seek(indexEnum.Seek(target));
                         bool result = NextBlock();
 
                         // Block must exist since, at least, the indexed term
                         // is in the block:
                         Debug.Assert(result);
 
-                        _indexIsCurrent = true;
-                        _didIndexNext = false;
-                        _blocksSinceSeek = 0;
+                        indexIsCurrent = true;
+                        didIndexNext = false;
+                        blocksSinceSeek = 0;
 
-                        if (_doOrd)
+                        if (doOrd)
                         {
-                            _state.Ord = _indexEnum.Ord - 1;
+                            state.Ord = indexEnum.Ord - 1;
                         }
 
-                        _term.CopyBytes(_indexEnum.Term);
+                        term.CopyBytes(indexEnum.Term);
                         //System.out.println("  seek: term=" + term.utf8ToString());
                     }
                     else
                     {
                         //System.out.println("  skip seek");
-                        if (_state.TermBlockOrd == _blockTermCount && !NextBlock())
+                        if (state.TermBlockOrd == blockTermCount && !NextBlock())
                         {
-                            _indexIsCurrent = false;
+                            indexIsCurrent = false;
                             return SeekStatus.END;
                         }
                     }
 
-                    _seekPending = false;
+                    seekPending = false;
 
                     int common = 0;
 
@@ -540,13 +519,15 @@ namespace Lucene.Net.Codecs.BlockTerms
 
                     while (true)
                     {
+
                         // First, see if target term matches common prefix
                         // in this block:
-                        if (common < _termBlockPrefix)
+                        if (common < termBlockPrefix)
                         {
-                            int cmp = (_term.Bytes[common] & 0xFF) - (target.Bytes[target.Offset + common] & 0xFF);
+                            int cmp = (term.Bytes[common] & 0xFF) - (target.Bytes[target.Offset + common] & 0xFF);
                             if (cmp < 0)
                             {
+
                                 // TODO: maybe we should store common prefix
                                 // in block header?  (instead of relying on
                                 // last term of previous block)
@@ -556,45 +537,46 @@ namespace Lucene.Net.Codecs.BlockTerms
                                 // but it could be in next block.  We
                                 // must scan to end-of-block to set common
                                 // prefix for next block:
-                                if (_state.TermBlockOrd < _blockTermCount)
+                                if (state.TermBlockOrd < blockTermCount)
                                 {
-                                    while (_state.TermBlockOrd < _blockTermCount - 1)
+                                    while (state.TermBlockOrd < blockTermCount - 1)
                                     {
-                                        _state.TermBlockOrd++;
-                                        _state.Ord++;
-                                        _termSuffixesReader.SkipBytes(_termSuffixesReader.ReadVInt32());
+                                        state.TermBlockOrd++;
+                                        state.Ord++;
+                                        termSuffixesReader.SkipBytes(termSuffixesReader.ReadVInt32());
                                     }
-                                    int suffix = _termSuffixesReader.ReadVInt32();
-                                    _term.Length = _termBlockPrefix + suffix;
-                                    if (_term.Bytes.Length < _term.Length)
+                                    int suffix = termSuffixesReader.ReadVInt32();
+                                    term.Length = termBlockPrefix + suffix;
+                                    if (term.Bytes.Length < term.Length)
                                     {
-                                        _term.Grow(_term.Length);
+                                        term.Grow(term.Length);
                                     }
-                                    _termSuffixesReader.ReadBytes(_term.Bytes, _termBlockPrefix, suffix);
+                                    termSuffixesReader.ReadBytes(term.Bytes, termBlockPrefix, suffix);
                                 }
-                                _state.Ord++;
+                                state.Ord++;
 
                                 if (!NextBlock())
                                 {
-                                    _indexIsCurrent = false;
+                                    indexIsCurrent = false;
                                     return SeekStatus.END;
                                 }
                                 common = 0;
+
                             }
                             else if (cmp > 0)
                             {
                                 // Target's prefix is before the common prefix
                                 // of this block, so we position to start of
                                 // block and return NOT_FOUND:
-                                Debug.Assert(_state.TermBlockOrd == 0);
+                                Debug.Assert(state.TermBlockOrd == 0);
 
-                                int suffix = _termSuffixesReader.ReadVInt32();
-                                _term.Length = _termBlockPrefix + suffix;
-                                if (_term.Bytes.Length < _term.Length)
+                                int suffix = termSuffixesReader.ReadVInt32();
+                                term.Length = termBlockPrefix + suffix;
+                                if (term.Bytes.Length < term.Length)
                                 {
-                                    _term.Grow(_term.Length);
+                                    term.Grow(term.Length);
                                 }
-                                _termSuffixesReader.ReadBytes(_term.Bytes, _termBlockPrefix, suffix);
+                                termSuffixesReader.ReadBytes(term.Bytes, termBlockPrefix, suffix);
                                 return SeekStatus.NOT_FOUND;
                             }
                             else
@@ -608,21 +590,21 @@ namespace Lucene.Net.Codecs.BlockTerms
                         // Test every term in this block
                         while (true)
                         {
-                            _state.TermBlockOrd++;
-                            _state.Ord++;
+                            state.TermBlockOrd++;
+                            state.Ord++;
 
-                            int suffix = _termSuffixesReader.ReadVInt32();
+                            int suffix = termSuffixesReader.ReadVInt32();
 
                             // We know the prefix matches, so just compare the new suffix:
-                            int termLen = _termBlockPrefix + suffix;
-                            int bytePos = _termSuffixesReader.Position;
+                            int termLen = termBlockPrefix + suffix;
+                            int bytePos = termSuffixesReader.Position;
 
                             bool next = false;
                             int limit = target.Offset + (termLen < target.Length ? termLen : target.Length);
-                            int targetPos = target.Offset + _termBlockPrefix;
+                            int targetPos = target.Offset + termBlockPrefix;
                             while (targetPos < limit)
                             {
-                                int cmp = (_termSuffixes[bytePos++] & 0xFF) - (target.Bytes[targetPos++] & 0xFF);
+                                int cmp = (termSuffixes[bytePos++] & 0xFF) - (target.Bytes[targetPos++] & 0xFF);
                                 if (cmp < 0)
                                 {
                                     // Current term is still before the target;
@@ -634,12 +616,12 @@ namespace Lucene.Net.Codecs.BlockTerms
                                 {
                                     // Done!  Current term is after target. Stop
                                     // here, fill in real term, return NOT_FOUND.
-                                    _term.Length = _termBlockPrefix + suffix;
-                                    if (_term.Bytes.Length < _term.Length)
+                                    term.Length = termBlockPrefix + suffix;
+                                    if (term.Bytes.Length < term.Length)
                                     {
-                                        _term.Grow(_term.Length);
+                                        term.Grow(term.Length);
                                     }
-                                    _termSuffixesReader.ReadBytes(_term.Bytes, _termBlockPrefix, suffix);
+                                    termSuffixesReader.ReadBytes(term.Bytes, termBlockPrefix, suffix);
                                     //System.out.println("  NOT_FOUND");
                                     return SeekStatus.NOT_FOUND;
                                 }
@@ -647,12 +629,12 @@ namespace Lucene.Net.Codecs.BlockTerms
 
                             if (!next && target.Length <= termLen)
                             {
-                                _term.Length = _termBlockPrefix + suffix;
-                                if (_term.Bytes.Length < _term.Length)
+                                term.Length = termBlockPrefix + suffix;
+                                if (term.Bytes.Length < term.Length)
                                 {
-                                    _term.Grow(_term.Length);
+                                    term.Grow(term.Length);
                                 }
-                                _termSuffixesReader.ReadBytes(_term.Bytes, _termBlockPrefix, suffix);
+                                termSuffixesReader.ReadBytes(term.Bytes, termBlockPrefix, suffix);
 
                                 if (target.Length == termLen)
                                 {
@@ -668,20 +650,20 @@ namespace Lucene.Net.Codecs.BlockTerms
                                 }
                             }
 
-                            if (_state.TermBlockOrd == _blockTermCount)
+                            if (state.TermBlockOrd == blockTermCount)
                             {
                                 // Must pre-fill term for next block's common prefix
-                                _term.Length = _termBlockPrefix + suffix;
-                                if (_term.Bytes.Length < _term.Length)
+                                term.Length = termBlockPrefix + suffix;
+                                if (term.Bytes.Length < term.Length)
                                 {
-                                    _term.Grow(_term.Length);
+                                    term.Grow(term.Length);
                                 }
-                                _termSuffixesReader.ReadBytes(_term.Bytes, _termBlockPrefix, suffix);
+                                termSuffixesReader.ReadBytes(term.Bytes, termBlockPrefix, suffix);
                                 break;
                             }
                             else
                             {
-                                _termSuffixesReader.SkipBytes(suffix);
+                                termSuffixesReader.SkipBytes(suffix);
                             }
                         }
 
@@ -691,12 +673,12 @@ namespace Lucene.Net.Codecs.BlockTerms
                         // cross another index term (besides the first
                         // one) while we are scanning:
 
-                        Debug.Assert(_indexIsCurrent);
+                        Debug.Assert(indexIsCurrent);
 
                         if (!NextBlock())
                         {
                             //System.out.println("  END");
-                            _indexIsCurrent = false;
+                            indexIsCurrent = false;
                             return SeekStatus.END;
                         }
                         common = 0;
@@ -712,27 +694,27 @@ namespace Lucene.Net.Codecs.BlockTerms
                     // docFreq, etc.  But, if they then call next(),
                     // this method catches up all internal state so next()
                     // works properly:
-                    if (_seekPending)
+                    if (seekPending)
                     {
-                        Debug.Assert(!_indexIsCurrent);
-                        _input.Seek(_state.BlockFilePointer);
-                        int pendingSeekCount = _state.TermBlockOrd;
+                        Debug.Assert(!indexIsCurrent);
+                        input.Seek(state.BlockFilePointer);
+                        int pendingSeekCount = state.TermBlockOrd;
                         bool result = NextBlock();
 
-                        long savOrd = _state.Ord;
+                        long savOrd = state.Ord;
 
                         // Block must exist since seek(TermState) was called w/ a
                         // TermState previously returned by this enum when positioned
                         // on a real term:
                         Debug.Assert(result);
 
-                        while (_state.TermBlockOrd < pendingSeekCount)
+                        while (state.TermBlockOrd < pendingSeekCount)
                         {
                             BytesRef nextResult = _next();
                             Debug.Assert(nextResult != null);
                         }
-                        _seekPending = false;
-                        _state.Ord = savOrd;
+                        seekPending = false;
+                        state.Ord = savOrd;
                     }
                     return _next();
                 }
@@ -745,36 +727,36 @@ namespace Lucene.Net.Codecs.BlockTerms
                 /// <returns></returns>
                 private BytesRef _next()
                 {
-                    //System.out.println("BTR._next seg=" + segment + " this=" + this + " termCount=" + state.TermBlockOrd + " (vs " + blockTermCount + ")");
-                    if (_state.TermBlockOrd == _blockTermCount && !NextBlock())
+                    //System.out.println("BTR._next seg=" + segment + " this=" + this + " termCount=" + state.termBlockOrd + " (vs " + blockTermCount + ")");
+                    if (state.TermBlockOrd == blockTermCount && !NextBlock())
                     {
                         //System.out.println("  eof");
-                        _indexIsCurrent = false;
+                        indexIsCurrent = false;
                         return null;
                     }
 
                     // TODO: cutover to something better for these ints!  simple64?
-                    int suffix = _termSuffixesReader.ReadVInt32();
+                    int suffix = termSuffixesReader.ReadVInt32();
                     //System.out.println("  suffix=" + suffix);
 
-                    _term.Length = _termBlockPrefix + suffix;
-                    if (_term.Bytes.Length < _term.Length)
+                    term.Length = termBlockPrefix + suffix;
+                    if (term.Bytes.Length < term.Length)
                     {
-                        _term.Grow(_term.Length);
+                        term.Grow(term.Length);
                     }
-                    _termSuffixesReader.ReadBytes(_term.Bytes, _termBlockPrefix, suffix);
-                    _state.TermBlockOrd++;
+                    termSuffixesReader.ReadBytes(term.Bytes, termBlockPrefix, suffix);
+                    state.TermBlockOrd++;
 
                     // NOTE: meaningless in the non-ord case
-                    _state.Ord++;
+                    state.Ord++;
 
                     //System.out.println("  return term=" + fieldInfo.name + ":" + term.utf8ToString() + " " + term + " tbOrd=" + state.termBlockOrd);
-                    return _term;
+                    return term;
                 }
 
                 public override BytesRef Term
                 {
-                    get { return _term; }
+                    get { return term; }
                 }
 
                 public override int DocFreq
@@ -784,7 +766,7 @@ namespace Lucene.Net.Codecs.BlockTerms
                         //System.out.println("BTR.docFreq");
                         DecodeMetaData();
                         //System.out.println("  return " + state.docFreq);
-                        return _state.DocFreq;
+                        return state.DocFreq;
                     }
                 }
 
@@ -793,7 +775,7 @@ namespace Lucene.Net.Codecs.BlockTerms
                     get
                     {
                         DecodeMetaData();
-                        return _state.TotalTermFreq;
+                        return state.TotalTermFreq;
                     }
                 }
 
@@ -802,38 +784,38 @@ namespace Lucene.Net.Codecs.BlockTerms
                     //System.out.println("BTR.docs this=" + this);
                     DecodeMetaData();
                     //System.out.println("BTR.docs:  state.docFreq=" + state.docFreq);
-                    return outerInstance.outerInstance._postingsReader.Docs(outerInstance._fieldInfo, _state, liveDocs, reuse, flags);
+                    return outerInstance.outerInstance.postingsReader.Docs(outerInstance.fieldInfo, state, liveDocs, reuse, flags);
                 }
 
                 public override DocsAndPositionsEnum DocsAndPositions(IBits liveDocs, DocsAndPositionsEnum reuse,
                     DocsAndPositionsFlags flags)
                 {
-                    if (outerInstance._fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0)
+                    if (outerInstance.fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0)
                     {
                         // Positions were not indexed:
                         return null;
                     }
 
                     DecodeMetaData();
-                    return outerInstance.outerInstance._postingsReader.DocsAndPositions(outerInstance._fieldInfo, _state, liveDocs, reuse, flags);
+                    return outerInstance.outerInstance.postingsReader.DocsAndPositions(outerInstance.fieldInfo, state, liveDocs, reuse, flags);
                 }
 
                 public override void SeekExact(BytesRef target, TermState otherState)
                 {
                     //System.out.println("BTR.seekExact termState target=" + target.utf8ToString() + " " + target + " this=" + this);
                     Debug.Assert(otherState != null && otherState is BlockTermState);
-                    Debug.Assert(!_doOrd || ((BlockTermState)otherState).Ord < outerInstance._numTerms);
-                    _state.CopyFrom(otherState);
-                    _seekPending = true;
-                    _indexIsCurrent = false;
-                    _term.CopyBytes(target);
+                    Debug.Assert(!doOrd || ((BlockTermState)otherState).Ord < outerInstance.numTerms);
+                    state.CopyFrom(otherState);
+                    seekPending = true;
+                    indexIsCurrent = false;
+                    term.CopyBytes(target);
                 }
 
                 public override TermState GetTermState()
                 {
                     //System.out.println("BTR.termState this=" + this);
                     DecodeMetaData();
-                    TermState ts = (TermState)_state.Clone();
+                    TermState ts = (TermState)state.Clone();
                     //System.out.println("  return ts=" + ts);
                     return ts;
                 }
@@ -841,52 +823,51 @@ namespace Lucene.Net.Codecs.BlockTerms
                 public override void SeekExact(long ord)
                 {
                     //System.out.println("BTR.seek by ord ord=" + ord);
-                    if (_indexEnum == null)
+                    if (indexEnum == null)
                     {
                         throw new InvalidOperationException("terms index was not loaded");
                     }
 
-                    Debug.Assert(ord < outerInstance._numTerms);
+                    Debug.Assert(ord < outerInstance.numTerms);
 
                     // TODO: if ord is in same terms block and
                     // after current ord, we should avoid this seek just
                     // like we do in the seek(BytesRef) case
-                    _input.Seek(_indexEnum.Seek(ord));
+                    input.Seek(indexEnum.Seek(ord));
                     bool result = NextBlock();
 
                     // Block must exist since ord < numTerms:
                     Debug.Assert(result);
 
-                    _indexIsCurrent = true;
-                    _didIndexNext = false;
-                    _blocksSinceSeek = 0;
-                    _seekPending = false;
+                    indexIsCurrent = true;
+                    didIndexNext = false;
+                    blocksSinceSeek = 0;
+                    seekPending = false;
 
-                    _state.Ord = _indexEnum.Ord - 1;
-                    Debug.Assert(_state.Ord >= -1, "Ord=" + _state.Ord);
-                    _term.CopyBytes(_indexEnum.Term);
+                    state.Ord = indexEnum.Ord - 1;
+                    Debug.Assert(state.Ord >= -1, "Ord=" + state.Ord);
+                    term.CopyBytes(indexEnum.Term);
 
                     // Now, scan:
-                    int left = (int)(ord - _state.Ord);
+                    int left = (int)(ord - state.Ord);
                     while (left > 0)
                     {
                         BytesRef term = _next();
                         Debug.Assert(term != null);
                         left--;
-                        Debug.Assert(_indexIsCurrent);
+                        Debug.Assert(indexIsCurrent);
                     }
-
                 }
 
                 public override long Ord
                 {
                     get
                     {
-                        if (!_doOrd)
+                        if (!doOrd)
                         {
                             throw new NotSupportedException();
                         }
-                        return _state.Ord;
+                        return state.Ord;
                     }
                 }
 
@@ -908,55 +889,54 @@ namespace Lucene.Net.Codecs.BlockTerms
                     // bsearch w/in the block...
 
                     //System.out.println("BTR.nextBlock() fp=" + in.getFilePointer() + " this=" + this);
-                    _state.BlockFilePointer = _input.GetFilePointer();
-                    _blockTermCount = _input.ReadVInt32();
-
+                    state.BlockFilePointer = input.GetFilePointer();
+                    blockTermCount = input.ReadVInt32();
                     //System.out.println("  blockTermCount=" + blockTermCount);
-                    if (_blockTermCount == 0)
+                    if (blockTermCount == 0)
                     {
                         return false;
                     }
-                    _termBlockPrefix = _input.ReadVInt32();
+                    termBlockPrefix = input.ReadVInt32();
 
                     // term suffixes:
-                    int len = _input.ReadVInt32();
-                    if (_termSuffixes.Length < len)
+                    int len = input.ReadVInt32();
+                    if (termSuffixes.Length < len)
                     {
-                        _termSuffixes = new byte[ArrayUtil.Oversize(len, 1)];
+                        termSuffixes = new byte[ArrayUtil.Oversize(len, 1)];
                     }
                     //System.out.println("  termSuffixes len=" + len);
-                    _input.ReadBytes(_termSuffixes, 0, len);
-                    _termSuffixesReader.Reset(_termSuffixes, 0, len);
+                    input.ReadBytes(termSuffixes, 0, len);
+                    termSuffixesReader.Reset(termSuffixes, 0, len);
 
                     // docFreq, totalTermFreq
-                    len = _input.ReadVInt32();
-                    if (_docFreqBytes.Length < len)
+                    len = input.ReadVInt32();
+                    if (docFreqBytes.Length < len)
                     {
-                        _docFreqBytes = new byte[ArrayUtil.Oversize(len, 1)];
+                        docFreqBytes = new byte[ArrayUtil.Oversize(len, 1)];
                     }
                     //System.out.println("  freq bytes len=" + len);
-                    _input.ReadBytes(_docFreqBytes, 0, len);
-                    _freqReader.Reset(_docFreqBytes, 0, len);
+                    input.ReadBytes(docFreqBytes, 0, len);
+                    freqReader.Reset(docFreqBytes, 0, len);
 
                     // metadata
-                    len = _input.ReadVInt32();
-                    if (_bytes == null)
+                    len = input.ReadVInt32();
+                    if (bytes == null)
                     {
-                        _bytes = new byte[ArrayUtil.Oversize(len, 1)];
-                        _bytesReader = new ByteArrayDataInput();
+                        bytes = new byte[ArrayUtil.Oversize(len, 1)];
+                        bytesReader = new ByteArrayDataInput();
                     }
-                    else if (_bytes.Length < len)
+                    else if (bytes.Length < len)
                     {
-                        _bytes = new byte[ArrayUtil.Oversize(len, 1)];
+                        bytes = new byte[ArrayUtil.Oversize(len, 1)];
                     }
-                    _input.ReadBytes(_bytes, 0, len);
-                    _bytesReader.Reset(_bytes, 0, len);
+                    input.ReadBytes(bytes, 0, len);
+                    bytesReader.Reset(bytes, 0, len);
 
-                    _metaDataUpto = 0;
-                    _state.TermBlockOrd = 0;
+                    metaDataUpto = 0;
+                    state.TermBlockOrd = 0;
 
-                    _blocksSinceSeek++;
-                    _indexIsCurrent = _indexIsCurrent && (_blocksSinceSeek < outerInstance.outerInstance._indexReader.Divisor);
+                    blocksSinceSeek++;
+                    indexIsCurrent = indexIsCurrent && (blocksSinceSeek < outerInstance.outerInstance.indexReader.Divisor);
                     //System.out.println("  indexIsCurrent=" + indexIsCurrent);
 
                     return true;
@@ -964,8 +944,8 @@ namespace Lucene.Net.Codecs.BlockTerms
 
                 private void DecodeMetaData()
                 {
-                    //System.out.println("BTR.decodeMetadata mdUpto=" + metaDataUpto + " vs termCount=" + state.TermBlockOrd + " state=" + state);
-                    if (!_seekPending)
+                    //System.out.println("BTR.decodeMetadata mdUpto=" + metaDataUpto + " vs termCount=" + state.termBlockOrd + " state=" + state);
+                    if (!seekPending)
                     {
                         // TODO: cutover to random-access API
                         // here.... really stupid that we have to decode N
@@ -973,10 +953,10 @@ namespace Lucene.Net.Codecs.BlockTerms
                         // that we really need...
 
                         // lazily catch up on metadata decode:
-                        int limit = _state.TermBlockOrd;
-                        bool absolute = _metaDataUpto == 0;
+                        int limit = state.TermBlockOrd;
+                        bool absolute = metaDataUpto == 0;
                         // TODO: better API would be "jump straight to term=N"???
-                        while (_metaDataUpto < limit)
+                        while (metaDataUpto < limit)
                         {
                             //System.out.println("  decode mdUpto=" + metaDataUpto);
                             // TODO: we could make "tiers" of metadata, ie,
@@ -989,19 +969,20 @@ namespace Lucene.Net.Codecs.BlockTerms
                             // just skipN here:
 
                             // docFreq, totalTermFreq
-                            _state.DocFreq = _freqReader.ReadVInt32();
+                            state.DocFreq = freqReader.ReadVInt32();
                             //System.out.println("    dF=" + state.docFreq);
-                            if (outerInstance._fieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
+                            if (outerInstance.fieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
                             {
-                                _state.TotalTermFreq = _state.DocFreq + _freqReader.ReadVInt64();
+                                state.TotalTermFreq = state.DocFreq + freqReader.ReadVInt64();
+                                //System.out.println("    totTF=" + state.totalTermFreq);
                             }
                             // metadata
-                            for (int i = 0; i < _longs.Length; i++)
+                            for (int i = 0; i < longs.Length; i++)
                             {
-                                _longs[i] = _bytesReader.ReadVInt64();
+                                longs[i] = bytesReader.ReadVInt64();
                             }
-                            outerInstance.outerInstance._postingsReader.DecodeTerm(_longs, _bytesReader, outerInstance._fieldInfo, _state, absolute);
-                            _metaDataUpto++;
+                            outerInstance.outerInstance.postingsReader.DecodeTerm(longs, bytesReader, outerInstance.fieldInfo, state, absolute);
+                            metaDataUpto++;
                             absolute = false;
                         }
                     }
@@ -1015,20 +996,20 @@ namespace Lucene.Net.Codecs.BlockTerms
 
         public override long RamBytesUsed()
         {
-            long sizeInBytes = (_postingsReader != null) ? _postingsReader.RamBytesUsed() : 0;
-            sizeInBytes += (_indexReader != null) ? _indexReader.RamBytesUsed() : 0;
+            long sizeInBytes = (postingsReader != null) ? postingsReader.RamBytesUsed() : 0;
+            sizeInBytes += (indexReader != null) ? indexReader.RamBytesUsed() : 0;
             return sizeInBytes;
         }
 
         public override void CheckIntegrity()
         {
             // verify terms
-            if (_version >= BlockTermsWriter.VERSION_CHECKSUM)
+            if (version >= BlockTermsWriter.VERSION_CHECKSUM)
             {
-                CodecUtil.ChecksumEntireFile(_input);
+                CodecUtil.ChecksumEntireFile(input);
             }
             // verify postings
-            _postingsReader.CheckIntegrity();
+            postingsReader.CheckIntegrity();
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/1246d5c4/src/Lucene.Net.Codecs/BlockTerms/BlockTermsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsWriter.cs b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsWriter.cs
index 0f7b161..c16560f 100644
--- a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsWriter.cs
+++ b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsWriter.cs
@@ -37,24 +37,24 @@ namespace Lucene.Net.Codecs.BlockTerms
     /// </remarks>
     public class BlockTermsWriter : FieldsConsumer
     {
-        internal const string CODEC_NAME = "BLOCK_TERMS_DICT";
+        internal readonly static string CODEC_NAME = "BLOCK_TERMS_DICT";
 
         // Initial format
-        public const int VERSION_START = 0;
-        public const int VERSION_APPEND_ONLY = 1;
-        public const int VERSION_META_ARRAY = 2;
-        public const int VERSION_CHECKSUM = 3;
-        public const int VERSION_CURRENT = VERSION_CHECKSUM;
+        public readonly static int VERSION_START = 0;
+        public readonly static int VERSION_APPEND_ONLY = 1;
+        public readonly static int VERSION_META_ARRAY = 2;
+        public readonly static int VERSION_CHECKSUM = 3;
+        public readonly static int VERSION_CURRENT = VERSION_CHECKSUM;
 
         /// <summary>Extension of terms file</summary>
-        public const string TERMS_EXTENSION = "tib";
+        public readonly static string TERMS_EXTENSION = "tib";
 
         protected IndexOutput m_output;
         private readonly PostingsWriterBase postingsWriter;
         private readonly FieldInfos fieldInfos;
         private FieldInfo currentField;
         private readonly TermsIndexWriterBase termsIndexWriter;
-        
+
         private class FieldMetaData
         {
             public FieldInfo FieldInfo { get; private set; }
@@ -83,13 +83,14 @@ namespace Lucene.Net.Codecs.BlockTerms
             }
         }
 
-        private readonly List<FieldMetaData> _fields = new List<FieldMetaData>();
+        private readonly IList<FieldMetaData> fields = new List<FieldMetaData>();
+
+        // private final String segment;
 
         public BlockTermsWriter(TermsIndexWriterBase termsIndexWriter,
             SegmentWriteState state, PostingsWriterBase postingsWriter)
         {
-            string termsFileName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix,
-                TERMS_EXTENSION);
+            string termsFileName = IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, TERMS_EXTENSION);
             this.termsIndexWriter = termsIndexWriter;
             m_output = state.Directory.CreateOutput(termsFileName, state.Context);
             bool success = false;
@@ -137,8 +138,8 @@ namespace Lucene.Net.Codecs.BlockTerms
                 {
                     long dirStart = m_output.FilePointer;
 
-                    m_output.WriteVInt32(_fields.Count);
-                    foreach (FieldMetaData field in _fields)
+                    m_output.WriteVInt32(fields.Count);
+                    foreach (FieldMetaData field in fields)
                     {
                         m_output.WriteVInt32(field.FieldInfo.Number);
                         m_output.WriteVInt64(field.NumTerms);
@@ -153,7 +154,6 @@ namespace Lucene.Net.Codecs.BlockTerms
                         {
                             m_output.WriteVInt32(field.Int64sSize);
                         }
-
                     }
                     WriteTrailer(dirStart);
                     CodecUtil.WriteFooter(m_output);
@@ -186,19 +186,19 @@ namespace Lucene.Net.Codecs.BlockTerms
         {
             private readonly BlockTermsWriter outerInstance;
 
-            private readonly FieldInfo _fieldInfo;
-            private readonly PostingsWriterBase _postingsWriter;
-            private readonly long _termsStartPointer;
-            private long _numTerms;
-            private readonly TermsIndexWriterBase.FieldWriter _fieldIndexWriter;
-            private long _sumTotalTermFreq;
-            private long _sumDocFreq;
-            private int _docCount;
-            private readonly int _longsSize;
+            private readonly FieldInfo fieldInfo;
+            private readonly PostingsWriterBase postingsWriter;
+            private readonly long termsStartPointer;
+            private long numTerms;
+            private readonly TermsIndexWriterBase.FieldWriter fieldIndexWriter;
+            long sumTotalTermFreq;
+            long sumDocFreq;
+            int docCount;
+            int longsSize;
 
-            private TermEntry[] _pendingTerms;
+            private TermEntry[] pendingTerms;
 
-            private int _pendingCount;
+            private int pendingCount;
 
             internal TermsWriter(
                 BlockTermsWriter outerInstance,
@@ -208,97 +208,96 @@ namespace Lucene.Net.Codecs.BlockTerms
             {
                 this.outerInstance = outerInstance;
 
-                this._fieldInfo = fieldInfo;
-                this._fieldIndexWriter = fieldIndexWriter;
-                _pendingTerms = new TermEntry[32];
-                for (int i = 0; i < _pendingTerms.Length; i++)
+                this.fieldInfo = fieldInfo;
+                this.fieldIndexWriter = fieldIndexWriter;
+                pendingTerms = new TermEntry[32];
+                for (int i = 0; i < pendingTerms.Length; i++)
                 {
-                    _pendingTerms[i] = new TermEntry();
+                    pendingTerms[i] = new TermEntry();
                 }
-                _termsStartPointer = this.outerInstance.m_output.FilePointer;
-                this._postingsWriter = postingsWriter;
-                this._longsSize = postingsWriter.SetField(fieldInfo);
+                termsStartPointer = outerInstance.m_output.FilePointer;
+                this.postingsWriter = postingsWriter;
+                this.longsSize = postingsWriter.SetField(fieldInfo);
             }
 
             public override IComparer<BytesRef> Comparer
             {
                 get { return BytesRef.UTF8SortedAsUnicodeComparer; }
-            }   
-        
+            }
+
             public override PostingsConsumer StartTerm(BytesRef text)
             {
                 //System.out.println("BTW: startTerm term=" + fieldInfo.name + ":" + text.utf8ToString() + " " + text + " seg=" + segment);
-                _postingsWriter.StartTerm();
-                return _postingsWriter;
+                postingsWriter.StartTerm();
+                return postingsWriter;
             }
 
-            private readonly BytesRef _lastPrevTerm = new BytesRef();
+            private readonly BytesRef lastPrevTerm = new BytesRef();
 
             public override void FinishTerm(BytesRef text, TermStats stats)
             {
                 Debug.Assert(stats.DocFreq > 0);
                 //System.out.println("BTW: finishTerm term=" + fieldInfo.name + ":" + text.utf8ToString() + " " + text + " seg=" + segment + " df=" + stats.docFreq);
 
-                bool isIndexTerm = _fieldIndexWriter.CheckIndexTerm(text, stats);
+                bool isIndexTerm = fieldIndexWriter.CheckIndexTerm(text, stats);
 
                 if (isIndexTerm)
                 {
-                    if (_pendingCount > 0)
+                    if (pendingCount > 0)
                     {
                         // Instead of writing each term, live, we gather terms
                         // in RAM in a pending buffer, and then write the
                         // entire block in between index terms:
                         FlushBlock();
                     }
-                    _fieldIndexWriter.Add(text, stats, outerInstance.m_output.FilePointer);
+                    fieldIndexWriter.Add(text, stats, outerInstance.m_output.FilePointer);
                     //System.out.println("  index term!");
                 }
 
-                if (_pendingTerms.Length == _pendingCount)
+                if (pendingTerms.Length == pendingCount)
                 {
-                    TermEntry[] newArray = new TermEntry[ArrayUtil.Oversize(_pendingCount + 1, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
-                    Array.Copy(_pendingTerms, 0, newArray, 0, _pendingCount);
-                    for (var i = _pendingCount; i < newArray.Length; i++)
+                    TermEntry[] newArray = new TermEntry[ArrayUtil.Oversize(pendingCount + 1, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
+                    System.Array.Copy(pendingTerms, 0, newArray, 0, pendingCount);
+                    for (int i = pendingCount; i < newArray.Length; i++)
                     {
                         newArray[i] = new TermEntry();
                     }
-                    _pendingTerms = newArray;
+                    pendingTerms = newArray;
                 }
-                TermEntry te = _pendingTerms[_pendingCount];
+                TermEntry te = pendingTerms[pendingCount];
                 te.Term.CopyBytes(text);
-                te.State = _postingsWriter.NewTermState();
+                te.State = postingsWriter.NewTermState();
                 te.State.DocFreq = stats.DocFreq;
                 te.State.TotalTermFreq = stats.TotalTermFreq;
-                _postingsWriter.FinishTerm(te.State);
+                postingsWriter.FinishTerm(te.State);
 
-                _pendingCount++;
-                _numTerms++;
+                pendingCount++;
+                numTerms++;
             }
 
             // Finishes all terms in this field
             public override void Finish(long sumTotalTermFreq, long sumDocFreq, int docCount)
             {
-                if (_pendingCount > 0)
+                if (pendingCount > 0)
                 {
                     FlushBlock();
                 }
                 // EOF marker:
                 outerInstance.m_output.WriteVInt32(0);
 
-                _sumTotalTermFreq = sumTotalTermFreq;
-                _sumDocFreq = sumDocFreq;
-                _docCount = docCount;
-                _fieldIndexWriter.Finish(outerInstance.m_output.FilePointer);
-                if (_numTerms > 0)
+                this.sumTotalTermFreq = sumTotalTermFreq;
+                this.sumDocFreq = sumDocFreq;
+                this.docCount = docCount;
+                fieldIndexWriter.Finish(outerInstance.m_output.FilePointer);
+                if (numTerms > 0)
                 {
-                    outerInstance._fields.Add(new FieldMetaData(
-                        _fieldInfo,
-                        _numTerms,
-                        _termsStartPointer,
-                        sumTotalTermFreq,
-                        sumDocFreq,
-                        docCount,
-                        _longsSize));
+                    outerInstance.fields.Add(new FieldMetaData(fieldInfo,
+                                                 numTerms,
+                                                 termsStartPointer,
+                                                 sumTotalTermFreq,
+                                                 sumDocFreq,
+                                                 docCount,
+                                                 longsSize));
                 }
             }
 
@@ -306,7 +305,6 @@ namespace Lucene.Net.Codecs.BlockTerms
             {
                 Debug.Assert(term1.Offset == 0);
                 Debug.Assert(term2.Offset == 0);
-
                 int pos1 = 0;
                 int pos1End = pos1 + Math.Min(term1.Length, term2.Length);
                 int pos2 = 0;
@@ -319,12 +317,11 @@ namespace Lucene.Net.Codecs.BlockTerms
                     pos1++;
                     pos2++;
                 }
-
                 return pos1;
             }
 
-            private readonly RAMOutputStream _bytesWriter = new RAMOutputStream();
-            private readonly RAMOutputStream _bufferWriter = new RAMOutputStream();
+            private readonly RAMOutputStream bytesWriter = new RAMOutputStream();
+            private readonly RAMOutputStream bufferWriter = new RAMOutputStream();
 
             private void FlushBlock()
             {
@@ -333,71 +330,68 @@ namespace Lucene.Net.Codecs.BlockTerms
                 // First pass: compute common prefix for all terms
                 // in the block, against term before first term in
                 // this block:
-
-                int commonPrefix = SharedPrefix(_lastPrevTerm, _pendingTerms[0].Term);
-                for (int termCount = 1; termCount < _pendingCount; termCount++)
+                int commonPrefix = SharedPrefix(lastPrevTerm, pendingTerms[0].Term);
+                for (int termCount = 1; termCount < pendingCount; termCount++)
                 {
                     commonPrefix = Math.Min(commonPrefix,
-                        SharedPrefix(_lastPrevTerm,
-                            _pendingTerms[termCount].Term));
+                                            SharedPrefix(lastPrevTerm,
+                                                         pendingTerms[termCount].Term));
                 }
 
-                outerInstance.m_output.WriteVInt32(_pendingCount);
+                outerInstance.m_output.WriteVInt32(pendingCount);
                 outerInstance.m_output.WriteVInt32(commonPrefix);
 
                 // 2nd pass: write suffixes, as separate byte[] blob
-                for (int termCount = 0; termCount < _pendingCount; termCount++)
+                for (int termCount = 0; termCount < pendingCount; termCount++)
                 {
-                    int suffix = _pendingTerms[termCount].Term.Length - commonPrefix;
+                    int suffix = pendingTerms[termCount].Term.Length - commonPrefix;
                     // TODO: cutover to better intblock codec, instead
                     // of interleaving here:
-                    _bytesWriter.WriteVInt32(suffix);
-                    _bytesWriter.WriteBytes(_pendingTerms[termCount].Term.Bytes, commonPrefix, suffix);
+                    bytesWriter.WriteVInt32(suffix);
+                    bytesWriter.WriteBytes(pendingTerms[termCount].Term.Bytes, commonPrefix, suffix);
                 }
-                outerInstance.m_output.WriteVInt32((int)_bytesWriter.FilePointer);
-                _bytesWriter.WriteTo(outerInstance.m_output);
-                _bytesWriter.Reset();
+                outerInstance.m_output.WriteVInt32((int)bytesWriter.FilePointer);
+                bytesWriter.WriteTo(outerInstance.m_output);
+                bytesWriter.Reset();
 
                 // 3rd pass: write the freqs as byte[] blob
                 // TODO: cutover to better intblock codec.  simple64?
                 // write prefix, suffix first:
-                for (int termCount = 0; termCount < _pendingCount; termCount++)
+                for (int termCount = 0; termCount < pendingCount; termCount++)
                 {
-                    BlockTermState state = _pendingTerms[termCount].State;
-
+                    BlockTermState state = pendingTerms[termCount].State;
                     Debug.Assert(state != null);
-
-                    _bytesWriter.WriteVInt32(state.DocFreq);
-                    if (_fieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
+                    bytesWriter.WriteVInt32(state.DocFreq);
+                    if (fieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
                     {
-                        _bytesWriter.WriteVInt64(state.TotalTermFreq - state.DocFreq);
+                        bytesWriter.WriteVInt64(state.TotalTermFreq - state.DocFreq);
                     }
                 }
-                outerInstance.m_output.WriteVInt32((int)_bytesWriter.FilePointer);
-                _bytesWriter.WriteTo(outerInstance.m_output);
-                _bytesWriter.Reset();
+                outerInstance.m_output.WriteVInt32((int)bytesWriter.FilePointer);
+                bytesWriter.WriteTo(outerInstance.m_output);
+                bytesWriter.Reset();
 
                 // 4th pass: write the metadata 
-                long[] longs = new long[_longsSize];
+                long[] longs = new long[longsSize];
                 bool absolute = true;
-                for (int termCount = 0; termCount < _pendingCount; termCount++)
+                for (int termCount = 0; termCount < pendingCount; termCount++)
                 {
-                    BlockTermState state = _pendingTerms[termCount].State;
-                    _postingsWriter.EncodeTerm(longs, _bufferWriter, _fieldInfo, state, absolute);
-                    for (int i = 0; i < _longsSize; i++)
+                    BlockTermState state = pendingTerms[termCount].State;
+                    postingsWriter.EncodeTerm(longs, bufferWriter, fieldInfo, state, absolute);
+                    for (int i = 0; i < longsSize; i++)
                     {
-                        _bytesWriter.WriteVInt64(longs[i]);
+                        bytesWriter.WriteVInt64(longs[i]);
                     }
-                    _bufferWriter.WriteTo(_bytesWriter);
-                    _bufferWriter.Reset();
+                    bufferWriter.WriteTo(bytesWriter);
+                    bufferWriter.Reset();
                     absolute = false;
                 }
-                outerInstance.m_output.WriteVInt32((int)_bytesWriter.FilePointer);
-                _bytesWriter.WriteTo(outerInstance.m_output);
-                _bytesWriter.Reset();
+                outerInstance.m_output.WriteVInt32((int)bytesWriter.FilePointer);
+                bytesWriter.WriteTo(outerInstance.m_output);
+                bytesWriter.Reset();
 
-                _lastPrevTerm.CopyBytes(_pendingTerms[_pendingCount - 1].Term);
-                _pendingCount = 0;
+                lastPrevTerm.CopyBytes(pendingTerms[pendingCount - 1].Term);
+                pendingCount = 0;
             }
         }
     }


Mime
View raw message