lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnas...@apache.org
Subject [5/7] Cleanup of codes, mostly SimpleText in this commit
Date Sun, 21 Sep 2014 16:53:31 GMT
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosReader.cs
index ae01b58..1dd0ed2 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosReader.cs
@@ -1,157 +1,190 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.lucene.codecs.FieldInfosReader;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfo.DocValuesType;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.StringHelper;
-
-import static org.apache.lucene.codecs.simpletext.SimpleTextFieldInfosWriter.*;
-
-/**
- * reads plaintext field infos files
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextFieldInfosReader extends FieldInfosReader {
-
-  @Override
-  public FieldInfos read(Directory directory, String segmentName, String segmentSuffix, IOContext iocontext)  {
-    final String fileName = IndexFileNames.segmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
-    ChecksumIndexInput input = directory.openChecksumInput(fileName, iocontext);
-    BytesRef scratch = new BytesRef();
-    
-    bool success = false;
-    try {
-      
-      SimpleTextUtil.readLine(input, scratch);
-      Debug.Assert( StringHelper.startsWith(scratch, NUMFIELDS);
-      final int size = Integer.parseInt(readString(NUMFIELDS.length, scratch));
-      FieldInfo infos[] = new FieldInfo[size];
-
-      for (int i = 0; i < size; i++) {
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, NAME);
-        String name = readString(NAME.length, scratch);
-        
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, NUMBER);
-        int fieldNumber = Integer.parseInt(readString(NUMBER.length, scratch));
-
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, ISINDEXED);
-        bool isIndexed = bool.parsebool(readString(ISINDEXED.length, scratch));
-        
-        final IndexOptions indexOptions;
-        if (isIndexed) {
-          SimpleTextUtil.readLine(input, scratch);
-          Debug.Assert( StringHelper.startsWith(scratch, INDEXOPTIONS);
-          indexOptions = IndexOptions.valueOf(readString(INDEXOPTIONS.length, scratch));          
-        } else {
-          indexOptions = null;
-        }
-        
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, STORETV);
-        bool storeTermVector = bool.parsebool(readString(STORETV.length, scratch));
-        
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, PAYLOADS);
-        bool storePayloads = bool.parsebool(readString(PAYLOADS.length, scratch));
-        
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, NORMS);
-        bool omitNorms = !bool.parsebool(readString(NORMS.length, scratch));
-        
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, NORMS_TYPE);
-        String nrmType = readString(NORMS_TYPE.length, scratch);
-        final DocValuesType normsType = docValuesType(nrmType);
-        
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, DOCVALUES);
-        String dvType = readString(DOCVALUES.length, scratch);
-        final DocValuesType docValuesType = docValuesType(dvType);
-        
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, DOCVALUES_GEN);
-        final long dvGen = Long.parseLong(readString(DOCVALUES_GEN.length, scratch));
-        
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, NUM_ATTS);
-        int numAtts = Integer.parseInt(readString(NUM_ATTS.length, scratch));
-        Map<String,String> atts = new HashMap<>();
-
-        for (int j = 0; j < numAtts; j++) {
-          SimpleTextUtil.readLine(input, scratch);
-          Debug.Assert( StringHelper.startsWith(scratch, ATT_KEY);
-          String key = readString(ATT_KEY.length, scratch);
-        
-          SimpleTextUtil.readLine(input, scratch);
-          Debug.Assert( StringHelper.startsWith(scratch, ATT_VALUE);
-          String value = readString(ATT_VALUE.length, scratch);
-          atts.put(key, value);
-        }
-
-        infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, 
-          omitNorms, storePayloads, indexOptions, docValuesType, normsType, Collections.unmodifiableMap(atts));
-        infos[i].setDocValuesGen(dvGen);
-      }
-
-      SimpleTextUtil.checkFooter(input);
-      
-      FieldInfos fieldInfos = new FieldInfos(infos);
-      success = true;
-      return fieldInfos;
-    } finally {
-      if (success) {
-        input.close();
-      } else {
-        IOUtils.closeWhileHandlingException(input);
-      }
-    }
-  }
-
-  public DocValuesType docValuesType(String dvType) {
-    if ("false".equals(dvType)) {
-      return null;
-    } else {
-      return DocValuesType.valueOf(dvType);
-    }
-  }
-  
-  private String readString(int offset, BytesRef scratch) {
-    return new String(scratch.bytes, scratch.offset+offset, scratch.length-offset, StandardCharsets.UTF_8);
-  }
-}
+using System;
+using System.Diagnostics;
+using System.Collections.Generic;
+
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+	/*
+	 * Licensed to the Apache Software Foundation (ASF) under one or more
+	 * contributor license agreements.  See the NOTICE file distributed with
+	 * this work for additional information regarding copyright ownership.
+	 * The ASF licenses this file to You under the Apache License, Version 2.0
+	 * (the "License"); you may not use this file except in compliance with
+	 * the License.  You may obtain a copy of the License at
+	 *
+	 *     http://www.apache.org/licenses/LICENSE-2.0
+	 *
+	 * Unless required by applicable law or agreed to in writing, software
+	 * distributed under the License is distributed on an "AS IS" BASIS,
+	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	 * See the License for the specific language governing permissions and
+	 * limitations under the License.
+	 */
+
+
+	using FieldInfo = index.FieldInfo;
+	using DocValuesType = index.FieldInfo.DocValuesType;
+	using FieldInfos = index.FieldInfos;
+	using IndexFileNames = index.IndexFileNames;
+	using IndexOptions = index.FieldInfo.IndexOptions;
+	using ChecksumIndexInput = store.ChecksumIndexInput;
+	using Directory = store.Directory;
+	using IOContext = store.IOContext;
+	using BytesRef = util.BytesRef;
+	using IOUtils = util.IOUtils;
+	using StringHelper = util.StringHelper;
+
+//JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+	import static Lucene.Net.Codecs.SimpleText.SimpleTextFieldInfosWriter.*;
+
+	/// <summary>
+	/// reads plaintext field infos files
+	/// <para>
+	/// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+	/// @lucene.experimental
+	/// </para>
+	/// </summary>
+	public class SimpleTextFieldInfosReader : FieldInfosReader
+	{
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public index.FieldInfos read(store.Directory directory, String segmentName, String segmentSuffix, store.IOContext iocontext) throws java.io.IOException
+	  public override FieldInfos read(Directory directory, string segmentName, string segmentSuffix, IOContext iocontext)
+	  {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final String fileName = index.IndexFileNames.segmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
+		string fileName = IndexFileNames.segmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
+		ChecksumIndexInput input = directory.openChecksumInput(fileName, iocontext);
+		BytesRef scratch = new BytesRef();
+
+		bool success = false;
+		try
+		{
+
+		  SimpleTextUtil.ReadLine(input, scratch);
+		  Debug.Assert(StringHelper.StartsWith(scratch, NUMFIELDS));
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final int size = Integer.parseInt(readString(NUMFIELDS.length, scratch));
+		  int size = Convert.ToInt32(readString(NUMFIELDS.length, scratch));
+		  FieldInfo[] infos = new FieldInfo[size];
+
+		  for (int i = 0; i < size; i++)
+		  {
+			SimpleTextUtil.ReadLine(input, scratch);
+			Debug.Assert(StringHelper.StartsWith(scratch, NAME));
+			string name = readString(NAME.length, scratch);
+
+			SimpleTextUtil.ReadLine(input, scratch);
+			Debug.Assert(StringHelper.StartsWith(scratch, NUMBER));
+			int fieldNumber = Convert.ToInt32(readString(NUMBER.length, scratch));
+
+			SimpleTextUtil.ReadLine(input, scratch);
+			Debug.Assert(StringHelper.StartsWith(scratch, ISINDEXED));
+			bool isIndexed = Convert.ToBoolean(readString(ISINDEXED.length, scratch));
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final index.FieldInfo.IndexOptions indexOptions;
+			FieldInfo.IndexOptions indexOptions;
+			if (isIndexed)
+			{
+			  SimpleTextUtil.ReadLine(input, scratch);
+			  Debug.Assert(StringHelper.StartsWith(scratch, INDEXOPTIONS));
+			  indexOptions = FieldInfo.IndexOptions.valueOf(readString(INDEXOPTIONS.length, scratch));
+			}
+			else
+			{
+			  indexOptions = null;
+			}
+
+			SimpleTextUtil.ReadLine(input, scratch);
+			Debug.Assert(StringHelper.StartsWith(scratch, STORETV));
+			bool storeTermVector = Convert.ToBoolean(readString(STORETV.length, scratch));
+
+			SimpleTextUtil.ReadLine(input, scratch);
+			Debug.Assert(StringHelper.StartsWith(scratch, PAYLOADS));
+			bool storePayloads = Convert.ToBoolean(readString(PAYLOADS.length, scratch));
+
+			SimpleTextUtil.ReadLine(input, scratch);
+			Debug.Assert(StringHelper.StartsWith(scratch, NORMS));
+			bool omitNorms = !Convert.ToBoolean(readString(NORMS.length, scratch));
+
+			SimpleTextUtil.ReadLine(input, scratch);
+			Debug.Assert(StringHelper.StartsWith(scratch, NORMS_TYPE));
+			string nrmType = readString(NORMS_TYPE.length, scratch);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final index.FieldInfo.DocValuesType normsType = docValuesType(nrmType);
+			FieldInfo.DocValuesType normsType = docValuesType(nrmType);
+
+			SimpleTextUtil.ReadLine(input, scratch);
+			Debug.Assert(StringHelper.StartsWith(scratch, DOCVALUES));
+			string dvType = readString(DOCVALUES.length, scratch);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final index.FieldInfo.DocValuesType docValuesType = docValuesType(dvType);
+			FieldInfo.DocValuesType docValuesType = docValuesType(dvType);
+
+			SimpleTextUtil.ReadLine(input, scratch);
+			Debug.Assert(StringHelper.StartsWith(scratch, DOCVALUES_GEN));
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final long dvGen = Long.parseLong(readString(DOCVALUES_GEN.length, scratch));
+			long dvGen = Convert.ToInt64(readString(DOCVALUES_GEN.length, scratch));
+
+			SimpleTextUtil.ReadLine(input, scratch);
+			Debug.Assert(StringHelper.StartsWith(scratch, NUM_ATTS));
+			int numAtts = Convert.ToInt32(readString(NUM_ATTS.length, scratch));
+			IDictionary<string, string> atts = new Dictionary<string, string>();
+
+			for (int j = 0; j < numAtts; j++)
+			{
+			  SimpleTextUtil.ReadLine(input, scratch);
+			  Debug.Assert(StringHelper.StartsWith(scratch, ATT_KEY));
+			  string key = readString(ATT_KEY.length, scratch);
+
+			  SimpleTextUtil.ReadLine(input, scratch);
+			  Debug.Assert(StringHelper.StartsWith(scratch, ATT_VALUE));
+			  string value = readString(ATT_VALUE.length, scratch);
+			  atts[key] = value;
+			}
+
+			infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, omitNorms, storePayloads, indexOptions, docValuesType, normsType, Collections.unmodifiableMap(atts));
+			infos[i].DocValuesGen = dvGen;
+		  }
+
+		  SimpleTextUtil.CheckFooter(input);
+
+		  FieldInfos fieldInfos = new FieldInfos(infos);
+		  success = true;
+		  return fieldInfos;
+		}
+		finally
+		{
+		  if (success)
+		  {
+			input.close();
+		  }
+		  else
+		  {
+			IOUtils.closeWhileHandlingException(input);
+		  }
+		}
+	  }
+
+	  public virtual FieldInfo.DocValuesType docValuesType(string dvType)
+	  {
+		if ("false".Equals(dvType))
+		{
+		  return null;
+		}
+		else
+		{
+		  return FieldInfo.DocValuesType.valueOf(dvType);
+		}
+	  }
+
+	  private string readString(int offset, BytesRef scratch)
+	  {
+		return new string(scratch.bytes, scratch.offset + offset, scratch.length - offset, StandardCharsets.UTF_8);
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosWriter.cs
index b3bdbed..d90d428 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosWriter.cs
@@ -1,149 +1,171 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.io.IOException;
-import java.util.Map;
-
-import org.apache.lucene.codecs.FieldInfosWriter;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfo.DocValuesType;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
-
-/**
- * writes plaintext field infos files
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextFieldInfosWriter extends FieldInfosWriter {
-  
-  /** Extension of field infos */
-  static final String FIELD_INFOS_EXTENSION = "inf";
-  
-  static final BytesRef NUMFIELDS       =  new BytesRef("number of fields ");
-  static final BytesRef NAME            =  new BytesRef("  name ");
-  static final BytesRef NUMBER          =  new BytesRef("  number ");
-  static final BytesRef ISINDEXED       =  new BytesRef("  indexed ");
-  static final BytesRef STORETV         =  new BytesRef("  term vectors ");
-  static final BytesRef STORETVPOS      =  new BytesRef("  term vector positions ");
-  static final BytesRef STORETVOFF      =  new BytesRef("  term vector offsets ");
-  static final BytesRef PAYLOADS        =  new BytesRef("  payloads ");
-  static final BytesRef NORMS           =  new BytesRef("  norms ");
-  static final BytesRef NORMS_TYPE      =  new BytesRef("  norms type ");
-  static final BytesRef DOCVALUES       =  new BytesRef("  doc values ");
-  static final BytesRef DOCVALUES_GEN   =  new BytesRef("  doc values gen ");
-  static final BytesRef INDEXOPTIONS    =  new BytesRef("  index options ");
-  static final BytesRef NUM_ATTS        =  new BytesRef("  attributes ");
-  final static BytesRef ATT_KEY         =  new BytesRef("    key ");
-  final static BytesRef ATT_VALUE       =  new BytesRef("    value ");
-  
-  @Override
-  public void write(Directory directory, String segmentName, String segmentSuffix, FieldInfos infos, IOContext context)  {
-    final String fileName = IndexFileNames.segmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
-    IndexOutput out = directory.createOutput(fileName, context);
-    BytesRef scratch = new BytesRef();
-    bool success = false;
-    try {
-      SimpleTextUtil.write(out, NUMFIELDS);
-      SimpleTextUtil.write(out, Integer.toString(infos.size()), scratch);
-      SimpleTextUtil.writeNewline(out);
-      
-      for (FieldInfo fi : infos) {
-        SimpleTextUtil.write(out, NAME);
-        SimpleTextUtil.write(out, fi.name, scratch);
-        SimpleTextUtil.writeNewline(out);
-        
-        SimpleTextUtil.write(out, NUMBER);
-        SimpleTextUtil.write(out, Integer.toString(fi.number), scratch);
-        SimpleTextUtil.writeNewline(out);
-        
-        SimpleTextUtil.write(out, ISINDEXED);
-        SimpleTextUtil.write(out, bool.toString(fi.isIndexed()), scratch);
-        SimpleTextUtil.writeNewline(out);
-        
-        if (fi.isIndexed()) {
-          Debug.Assert( fi.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads();
-          SimpleTextUtil.write(out, INDEXOPTIONS);
-          SimpleTextUtil.write(out, fi.getIndexOptions().toString(), scratch);
-          SimpleTextUtil.writeNewline(out);
-        }
-        
-        SimpleTextUtil.write(out, STORETV);
-        SimpleTextUtil.write(out, bool.toString(fi.hasVectors()), scratch);
-        SimpleTextUtil.writeNewline(out);
-        
-        SimpleTextUtil.write(out, PAYLOADS);
-        SimpleTextUtil.write(out, bool.toString(fi.hasPayloads()), scratch);
-        SimpleTextUtil.writeNewline(out);
-               
-        SimpleTextUtil.write(out, NORMS);
-        SimpleTextUtil.write(out, bool.toString(!fi.omitsNorms()), scratch);
-        SimpleTextUtil.writeNewline(out);
-        
-        SimpleTextUtil.write(out, NORMS_TYPE);
-        SimpleTextUtil.write(out, getDocValuesType(fi.getNormType()), scratch);
-        SimpleTextUtil.writeNewline(out);
-        
-        SimpleTextUtil.write(out, DOCVALUES);
-        SimpleTextUtil.write(out, getDocValuesType(fi.getDocValuesType()), scratch);
-        SimpleTextUtil.writeNewline(out);
-        
-        SimpleTextUtil.write(out, DOCVALUES_GEN);
-        SimpleTextUtil.write(out, Long.toString(fi.getDocValuesGen()), scratch);
-        SimpleTextUtil.writeNewline(out);
-               
-        Map<String,String> atts = fi.attributes();
-        int numAtts = atts == null ? 0 : atts.size();
-        SimpleTextUtil.write(out, NUM_ATTS);
-        SimpleTextUtil.write(out, Integer.toString(numAtts), scratch);
-        SimpleTextUtil.writeNewline(out);
-      
-        if (numAtts > 0) {
-          for (Map.Entry<String,String> entry : atts.entrySet()) {
-            SimpleTextUtil.write(out, ATT_KEY);
-            SimpleTextUtil.write(out, entry.getKey(), scratch);
-            SimpleTextUtil.writeNewline(out);
-          
-            SimpleTextUtil.write(out, ATT_VALUE);
-            SimpleTextUtil.write(out, entry.getValue(), scratch);
-            SimpleTextUtil.writeNewline(out);
-          }
-        }
-      }
-      SimpleTextUtil.writeChecksum(out, scratch);
-      success = true;
-    } finally {
-      if (success) {
-        out.close();
-      } else {
-        IOUtils.closeWhileHandlingException(out);
-      }
-    }
-  }
-  
-  private static String getDocValuesType(DocValuesType type) {
-    return type == null ? "false" : type.toString();
-  }
-}
+using System;
+using System.Diagnostics;
+using System.Collections.Generic;
+
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+	/*
+	 * Licensed to the Apache Software Foundation (ASF) under one or more
+	 * contributor license agreements.  See the NOTICE file distributed with
+	 * this work for additional information regarding copyright ownership.
+	 * The ASF licenses this file to You under the Apache License, Version 2.0
+	 * (the "License"); you may not use this file except in compliance with
+	 * the License.  You may obtain a copy of the License at
+	 *
+	 *     http://www.apache.org/licenses/LICENSE-2.0
+	 *
+	 * Unless required by applicable law or agreed to in writing, software
+	 * distributed under the License is distributed on an "AS IS" BASIS,
+	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	 * See the License for the specific language governing permissions and
+	 * limitations under the License.
+	 */
+
+	using FieldInfo = index.FieldInfo;
+	using DocValuesType = index.FieldInfo.DocValuesType;
+	using FieldInfos = index.FieldInfos;
+	using IndexFileNames = index.IndexFileNames;
+	using IndexOptions = index.FieldInfo.IndexOptions;
+	using Directory = store.Directory;
+	using IOContext = store.IOContext;
+	using IndexOutput = store.IndexOutput;
+	using BytesRef = util.BytesRef;
+	using IOUtils = util.IOUtils;
+
+	/// <summary>
+	/// writes plaintext field infos files
+	/// <para>
+	/// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+	/// @lucene.experimental
+	/// </para>
+	/// </summary>
+	public class SimpleTextFieldInfosWriter : FieldInfosWriter
+	{
+
+	  /// <summary>
+	  /// Extension of field infos </summary>
+	  internal const string FIELD_INFOS_EXTENSION = "inf";
+
+	  internal static readonly BytesRef NUMFIELDS = new BytesRef("number of fields ");
+	  internal static readonly BytesRef NAME = new BytesRef("  name ");
+	  internal static readonly BytesRef NUMBER = new BytesRef("  number ");
+	  internal static readonly BytesRef ISINDEXED = new BytesRef("  indexed ");
+	  internal static readonly BytesRef STORETV = new BytesRef("  term vectors ");
+	  internal static readonly BytesRef STORETVPOS = new BytesRef("  term vector positions ");
+	  internal static readonly BytesRef STORETVOFF = new BytesRef("  term vector offsets ");
+	  internal static readonly BytesRef PAYLOADS = new BytesRef("  payloads ");
+	  internal static readonly BytesRef NORMS = new BytesRef("  norms ");
+	  internal static readonly BytesRef NORMS_TYPE = new BytesRef("  norms type ");
+	  internal static readonly BytesRef DOCVALUES = new BytesRef("  doc values ");
+	  internal static readonly BytesRef DOCVALUES_GEN = new BytesRef("  doc values gen ");
+	  internal static readonly BytesRef INDEXOPTIONS = new BytesRef("  index options ");
+	  internal static readonly BytesRef NUM_ATTS = new BytesRef("  attributes ");
+	  internal static readonly BytesRef ATT_KEY = new BytesRef("    key ");
+	  internal static readonly BytesRef ATT_VALUE = new BytesRef("    value ");
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void write(store.Directory directory, String segmentName, String segmentSuffix, index.FieldInfos infos, store.IOContext context) throws java.io.IOException
+	  public override void write(Directory directory, string segmentName, string segmentSuffix, FieldInfos infos, IOContext context)
+	  {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final String fileName = index.IndexFileNames.segmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
+		string fileName = IndexFileNames.segmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
+		IndexOutput @out = directory.createOutput(fileName, context);
+		BytesRef scratch = new BytesRef();
+		bool success = false;
+		try
+		{
+		  SimpleTextUtil.write(@out, NUMFIELDS);
+		  SimpleTextUtil.write(@out, Convert.ToString(infos.size()), scratch);
+		  SimpleTextUtil.WriteNewline(@out);
+
+		  foreach (FieldInfo fi in infos)
+		  {
+			SimpleTextUtil.write(@out, NAME);
+			SimpleTextUtil.write(@out, fi.name, scratch);
+			SimpleTextUtil.WriteNewline(@out);
+
+			SimpleTextUtil.write(@out, NUMBER);
+			SimpleTextUtil.write(@out, Convert.ToString(fi.number), scratch);
+			SimpleTextUtil.WriteNewline(@out);
+
+			SimpleTextUtil.write(@out, ISINDEXED);
+			SimpleTextUtil.write(@out, Convert.ToString(fi.Indexed), scratch);
+			SimpleTextUtil.WriteNewline(@out);
+
+			if (fi.Indexed)
+			{
+			  Debug.Assert(fi.IndexOptions.compareTo(FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads());
+			  SimpleTextUtil.write(@out, INDEXOPTIONS);
+			  SimpleTextUtil.write(@out, fi.IndexOptions.ToString(), scratch);
+			  SimpleTextUtil.WriteNewline(@out);
+			}
+
+			SimpleTextUtil.write(@out, STORETV);
+			SimpleTextUtil.write(@out, Convert.ToString(fi.hasVectors()), scratch);
+			SimpleTextUtil.WriteNewline(@out);
+
+			SimpleTextUtil.write(@out, PAYLOADS);
+			SimpleTextUtil.write(@out, Convert.ToString(fi.hasPayloads()), scratch);
+			SimpleTextUtil.WriteNewline(@out);
+
+			SimpleTextUtil.write(@out, NORMS);
+			SimpleTextUtil.write(@out, Convert.ToString(!fi.omitsNorms()), scratch);
+			SimpleTextUtil.WriteNewline(@out);
+
+			SimpleTextUtil.write(@out, NORMS_TYPE);
+			SimpleTextUtil.write(@out, getDocValuesType(fi.NormType), scratch);
+			SimpleTextUtil.WriteNewline(@out);
+
+			SimpleTextUtil.write(@out, DOCVALUES);
+			SimpleTextUtil.write(@out, getDocValuesType(fi.DocValuesType), scratch);
+			SimpleTextUtil.WriteNewline(@out);
+
+			SimpleTextUtil.write(@out, DOCVALUES_GEN);
+			SimpleTextUtil.write(@out, Convert.ToString(fi.DocValuesGen), scratch);
+			SimpleTextUtil.WriteNewline(@out);
+
+			IDictionary<string, string> atts = fi.attributes();
+			int numAtts = atts == null ? 0 : atts.Count;
+			SimpleTextUtil.write(@out, NUM_ATTS);
+			SimpleTextUtil.write(@out, Convert.ToString(numAtts), scratch);
+			SimpleTextUtil.WriteNewline(@out);
+
+			if (numAtts > 0)
+			{
+			  foreach (KeyValuePair<string, string> entry in atts.SetOfKeyValuePairs())
+			  {
+				SimpleTextUtil.write(@out, ATT_KEY);
+				SimpleTextUtil.write(@out, entry.Key, scratch);
+				SimpleTextUtil.WriteNewline(@out);
+
+				SimpleTextUtil.write(@out, ATT_VALUE);
+				SimpleTextUtil.write(@out, entry.Value, scratch);
+				SimpleTextUtil.WriteNewline(@out);
+			  }
+			}
+		  }
+		  SimpleTextUtil.WriteChecksum(@out, scratch);
+		  success = true;
+		}
+		finally
+		{
+		  if (success)
+		  {
+			@out.close();
+		  }
+		  else
+		  {
+			IOUtils.closeWhileHandlingException(@out);
+		  }
+		}
+	  }
+
+	  private static string getDocValuesType(FieldInfo.DocValuesType type)
+	  {
+		return type == null ? "false" : type.ToString();
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
index 63e999a..34025b9 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
@@ -1,690 +1,829 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.index.DocsAndPositionsEnum;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.store.BufferedChecksumIndexInput;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.FixedBitSet;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.IntsRef;
-import org.apache.lucene.util.StringHelper;
-import org.apache.lucene.util.UnicodeUtil;
-import org.apache.lucene.util.fst.Builder;
-import org.apache.lucene.util.fst.BytesRefFSTEnum;
-import org.apache.lucene.util.fst.FST;
-import org.apache.lucene.util.fst.PairOutputs;
-import org.apache.lucene.util.fst.PositiveIntOutputs;
-import org.apache.lucene.util.fst.Util;
-
-import static org.apache.lucene.codecs.simpletext.SimpleTextFieldsWriter.END;
-import static org.apache.lucene.codecs.simpletext.SimpleTextFieldsWriter.FIELD;
-import static org.apache.lucene.codecs.simpletext.SimpleTextFieldsWriter.TERM;
-import static org.apache.lucene.codecs.simpletext.SimpleTextFieldsWriter.DOC;
-import static org.apache.lucene.codecs.simpletext.SimpleTextFieldsWriter.FREQ;
-import static org.apache.lucene.codecs.simpletext.SimpleTextFieldsWriter.POS;
-import static org.apache.lucene.codecs.simpletext.SimpleTextFieldsWriter.START_OFFSET;
-import static org.apache.lucene.codecs.simpletext.SimpleTextFieldsWriter.END_OFFSET;
-import static org.apache.lucene.codecs.simpletext.SimpleTextFieldsWriter.PAYLOAD;
-
-class SimpleTextFieldsReader extends FieldsProducer {
-  private final TreeMap<String,Long> fields;
-  private final IndexInput in;
-  private final FieldInfos fieldInfos;
-  private final int maxDoc;
-
-  public SimpleTextFieldsReader(SegmentReadState state)  {
-    this.maxDoc = state.segmentInfo.getDocCount();
-    fieldInfos = state.fieldInfos;
-    in = state.directory.openInput(SimpleTextPostingsFormat.getPostingsFileName(state.segmentInfo.name, state.segmentSuffix), state.context);
-    bool success = false;
-    try {
-      fields = readFields(in.clone());
-      success = true;
-    } finally {
-      if (!success) {
-        IOUtils.closeWhileHandlingException(this);
-      }
-    }
-  }
-  
-  private TreeMap<String,Long> readFields(IndexInput in)  {
-    ChecksumIndexInput input = new BufferedChecksumIndexInput(in);
-    BytesRef scratch = new BytesRef(10);
-    TreeMap<String,Long> fields = new TreeMap<>();
-    
-    while (true) {
-      SimpleTextUtil.readLine(input, scratch);
-      if (scratch.equals(END)) {
-        SimpleTextUtil.checkFooter(input);
-        return fields;
-      } else if (StringHelper.startsWith(scratch, FIELD)) {
-        String fieldName = new String(scratch.bytes, scratch.offset + FIELD.length, scratch.length - FIELD.length, StandardCharsets.UTF_8);
-        fields.put(fieldName, input.getFilePointer());
-      }
-    }
-  }
-
-  private class SimpleTextTermsEnum extends TermsEnum {
-    private final IndexOptions indexOptions;
-    private int docFreq;
-    private long totalTermFreq;
-    private long docsStart;
-    private bool ended;
-    private final BytesRefFSTEnum<PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>> fstEnum;
-
-    public SimpleTextTermsEnum(FST<PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>> fst, IndexOptions indexOptions) {
-      this.indexOptions = indexOptions;
-      fstEnum = new BytesRefFSTEnum<>(fst);
-    }
-
-    @Override
-    public bool seekExact(BytesRef text)  {
-
-      final BytesRefFSTEnum.InputOutput<PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>> result = fstEnum.seekExact(text);
-      if (result != null) {
-        PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>> pair1 = result.output;
-        PairOutputs.Pair<Long,Long> pair2 = pair1.output2;
-        docsStart = pair1.output1;
-        docFreq = pair2.output1.intValue();
-        totalTermFreq = pair2.output2;
-        return true;
-      } else {
-        return false;
-      }
-    }
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System.Linq;
+
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+    using System;
+    using System.Diagnostics;
+    using System.Collections.Generic;
+
+    using DocsAndPositionsEnum = Index.DocsAndPositionsEnum;
+    using DocsEnum = Index.DocsEnum;
+    using FieldInfo = Index.FieldInfo;
+    using IndexOptions = Index.FieldInfo.IndexOptions;
+    using FieldInfos = Index.FieldInfos;
+    using SegmentReadState = Index.SegmentReadState;
+    using Terms = Index.Terms;
+    using TermsEnum = Index.TermsEnum;
+    using BufferedChecksumIndexInput = Store.BufferedChecksumIndexInput;
+    using ChecksumIndexInput = Store.ChecksumIndexInput;
+    using IndexInput = Store.IndexInput;
+    using ArrayUtil = Util.ArrayUtil;
+    using Bits = Util.Bits;
+    using BytesRef = Util.BytesRef;
+    using CharsRef = Util.CharsRef;
+    using FixedBitSet = Util.FixedBitSet;
+    using IOUtils = Util.IOUtils;
+    using IntsRef = Util.IntsRef;
+    using StringHelper = Util.StringHelper;
+    using UnicodeUtil = Util.UnicodeUtil;
+    using Builder = Util.Fst.Builder;
+    using BytesRefFSTEnum = Util.Fst.BytesRefFSTEnum;
+    using FST = Util.Fst.FST;
+    using PairOutputs = Util.Fst.PairOutputs;
+    using PositiveIntOutputs = Util.Fst.PositiveIntOutputs;
+    using Util = Util.Fst.Util;
+
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextFieldsWriter.END;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextFieldsWriter.FIELD;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextFieldsWriter.TERM;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextFieldsWriter.DOC;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextFieldsWriter.FREQ;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextFieldsWriter.POS;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextFieldsWriter.START_OFFSET;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextFieldsWriter.END_OFFSET;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextFieldsWriter.PAYLOAD;
+
+    internal class SimpleTextFieldsReader : FieldsProducer
+    {
+        private readonly SortedDictionary<string, long?> fields;
+        private readonly IndexInput _input;
+        private readonly FieldInfos fieldInfos;
+        private readonly int maxDoc;
+        private readonly IDictionary<string, SimpleTextTerms> _termsCache = new Dictionary<string, SimpleTextTerms>();
+
+        public SimpleTextFieldsReader(SegmentReadState state)
+        {
+            this.maxDoc = state.SegmentInfo.DocCount;
+            fieldInfos = state.FieldInfos;
+            _input =
+                state.Directory.OpenInput(
+                    SimpleTextPostingsFormat.GetPostingsFileName(state.SegmentInfo.Name, state.SegmentSuffix),
+                    state.Context);
+            bool success = false;
+            try
+            {
+                fields = readFields((IndexInput)_input.Clone());
+                success = true;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    IOUtils.CloseWhileHandlingException(this);
+                }
+            }
+        }
 
-    @Override
-    public SeekStatus seekCeil(BytesRef text)  {
-
-      //System.out.println("seek to text=" + text.utf8ToString());
-      final BytesRefFSTEnum.InputOutput<PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>> result = fstEnum.seekCeil(text);
-      if (result == null) {
-        //System.out.println("  end");
-        return SeekStatus.END;
-      } else {
-        //System.out.println("  got text=" + term.utf8ToString());
-        PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>> pair1 = result.output;
-        PairOutputs.Pair<Long,Long> pair2 = pair1.output2;
-        docsStart = pair1.output1;
-        docFreq = pair2.output1.intValue();
-        totalTermFreq = pair2.output2;
-
-        if (result.input.equals(text)) {
-          //System.out.println("  match docsStart=" + docsStart);
-          return SeekStatus.FOUND;
-        } else {
-          //System.out.println("  not match docsStart=" + docsStart);
-          return SeekStatus.NOT_FOUND;
+        private SortedDictionary<string, long?> ReadFields(IndexInput @in)
+        {
+            ChecksumIndexInput input = new BufferedChecksumIndexInput(@in);
+            BytesRef scratch = new BytesRef(10);
+            SortedDictionary<string, long?> fields = new SortedDictionary<string, long?>();
+
+            while (true)
+            {
+                SimpleTextUtil.ReadLine(input, scratch);
+                if (scratch.Equals(END))
+                {
+                    SimpleTextUtil.CheckFooter(input);
+                    return fields;
+                }
+                else if (StringHelper.StartsWith(scratch, FIELD))
+                {
+                    string fieldName = new string(scratch.Bytes, scratch.Offset + FIELD.length,
+                        scratch.Length - FIELD.length, StandardCharsets.UTF_8);
+                    fields[fieldName] = input.FilePointer;
+                }
+            }
         }
-      }
-    }
 
-    @Override
-    public BytesRef next()  {
-      Debug.Assert( !ended;
-      final BytesRefFSTEnum.InputOutput<PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>> result = fstEnum.next();
-      if (result != null) {
-        PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>> pair1 = result.output;
-        PairOutputs.Pair<Long,Long> pair2 = pair1.output2;
-        docsStart = pair1.output1;
-        docFreq = pair2.output1.intValue();
-        totalTermFreq = pair2.output2;
-        return result.input;
-      } else {
-        return null;
-      }
-    }
+        private class SimpleTextTermsEnum : TermsEnum
+        {
+            private readonly SimpleTextFieldsReader outerInstance;
+
+            internal readonly FieldInfo.IndexOptions indexOptions;
+            internal int docFreq_Renamed;
+            internal long totalTermFreq_Renamed;
+            internal long docsStart;
+            internal bool ended;
+            internal readonly BytesRefFSTEnum<PairOutputs.Pair<long?, PairOutputs.Pair<long?, long?>>> fstEnum;
+
+            public SimpleTextTermsEnum(SimpleTextFieldsReader outerInstance,
+                FST<PairOutputs.Pair<long?, PairOutputs.Pair<long?, long?>>> fst, FieldInfo.IndexOptions indexOptions)
+            {
+                this.outerInstance = outerInstance;
+                this.indexOptions = indexOptions;
+                fstEnum = new BytesRefFSTEnum<>(fst);
+            }
 
-    @Override
-    public BytesRef term() {
-      return fstEnum.current().input;
-    }
+            public override bool SeekExact(BytesRef text)
+            {
+
+                BytesRefFSTEnum.InputOutput<PairOutputs.Pair<long?, PairOutputs.Pair<long?, long?>>> result =
+                    fstEnum.SeekExact(text);
+                if (result != null)
+                {
+                    PairOutputs.Pair<long?, PairOutputs.Pair<long?, long?>> pair1 = result.output;
+                    PairOutputs.Pair<long?, long?> pair2 = pair1.output2;
+                    docsStart = pair1.Output1;
+                    docFreq_Renamed = (int) pair2.Output1;
+                    totalTermFreq_Renamed = pair2.Output2;
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
 
-    @Override
-    public long ord()  {
-      throw new UnsupportedOperationException();
-    }
+            public override SeekStatus SeekCeil(BytesRef text)
+            {
+
+                BytesRefFSTEnum.InputOutput<PairOutputs.Pair<long?, PairOutputs.Pair<long?, long?>>> result =
+                    fstEnum.SeekCeil(text);
+                if (result == null)
+                {
+                    //System.out.println("  end");
+                    return SeekStatus.END;
+                }
+                else
+                {
+                    //System.out.println("  got text=" + term.utf8ToString());
+                    PairOutputs.Pair<long?, PairOutputs.Pair<long?, long?>> pair1 = result.output;
+                    PairOutputs.Pair<long?, long?> pair2 = pair1.output2;
+                    docsStart = pair1.output1;
+                    docFreq_Renamed = (int) pair2.output1;
+                    totalTermFreq_Renamed = pair2.output2;
+
+                    if (result.input.Equals(text))
+                    {
+                        //System.out.println("  match docsStart=" + docsStart);
+                        return SeekStatus.FOUND;
+                    }
+                    else
+                    {
+                        //System.out.println("  not match docsStart=" + docsStart);
+                        return SeekStatus.NOT_FOUND;
+                    }
+                }
+            }
+            public override BytesRef Next()
+            {
+                Debug.Assert(!ended);
+                BytesRefFSTEnum.InputOutput<PairOutputs.Pair<long?, PairOutputs.Pair<long?, long?>>> result =
+                    fstEnum.Next();
+                if (result != null)
+                {
+                    PairOutputs.Pair<long?, PairOutputs.Pair<long?, long?>> pair1 = result.output;
+                    PairOutputs.Pair<long?, long?> pair2 = pair1.output2;
+                    docsStart = pair1.output1;
+                    docFreq_Renamed = (int) pair2.output1;
+                    totalTermFreq_Renamed = pair2.output2;
+                    return result.input;
+                }
+                else
+                {
+                    return null;
+                }
+            }
 
-    @Override
-    public void seekExact(long ord) {
-      throw new UnsupportedOperationException();
-    }
+            public override BytesRef Term()
+            {
+                return fstEnum.Current().Input;
+            }
 
-    @Override
-    public int docFreq() {
-      return docFreq;
-    }
+            public override long Ord()
+            {
+                throw new NotSupportedException();
+            }
 
-    @Override
-    public long totalTermFreq() {
-      return indexOptions == IndexOptions.DOCS_ONLY ? -1 : totalTermFreq;
-    }
- 
-    @Override
-    public DocsEnum docs(Bits liveDocs, DocsEnum reuse, int flags)  {
-      SimpleTextDocsEnum docsEnum;
-      if (reuse != null && reuse instanceof SimpleTextDocsEnum && ((SimpleTextDocsEnum) reuse).canReuse(SimpleTextFieldsReader.this.in)) {
-        docsEnum = (SimpleTextDocsEnum) reuse;
-      } else {
-        docsEnum = new SimpleTextDocsEnum();
-      }
-      return docsEnum.reset(docsStart, liveDocs, indexOptions == IndexOptions.DOCS_ONLY, docFreq);
-    }
+            public override void SeekExact(long ord)
+            {
+                throw new NotSupportedException();
+            }
 
-    @Override
-    public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags)  {
-
-      if (indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
-        // Positions were not indexed
-        return null;
-      }
-
-      SimpleTextDocsAndPositionsEnum docsAndPositionsEnum;
-      if (reuse != null && reuse instanceof SimpleTextDocsAndPositionsEnum && ((SimpleTextDocsAndPositionsEnum) reuse).canReuse(SimpleTextFieldsReader.this.in)) {
-        docsAndPositionsEnum = (SimpleTextDocsAndPositionsEnum) reuse;
-      } else {
-        docsAndPositionsEnum = new SimpleTextDocsAndPositionsEnum();
-      } 
-      return docsAndPositionsEnum.reset(docsStart, liveDocs, indexOptions, docFreq);
-    }
-    
-    @Override
-    public Comparator<BytesRef> getComparator() {
-      return BytesRef.getUTF8SortedAsUnicodeComparator();
-    }
-  }
-
-  private class SimpleTextDocsEnum extends DocsEnum {
-    private final IndexInput inStart;
-    private final IndexInput in;
-    private bool omitTF;
-    private int docID = -1;
-    private int tf;
-    private Bits liveDocs;
-    private final BytesRef scratch = new BytesRef(10);
-    private final CharsRef scratchUTF16 = new CharsRef(10);
-    private int cost;
-    
-    public SimpleTextDocsEnum() {
-      this.inStart = SimpleTextFieldsReader.this.in;
-      this.in = this.inStart.clone();
-    }
+            public override int DocFreq()
+            {
+                return docFreq_Renamed;
+            }
 
-    public bool canReuse(IndexInput in) {
-      return in == inStart;
-    }
+            public override long TotalTermFreq()
+            {
+                return indexOptions == IndexOptions.DOCS_ONLY ? - 1 : totalTermFreq_Renamed;
+            }
 
-    public SimpleTextDocsEnum reset(long fp, Bits liveDocs, bool omitTF, int docFreq)  {
-      this.liveDocs = liveDocs;
-      in.seek(fp);
-      this.omitTF = omitTF;
-      docID = -1;
-      tf = 1;
-      cost = docFreq;
-      return this;
-    }
+            public override DocsEnum Docs(Bits liveDocs, DocsEnum reuse, int flags)
+            {
+                SimpleTextDocsEnum docsEnum;
+                if (reuse != null && reuse is SimpleTextDocsEnum &&
+                    ((SimpleTextDocsEnum) reuse).CanReuse(outerInstance._input))
+                {
+                    docsEnum = (SimpleTextDocsEnum) reuse;
+                }
+                else
+                {
+                    docsEnum = new SimpleTextDocsEnum(outerInstance);
+                }
+                return docsEnum.Reset(docsStart, liveDocs, indexOptions == IndexOptions.DOCS_ONLY,
+                    docFreq_Renamed);
+            }
 
-    @Override
-    public int docID() {
-      return docID;
-    }
+            public override DocsAndPositionsEnum DocsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags)
+            {
+
+                if (indexOptions < IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
+                {
+                    // Positions were not indexed
+                    return null;
+                }
+
+                SimpleTextDocsAndPositionsEnum docsAndPositionsEnum;
+                if (reuse != null && reuse is SimpleTextDocsAndPositionsEnum &&
+                    ((SimpleTextDocsAndPositionsEnum) reuse).canReuse(outerInstance._input))
+                {
+                    docsAndPositionsEnum = (SimpleTextDocsAndPositionsEnum) reuse;
+                }
+                else
+                {
+                    docsAndPositionsEnum = new SimpleTextDocsAndPositionsEnum(outerInstance);
+                }
+                return docsAndPositionsEnum.reset(docsStart, liveDocs, indexOptions, docFreq_Renamed);
+            }
 
-    @Override
-    public int freq()  {
-      return tf;
-    }
+            public override IComparer<BytesRef> Comparator
+            {
+                get { return BytesRef.UTF8SortedAsUnicodeComparer; }
+            }
+        }
+
+        private class SimpleTextDocsEnum : DocsEnum
+        {
+            private readonly SimpleTextFieldsReader outerInstance;
+
+            internal readonly IndexInput inStart;
+            internal readonly IndexInput @in;
+            internal bool omitTF;
+            internal int docID_Renamed = -1;
+            internal int tf;
+            internal Bits liveDocs;
+            internal readonly BytesRef scratch = new BytesRef(10);
+            internal readonly CharsRef scratchUTF16 = new CharsRef(10);
+            internal int cost_Renamed;
+
+            public SimpleTextDocsEnum(SimpleTextFieldsReader outerInstance)
+            {
+                this.outerInstance = outerInstance;
+                inStart = outerInstance._input;
+                @in = (IndexInput) inStart.Clone();
+            }
+
+            public virtual bool CanReuse(IndexInput @in)
+            {
+                return @in == inStart;
+            }
+
+            public virtual SimpleTextDocsEnum Reset(long fp, Bits liveDocs, bool omitTF, int docFreq)
+            {
+                this.liveDocs = liveDocs;
+                @in.Seek(fp);
+                this.omitTF = omitTF;
+                docID_Renamed = -1;
+                tf = 1;
+                cost_Renamed = docFreq;
+                return this;
+            }
+
+            public override int DocID()
+            {
+                return docID_Renamed;
+            }
+
+            public override int Freq()
+            {
+                return tf;
+            }
+
+            public override int NextDoc()
+            {
+                if (docID_Renamed == NO_MORE_DOCS)
+                {
+                    return docID_Renamed;
+                }
+                bool first = true;
+                int termFreq = 0;
+                while (true)
+                {
+                    long lineStart = @in.FilePointer;
+                    SimpleTextUtil.ReadLine(@in, scratch);
+                    if (StringHelper.StartsWith(scratch, DOC))
+                    {
+                        if (!first && (liveDocs == null || liveDocs.Get(docID_Renamed)))
+                        {
+                            @in.Seek(lineStart);
+                            if (!omitTF)
+                            {
+                                tf = termFreq;
+                            }
+                            return docID_Renamed;
+                        }
+                        UnicodeUtil.UTF8toUTF16(scratch.Bytes, scratch.Offset + DOC.length, scratch.Length - DOC.length,
+                            scratchUTF16);
+                        docID_Renamed = ArrayUtil.ParseInt(scratchUTF16.Chars, 0, scratchUTF16.length);
+                        termFreq = 0;
+                        first = false;
+                    }
+                    else if (StringHelper.StartsWith(scratch, FREQ))
+                    {
+                        UnicodeUtil.UTF8toUTF16(scratch.Bytes, scratch.Offset + FREQ.length,
+                            scratch.Length - FREQ.length, scratchUTF16);
+                        termFreq = ArrayUtil.ParseInt(scratchUTF16.Chars, 0, scratchUTF16.length);
+                    }
+                    else if (StringHelper.StartsWith(scratch, POS))
+                    {
+                        // skip termFreq++;
+                    }
+                    else if (StringHelper.StartsWith(scratch, START_OFFSET))
+                    {
+                        // skip
+                    }
+                    else if (StringHelper.StartsWith(scratch, END_OFFSET))
+                    {
+                        // skip
+                    }
+                    else if (StringHelper.StartsWith(scratch, PAYLOAD))
+                    {
+                        // skip
+                    }
+                    else
+                    {
+                        Debug.Assert(
+                            StringHelper.StartsWith(scratch, TERM) || StringHelper.StartsWith(scratch, FIELD) ||
+                            StringHelper.StartsWith(scratch, END), "scratch=" + scratch.Utf8ToString());
+                        if (!first && (liveDocs == null || liveDocs.Get(docID_Renamed)))
+                        {
+                            @in.Seek(lineStart);
+                            if (!omitTF)
+                            {
+                                tf = termFreq;
+                            }
+                            return docID_Renamed;
+                        }
+                        return docID_Renamed = NO_MORE_DOCS;
+                    }
+                }
+            }
+
+            public override int Advance(int target)
+            {
+                // Naive -- better to index skip data
+                return SlowAdvance(target);
+            }
 
-    @Override
-    public int nextDoc()  {
-      if (docID == NO_MORE_DOCS) {
-        return docID;
-      }
-      bool first = true;
-      int termFreq = 0;
-      while(true) {
-        final long lineStart = in.getFilePointer();
-        SimpleTextUtil.readLine(in, scratch);
-        if (StringHelper.startsWith(scratch, DOC)) {
-          if (!first && (liveDocs == null || liveDocs.get(docID))) {
-            in.seek(lineStart);
-            if (!omitTF) {
-              tf = termFreq;
-            }
-            return docID;
-          }
-          UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+DOC.length, scratch.length-DOC.length, scratchUTF16);
-          docID = ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
-          termFreq = 0;
-          first = false;
-        } else if (StringHelper.startsWith(scratch, FREQ)) {
-          UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+FREQ.length, scratch.length-FREQ.length, scratchUTF16);
-          termFreq = ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
-        } else if (StringHelper.startsWith(scratch, POS)) {
-          // skip termFreq++;
-        } else if (StringHelper.startsWith(scratch, START_OFFSET)) {
-          // skip
-        } else if (StringHelper.startsWith(scratch, END_OFFSET)) {
-          // skip
-        } else if (StringHelper.startsWith(scratch, PAYLOAD)) {
-          // skip
-        } else {
-          Debug.Assert( StringHelper.startsWith(scratch, TERM) || StringHelper.startsWith(scratch, FIELD) || StringHelper.startsWith(scratch, END): "scratch=" + scratch.utf8ToString();
-          if (!first && (liveDocs == null || liveDocs.get(docID))) {
-            in.seek(lineStart);
-            if (!omitTF) {
-              tf = termFreq;
-            }
-            return docID;
-          }
-          return docID = NO_MORE_DOCS;
+            public override long Cost()
+            {
+                return cost_Renamed;
+            }
         }
-      }
-    }
 
-    @Override
-    public int advance(int target)  {
-      // Naive -- better to index skip data
-      return slowAdvance(target);
-    }
-    
-    @Override
-    public long cost() {
-      return cost;
-    }
-  }
-
-  private class SimpleTextDocsAndPositionsEnum extends DocsAndPositionsEnum {
-    private final IndexInput inStart;
-    private final IndexInput in;
-    private int docID = -1;
-    private int tf;
-    private Bits liveDocs;
-    private final BytesRef scratch = new BytesRef(10);
-    private final BytesRef scratch2 = new BytesRef(10);
-    private final CharsRef scratchUTF16 = new CharsRef(10);
-    private final CharsRef scratchUTF16_2 = new CharsRef(10);
-    private BytesRef payload;
-    private long nextDocStart;
-    private bool readOffsets;
-    private bool readPositions;
-    private int startOffset;
-    private int endOffset;
-    private int cost;
-
-    public SimpleTextDocsAndPositionsEnum() {
-      this.inStart = SimpleTextFieldsReader.this.in;
-      this.in = inStart.clone();
-    }
+        private class SimpleTextDocsAndPositionsEnum : DocsAndPositionsEnum
+        {
+            private readonly SimpleTextFieldsReader outerInstance;
+
+            internal readonly IndexInput inStart;
+            internal readonly IndexInput @in;
+            internal int docID_Renamed = -1;
+            internal int tf;
+            internal Bits liveDocs;
+            internal readonly BytesRef scratch = new BytesRef(10);
+            internal readonly BytesRef scratch2 = new BytesRef(10);
+            internal readonly CharsRef scratchUTF16 = new CharsRef(10);
+            internal readonly CharsRef scratchUTF16_2 = new CharsRef(10);
+            internal BytesRef payload;
+            internal long nextDocStart;
+            internal bool readOffsets;
+            internal bool readPositions;
+            internal int startOffset_Renamed;
+            internal int endOffset_Renamed;
+            internal int cost_Renamed;
+
+            public SimpleTextDocsAndPositionsEnum(SimpleTextFieldsReader outerInstance)
+            {
+                this.outerInstance = outerInstance;
+                this.inStart = outerInstance._input;
+                this.@in = (IndexInput) inStart.Clone();
+            }
 
-    public bool canReuse(IndexInput in) {
-      return in == inStart;
-    }
+            public virtual bool canReuse(IndexInput @in)
+            {
+                return @in == inStart;
+            }
 
-    public SimpleTextDocsAndPositionsEnum reset(long fp, Bits liveDocs, IndexOptions indexOptions, int docFreq) {
-      this.liveDocs = liveDocs;
-      nextDocStart = fp;
-      docID = -1;
-      readPositions = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
-      readOffsets = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
-      if (!readOffsets) {
-        startOffset = -1;
-        endOffset = -1;
-      }
-      cost = docFreq;
-      return this;
-    }
+            public virtual SimpleTextDocsAndPositionsEnum reset(long fp, Bits liveDocs,
+                FieldInfo.IndexOptions indexOptions, int docFreq)
+            {
+                this.liveDocs = liveDocs;
+                nextDocStart = fp;
+                docID_Renamed = -1;
+                readPositions = indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
+                readOffsets = indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
+
+                if (!readOffsets)
+                {
+                    startOffset_Renamed = -1;
+                    endOffset_Renamed = -1;
+                }
+                cost_Renamed = docFreq;
+                return this;
+            }
 
-    @Override
-    public int docID() {
-      return docID;
-    }
+            public override int DocID()
+            {
+                return docID_Renamed;
+            }
 
-    @Override
-    public int freq()  {
-      return tf;
-    }
+            public override int Freq()
+            {
+                return tf;
+            }
+
+            public override int NextDoc()
+            {
+                bool first = true;
+                @in.Seek(nextDocStart);
+                long posStart = 0;
+                while (true)
+                {
+                    long lineStart = @in.FilePointer;
+                    SimpleTextUtil.ReadLine(@in, scratch);
+                    //System.out.println("NEXT DOC: " + scratch.utf8ToString());
+                    if (StringHelper.StartsWith(scratch, DOC))
+                    {
+                        if (!first && (liveDocs == null || liveDocs.Get(docID_Renamed)))
+                        {
+                            nextDocStart = lineStart;
+                            @in.Seek(posStart);
+                            return docID_Renamed;
+                        }
+                        UnicodeUtil.UTF8toUTF16(scratch.Bytes, scratch.Offset + DOC.length, scratch.Length - DOC.length,
+                            scratchUTF16);
+                        docID_Renamed = ArrayUtil.ParseInt(scratchUTF16.Chars, 0, scratchUTF16.length);
+                        tf = 0;
+                        first = false;
+                    }
+                    else if (StringHelper.StartsWith(scratch, FREQ))
+                    {
+                        UnicodeUtil.UTF8toUTF16(scratch.Bytes, scratch.Offset + FREQ.length,
+                            scratch.Length - FREQ.length, scratchUTF16);
+                        tf = ArrayUtil.ParseInt(scratchUTF16.Chars, 0, scratchUTF16.length);
+                        posStart = @in.FilePointer;
+                    }
+                    else if (StringHelper.StartsWith(scratch, POS))
+                    {
+                        // skip
+                    }
+                    else if (StringHelper.StartsWith(scratch, START_OFFSET))
+                    {
+                        // skip
+                    }
+                    else if (StringHelper.StartsWith(scratch, END_OFFSET))
+                    {
+                        // skip
+                    }
+                    else if (StringHelper.StartsWith(scratch, PAYLOAD))
+                    {
+                        // skip
+                    }
+                    else
+                    {
+                        Debug.Assert(StringHelper.StartsWith(scratch, TERM) || StringHelper.StartsWith(scratch, FIELD) ||
+                                     StringHelper.StartsWith(scratch, END));
+
+                        if (!first && (liveDocs == null || liveDocs.Get(docID_Renamed)))
+                        {
+                            nextDocStart = lineStart;
+                            @in.Seek(posStart);
+                            return docID_Renamed;
+                        }
+                        return docID_Renamed = NO_MORE_DOCS;
+                    }
+                }
+            }
+
+            public override int Advance(int target)
+            {
+                // Naive -- better to index skip data
+                return SlowAdvance(target);
+            }
+
+            public override int NextPosition()
+            {
+                int pos;
+                if (readPositions)
+                {
+                    SimpleTextUtil.ReadLine(@in, scratch);
+                    Debug.Assert(StringHelper.StartsWith(scratch, POS), "got line=" + scratch.Utf8ToString());
+                    UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.Offset + POS.length, scratch.Length - POS.length,
+                        scratchUTF16_2);
+                    pos = ArrayUtil.ParseInt(scratchUTF16_2.Chars, 0, scratchUTF16_2.length);
+                }
+                else
+                {
+                    pos = -1;
+                }
+
+                if (readOffsets)
+                {
+                    SimpleTextUtil.ReadLine(@in, scratch);
+                    Debug.Assert(StringHelper.StartsWith(scratch, START_OFFSET), "got line=" + scratch.Utf8ToString());
+                    UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.Offset + START_OFFSET.length,
+                        scratch.Length - START_OFFSET.length, scratchUTF16_2);
+                    startOffset_Renamed = ArrayUtil.ParseInt(scratchUTF16_2.chars, 0, scratchUTF16_2.length);
+                    SimpleTextUtil.ReadLine(@in, scratch);
+                    Debug.Assert(StringHelper.StartsWith(scratch, END_OFFSET), "got line=" + scratch.Utf8ToString());
+                    UnicodeUtil.UTF8toUTF16(scratch.Bytes, scratch.Offset + END_OFFSET.length,
+                        scratch.Length - END_OFFSET.length, scratchUTF16_2);
+                    endOffset_Renamed = ArrayUtil.ParseInt(scratchUTF16_2.Chars, 0, scratchUTF16_2.length);
+                }
+
+                long fp = @in.FilePointer;
+                SimpleTextUtil.ReadLine(@in, scratch);
+                if (StringHelper.StartsWith(scratch, PAYLOAD))
+                {
+                    int len = scratch.Length - PAYLOAD.length;
+                    if (scratch2.Bytes.Length < len)
+                    {
+                        scratch2.Grow(len);
+                    }
+                    Array.Copy(scratch.Bytes, PAYLOAD.length, scratch2.Bytes, 0, len);
+                    scratch2.Length = len;
+                    payload = scratch2;
+                }
+                else
+                {
+                    payload = null;
+                    @in.Seek(fp);
+                }
+                return pos;
+            }
+
+            public override int StartOffset()
+            {
+                return startOffset_Renamed;
+            }
+
+            public override int EndOffset()
+            {
+                return endOffset_Renamed;
+            }
+
+            public override BytesRef Payload
+            {
+                get { return payload; }
+            }
 
-    @Override
-    public int nextDoc()  {
-      bool first = true;
-      in.seek(nextDocStart);
-      long posStart = 0;
-      while(true) {
-        final long lineStart = in.getFilePointer();
-        SimpleTextUtil.readLine(in, scratch);
-        //System.out.println("NEXT DOC: " + scratch.utf8ToString());
-        if (StringHelper.startsWith(scratch, DOC)) {
-          if (!first && (liveDocs == null || liveDocs.get(docID))) {
-            nextDocStart = lineStart;
-            in.seek(posStart);
-            return docID;
-          }
-          UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+DOC.length, scratch.length-DOC.length, scratchUTF16);
-          docID = ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
-          tf = 0;
-          first = false;
-        } else if (StringHelper.startsWith(scratch, FREQ)) {
-          UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+FREQ.length, scratch.length-FREQ.length, scratchUTF16);
-          tf = ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
-          posStart = in.getFilePointer();
-        } else if (StringHelper.startsWith(scratch, POS)) {
-          // skip
-        } else if (StringHelper.startsWith(scratch, START_OFFSET)) {
-          // skip
-        } else if (StringHelper.startsWith(scratch, END_OFFSET)) {
-          // skip
-        } else if (StringHelper.startsWith(scratch, PAYLOAD)) {
-          // skip
-        } else {
-          Debug.Assert( StringHelper.startsWith(scratch, TERM) || StringHelper.startsWith(scratch, FIELD) || StringHelper.startsWith(scratch, END);
-          if (!first && (liveDocs == null || liveDocs.get(docID))) {
-            nextDocStart = lineStart;
-            in.seek(posStart);
-            return docID;
-          }
-          return docID = NO_MORE_DOCS;
+            public override long Cost()
+            {
+                return cost_Renamed;
+            }
         }
-      }
-    }
 
-    @Override
-    public int advance(int target)  {
-      // Naive -- better to index skip data
-      return slowAdvance(target);
-    }
+        internal class TermData
+        {
+            public long DocsStart { get; set; }
+            public int DocFreq { get; set; }
 
-    @Override
-    public int nextPosition()  {
-      final int pos;
-      if (readPositions) {
-        SimpleTextUtil.readLine(in, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, POS): "got line=" + scratch.utf8ToString();
-        UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+POS.length, scratch.length-POS.length, scratchUTF16_2);
-        pos = ArrayUtil.parseInt(scratchUTF16_2.chars, 0, scratchUTF16_2.length);
-      } else {
-        pos = -1;
-      }
-
-      if (readOffsets) {
-        SimpleTextUtil.readLine(in, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, START_OFFSET): "got line=" + scratch.utf8ToString();
-        UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+START_OFFSET.length, scratch.length-START_OFFSET.length, scratchUTF16_2);
-        startOffset = ArrayUtil.parseInt(scratchUTF16_2.chars, 0, scratchUTF16_2.length);
-        SimpleTextUtil.readLine(in, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, END_OFFSET): "got line=" + scratch.utf8ToString();
-        UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+END_OFFSET.length, scratch.length-END_OFFSET.length, scratchUTF16_2);
-        endOffset = ArrayUtil.parseInt(scratchUTF16_2.chars, 0, scratchUTF16_2.length);
-      }
-
-      final long fp = in.getFilePointer();
-      SimpleTextUtil.readLine(in, scratch);
-      if (StringHelper.startsWith(scratch, PAYLOAD)) {
-        final int len = scratch.length - PAYLOAD.length;
-        if (scratch2.bytes.length < len) {
-          scratch2.grow(len);
+            public TermData(long docsStart, int docFreq)
+            {
+                DocsStart = docsStart;
+                DocFreq = docFreq;
+            }
         }
-        System.arraycopy(scratch.bytes, PAYLOAD.length, scratch2.bytes, 0, len);
-        scratch2.length = len;
-        payload = scratch2;
-      } else {
-        payload = null;
-        in.seek(fp);
-      }
-      return pos;
-    }
 
-    @Override
-    public int startOffset()  {
-      return startOffset;
-    }
+        private class SimpleTextTerms : Terms
+        {
+            private readonly SimpleTextFieldsReader outerInstance;
+
+            internal readonly long termsStart;
+            internal readonly FieldInfo fieldInfo;
+            internal readonly int maxDoc;
+            internal long sumTotalTermFreq;
+            internal long sumDocFreq;
+            internal int docCount;
+            internal FST<PairOutputs.Pair<long?, PairOutputs.Pair<long?, long?>>> fst;
+            internal int termCount;
+            internal readonly BytesRef scratch = new BytesRef(10);
+            internal readonly CharsRef scratchUTF16 = new CharsRef(10);
+
+            public SimpleTextTerms(SimpleTextFieldsReader outerInstance, string field, long termsStart, int maxDoc)
+            {
+                this.outerInstance = outerInstance;
+                this.maxDoc = maxDoc;
+                this.termsStart = termsStart;
+                fieldInfo = outerInstance.fieldInfos.FieldInfo(field);
+                LoadTerms();
+            }
 
-    @Override
-    public int endOffset()  {
-      return endOffset;
-    }
+            internal virtual void LoadTerms()
+            {
+                PositiveIntOutputs posIntOutputs = PositiveIntOutputs.Singleton;
+                Builder<PairOutputs.Pair<long?, PairOutputs.Pair<long?, long?>>> b;
+                PairOutputs<long?, long?> outputsInner = new PairOutputs<long?, long?>(posIntOutputs, posIntOutputs);
+                PairOutputs<long?, PairOutputs.Pair<long?, long?>> outputs =
+                    new PairOutputs<long?, PairOutputs.Pair<long?, long?>>(posIntOutputs, outputsInner);
+                b = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
+                IndexInput @in = (IndexInput) outerInstance._input.Clone();
+                @in.Seek(termsStart);
+
+                BytesRef lastTerm = new BytesRef(10);
+                long lastDocsStart = -1;
+                int docFreq = 0;
+                long totalTermFreq = 0;
+                FixedBitSet visitedDocs = new FixedBitSet(maxDoc);
+
+                IntsRef scratchIntsRef = new IntsRef();
+                while (true)
+                {
+                    SimpleTextUtil.ReadLine(@in, scratch);
+                    if (scratch.Equals(END) || StringHelper.StartsWith(scratch, FIELD))
+                    {
+                        if (lastDocsStart != -1)
+                        {
+                            b.Add(Util.ToIntsRef(lastTerm, scratchIntsRef),
+                                outputs.NewPair(lastDocsStart, outputsInner.NewPair((long) docFreq, totalTermFreq)));
+                            sumTotalTermFreq += totalTermFreq;
+                        }
+                        break;
+                    }
+                    else if (StringHelper.StartsWith(scratch, DOC))
+                    {
+                        docFreq++;
+                        sumDocFreq++;
+                        UnicodeUtil.UTF8toUTF16(scratch.Bytes, scratch.Offset + DOC.length, scratch.Length - DOC.length,
+                            scratchUTF16);
+                        int docID = ArrayUtil.ParseInt(scratchUTF16.Chars, 0, scratchUTF16.length);
+                        visitedDocs.Set(docID);
+                    }
+                    else if (StringHelper.StartsWith(scratch, FREQ))
+                    {
+                        UnicodeUtil.UTF8toUTF16(scratch.Bytes, scratch.Offset + FREQ.length,
+                            scratch.Length - FREQ.length, scratchUTF16);
+                        totalTermFreq += ArrayUtil.ParseInt(scratchUTF16.Chars, 0, scratchUTF16.length);
+                    }
+                    else if (StringHelper.StartsWith(scratch, TERM))
+                    {
+                        if (lastDocsStart != -1)
+                        {
+                            b.Add(Util.ToIntsRef(lastTerm, scratchIntsRef),
+                                outputs.NewPair(lastDocsStart, outputsInner.NewPair((long) docFreq, totalTermFreq)));
+                        }
+                        lastDocsStart = @in.FilePointer;
+                        int len = scratch.Length - TERM.length;
+                        if (len > lastTerm.Length)
+                        {
+                            lastTerm.Grow(len);
+                        }
+                        Array.Copy(scratch.Bytes, TERM.length, lastTerm.Bytes, 0, len);
+                        lastTerm.Length = len;
+                        docFreq = 0;
+                        sumTotalTermFreq += totalTermFreq;
+                        totalTermFreq = 0;
+                        termCount++;
+                    }
+                }
+                docCount = visitedDocs.Cardinality();
+                fst = b.Finish();
+            
+            }
 
-    @Override
-    public BytesRef getPayload() {
-      return payload;
-    }
-    
-    @Override
-    public long cost() {
-      return cost;
-    }
-  }
+            /// <summary>Returns approximate RAM bytes used</summary>
+            public virtual long RamBytesUsed()
+            {
+                return (fst != null) ? fst.SizeInBytes : 0;
+            }
 
-  static class TermData {
-    public long docsStart;
-    public int docFreq;
+            public override TermsEnum Iterator(TermsEnum reuse)
+            {
+                return fst != null ? new SimpleTextTermsEnum(outerInstance, fst, fieldInfo.FieldIndexOptions.Value) : TermsEnum.EMPTY;
+            }
 
-    public TermData(long docsStart, int docFreq) {
-      this.docsStart = docsStart;
-      this.docFreq = docFreq;
-    }
-  }
-
-  private class SimpleTextTerms extends Terms {
-    private final long termsStart;
-    private final FieldInfo fieldInfo;
-    private final int maxDoc;
-    private long sumTotalTermFreq;
-    private long sumDocFreq;
-    private int docCount;
-    private FST<PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>> fst;
-    private int termCount;
-    private final BytesRef scratch = new BytesRef(10);
-    private final CharsRef scratchUTF16 = new CharsRef(10);
-
-    public SimpleTextTerms(String field, long termsStart, int maxDoc)  {
-      this.maxDoc = maxDoc;
-      this.termsStart = termsStart;
-      fieldInfo = fieldInfos.fieldInfo(field);
-      loadTerms();
-    }
+            public override IComparer<BytesRef> Comparator
+            {
+                get { return BytesRef.UTF8SortedAsUnicodeComparer; }
+            }
 
-    private void loadTerms()  {
-      PositiveIntOutputs posIntOutputs = PositiveIntOutputs.getSingleton();
-      final Builder<PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>> b;
-      final PairOutputs<Long,Long> outputsInner = new PairOutputs<>(posIntOutputs, posIntOutputs);
-      final PairOutputs<Long,PairOutputs.Pair<Long,Long>> outputs = new PairOutputs<>(posIntOutputs,
-                                                                                                                      outputsInner);
-      b = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
-      IndexInput in = SimpleTextFieldsReader.this.in.clone();
-      in.seek(termsStart);
-      final BytesRef lastTerm = new BytesRef(10);
-      long lastDocsStart = -1;
-      int docFreq = 0;
-      long totalTermFreq = 0;
-      FixedBitSet visitedDocs = new FixedBitSet(maxDoc);
-      final IntsRef scratchIntsRef = new IntsRef();
-      while(true) {
-        SimpleTextUtil.readLine(in, scratch);
-        if (scratch.equals(END) || StringHelper.startsWith(scratch, FIELD)) {
-          if (lastDocsStart != -1) {
-            b.add(Util.toIntsRef(lastTerm, scratchIntsRef),
-                  outputs.newPair(lastDocsStart,
-                                  outputsInner.newPair((long) docFreq, totalTermFreq)));
-            sumTotalTermFreq += totalTermFreq;
-          }
-          break;
-        } else if (StringHelper.startsWith(scratch, DOC)) {
-          docFreq++;
-          sumDocFreq++;
-          UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+DOC.length, scratch.length-DOC.length, scratchUTF16);
-          int docID = ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
-          visitedDocs.set(docID);
-        } else if (StringHelper.startsWith(scratch, FREQ)) {
-          UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+FREQ.length, scratch.length-FREQ.length, scratchUTF16);
-          totalTermFreq += ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
-        } else if (StringHelper.startsWith(scratch, TERM)) {
-          if (lastDocsStart != -1) {
-            b.add(Util.toIntsRef(lastTerm, scratchIntsRef), outputs.newPair(lastDocsStart,
-                                                                            outputsInner.newPair((long) docFreq, totalTermFreq)));
-          }
-          lastDocsStart = in.getFilePointer();
-          final int len = scratch.length - TERM.length;
-          if (len > lastTerm.length) {
-            lastTerm.grow(len);
-          }
-          System.arraycopy(scratch.bytes, TERM.length, lastTerm.bytes, 0, len);
-          lastTerm.length = len;
-          docFreq = 0;
-          sumTotalTermFreq += totalTermFreq;
-          totalTermFreq = 0;
-          termCount++;
-        }
-      }
-      docCount = visitedDocs.cardinality();
-      fst = b.finish();
-      /*
-      PrintStream ps = new PrintStream("out.dot");
-      fst.toDot(ps);
-      ps.close();
-      System.out.println("SAVED out.dot");
-      */
-      //System.out.println("FST " + fst.sizeInBytes());
-    }
-    
-    /** Returns approximate RAM bytes used */
-    public long ramBytesUsed() {
-      return (fst!=null) ? fst.sizeInBytes() : 0;
-    }
+            public override long Size()
+            {
+                return termCount;
+            }
 
-    @Override
-    public TermsEnum iterator(TermsEnum reuse)  {
-      if (fst != null) {
-        return new SimpleTextTermsEnum(fst, fieldInfo.getIndexOptions());
-      } else {
-        return TermsEnum.EMPTY;
-      }
-    }
+            public override long SumTotalTermFreq
+            {
+                get { return fieldInfo.FieldIndexOptions == IndexOptions.DOCS_ONLY ? - 1 : sumTotalTermFreq; }
+            }
 
-    @Override
-    public Comparator<BytesRef> getComparator() {
-      return BytesRef.getUTF8SortedAsUnicodeComparator();
-    }
+            public override long SumDocFreq
+            {
+                get { return sumDocFreq; }
+            }
 
-    @Override
-    public long size() {
-      return (long) termCount;
-    }
+            public override int DocCount
+            {
+                get { return docCount; }
+            }
 
-    @Override
-    public long getSumTotalTermFreq() {
-      return fieldInfo.getIndexOptions() == IndexOptions.DOCS_ONLY ? -1 : sumTotalTermFreq;
-    }
+            public override bool HasFreqs()
+            {
+                return fieldInfo.FieldIndexOptions >= IndexOptions.DOCS_AND_FREQS;
+            }
 
-    @Override
-    public long getSumDocFreq()  {
-      return sumDocFreq;
-    }
+            public override bool HasOffsets()
+            {
+                return
+                    fieldInfo.FieldIndexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
+            }
 
-    @Override
-    public int getDocCount()  {
-      return docCount;
-    }
+            public override bool HasPositions()
+            {
+                return fieldInfo.FieldIndexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
+            }
 
-    @Override
-    public bool hasFreqs() {
-      return fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) >= 0;
-    }
+            public override bool HasPayloads()
+            {
+                return fieldInfo.HasPayloads();
+            }
+        }
 
-    @Override
-    public bool hasOffsets() {
-      return fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
-    }
+        public override IEnumerator<string> Iterator()
+        {
+        }
 
-    @Override
-    public bool hasPositions() {
-      return fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
-    }
-    
-    @Override
-    public bool hasPayloads() {
-      return fieldInfo.hasPayloads();
-    }
-  }
-
-  @Override
-  public Iterator<String> iterator() {
-    return Collections.unmodifiableSet(fields.keySet()).iterator();
-  }
-
-  private final Map<String,SimpleTextTerms> termsCache = new HashMap<>();
-
-  @Override
-  synchronized public Terms terms(String field)  {
-    Terms terms = termsCache.get(field);
-    if (terms == null) {
-      Long fp = fields.get(field);
-      if (fp == null) {
-        return null;
-      } else {
-        terms = new SimpleTextTerms(field, fp, maxDoc);
-        termsCache.put(field, (SimpleTextTerms) terms);
-      }
-    }
-    return terms;
-  }
-
-  @Override
-  public int size() {
-    return -1;
-  }
-
-  @Override
-  public void close()  {
-    in.close();
-  }
-
-  @Override
-  public long ramBytesUsed() {
-    long sizeInBytes = 0;
-    for(SimpleTextTerms simpleTextTerms : termsCache.values()) {
-      sizeInBytes += (simpleTextTerms!=null) ? simpleTextTerms.ramBytesUsed() : 0;
+        public override Terms Terms(string field)
+        {
+            lock (this)
+            {
+                Terms terms = _termsCache[field];
+                if (terms == null)
+                {
+                    long? fp = fields[field];
+                    if (fp == null)
+                    {
+                        return null;
+                    }
+                    else
+                    {
+                        terms = new SimpleTextTerms(this, field, fp.Value, maxDoc);
+                        _termsCache[field] = (SimpleTextTerms) terms;
+                    }
+                }
+                return terms;
+            }
+        }
+
+        public override int Size()
+        {
+            return -1;
+        }
+
+        public override void Dispose()
+        {
+            _input.Dispose();
+        }
+
+        public override long RamBytesUsed()
+        {
+            return _termsCache.Values.Sum(simpleTextTerms => (simpleTextTerms != null) ? simpleTextTerms.RamBytesUsed() : 0);
+        }
+
+        public override void CheckIntegrity()
+        {
+        }
     }
-    return sizeInBytes;
-  }
 
-  @Override
-  public void checkIntegrity()  {}
-}
+}
\ No newline at end of file


Mime
View raw message