You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by pn...@apache.org on 2014/09/21 18:53:27 UTC
[1/7] git commit: Fixing Get / Set Other
Repository: lucenenet
Updated Branches:
refs/heads/master a85388772 -> cf1df6bec
Fixing Get / Set Other
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/0fffb732
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/0fffb732
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/0fffb732
Branch: refs/heads/master
Commit: 0fffb7322483fbee5896d7010050d4a224ae39b7
Parents: 6e90056
Author: Prescott Nasser <pn...@apache.org>
Authored: Sun Sep 14 17:09:43 2014 -0700
Committer: Prescott Nasser <pn...@apache.org>
Committed: Sun Sep 14 17:09:43 2014 -0700
----------------------------------------------------------------------
src/Lucene.Net.Codecs/Pulsing/PulsingPostingsReader.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/0fffb732/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsReader.cs b/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsReader.cs
index 75334e6..7ab59e9 100644
--- a/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsReader.cs
+++ b/src/Lucene.Net.Codecs/Pulsing/PulsingPostingsReader.cs
@@ -278,7 +278,7 @@ namespace Lucene.Net.Codecs.Pulsing
return null;
var atts = de.Attributes();
- return atts.AddAttribute(PulsingEnumAttribute.class).Enums().get(this);
+ return atts.AddAttribute<IPulsingEnumAttribute>().Enums()[this];
}
/// <summary>
@@ -288,7 +288,7 @@ namespace Lucene.Net.Codecs.Pulsing
private DocsEnum SetOther(DocsEnum de, DocsEnum other)
{
var atts = de.Attributes();
- return atts.AddAttribute(PulsingEnumAttribute.class).Enums().put(this, other);
+ return atts.AddAttribute<IPulsingEnumAttribute>().Enums()[this] = other;
}
///<summary>
[6/7] Cleanup of codes, mostly SimpleText in this commit
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs
index 63c3cf8..f8f9e97 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs
@@ -1,489 +1,768 @@
-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 static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.END;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.FIELD;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.LENGTH;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.MAXLENGTH;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.MINVALUE;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.NUMVALUES;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.ORDPATTERN;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.PATTERN;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.TYPE;
-
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.nio.charset.StandardCharsets;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.ParseException;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-
-import org.apache.lucene.codecs.DocValuesProducer;
-import org.apache.lucene.index.BinaryDocValues;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfo.DocValuesType;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SortedDocValues;
-import org.apache.lucene.index.SortedSetDocValues;
-import org.apache.lucene.store.BufferedChecksumIndexInput;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.StringHelper;
-
-class SimpleTextDocValuesReader extends DocValuesProducer {
-
- static class OneField {
- long dataStartFilePointer;
- String pattern;
- String ordPattern;
- int maxLength;
- bool fixedLength;
- long minValue;
- long numValues;
- }
-
- final int maxDoc;
- final IndexInput data;
- final BytesRef scratch = new BytesRef();
- final Map<String,OneField> fields = new HashMap<>();
-
- public SimpleTextDocValuesReader(SegmentReadState state, String ext) {
- // System.out.println("dir=" + state.directory + " seg=" + state.segmentInfo.name + " file=" + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext));
- data = state.directory.openInput(IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext), state.context);
- maxDoc = state.segmentInfo.getDocCount();
- while(true) {
- readLine();
- //System.out.println("READ field=" + scratch.utf8ToString());
- if (scratch.equals(END)) {
- break;
- }
- Debug.Assert( startsWith(FIELD) : scratch.utf8ToString();
- String fieldName = stripPrefix(FIELD);
- //System.out.println(" field=" + fieldName);
-
- OneField field = new OneField();
- fields.put(fieldName, field);
-
- readLine();
- Debug.Assert( startsWith(TYPE) : scratch.utf8ToString();
-
- DocValuesType dvType = DocValuesType.valueOf(stripPrefix(TYPE));
- Debug.Assert( dvType != null;
- if (dvType == DocValuesType.NUMERIC) {
- readLine();
- Debug.Assert( startsWith(MINVALUE): "got " + scratch.utf8ToString() + " field=" + fieldName + " ext=" + ext;
- field.minValue = Long.parseLong(stripPrefix(MINVALUE));
- readLine();
- Debug.Assert( startsWith(PATTERN);
- field.pattern = stripPrefix(PATTERN);
- field.dataStartFilePointer = data.getFilePointer();
- data.seek(data.getFilePointer() + (1+field.pattern.length()+2) * maxDoc);
- } else if (dvType == DocValuesType.BINARY) {
- readLine();
- Debug.Assert( startsWith(MAXLENGTH);
- field.maxLength = Integer.parseInt(stripPrefix(MAXLENGTH));
- readLine();
- Debug.Assert( startsWith(PATTERN);
- field.pattern = stripPrefix(PATTERN);
- field.dataStartFilePointer = data.getFilePointer();
- data.seek(data.getFilePointer() + (9+field.pattern.length()+field.maxLength+2) * maxDoc);
- } else if (dvType == DocValuesType.SORTED || dvType == DocValuesType.SORTED_SET) {
- readLine();
- Debug.Assert( startsWith(NUMVALUES);
- field.numValues = Long.parseLong(stripPrefix(NUMVALUES));
- readLine();
- Debug.Assert( startsWith(MAXLENGTH);
- field.maxLength = Integer.parseInt(stripPrefix(MAXLENGTH));
- readLine();
- Debug.Assert( startsWith(PATTERN);
- field.pattern = stripPrefix(PATTERN);
- readLine();
- Debug.Assert( startsWith(ORDPATTERN);
- field.ordPattern = stripPrefix(ORDPATTERN);
- field.dataStartFilePointer = data.getFilePointer();
- data.seek(data.getFilePointer() + (9+field.pattern.length()+field.maxLength) * field.numValues + (1+field.ordPattern.length())*maxDoc);
- } else {
- throw new Debug.Assert(ionError();
- }
- }
-
- // We should only be called from above if at least one
- // field has DVs:
- Debug.Assert( !fields.isEmpty();
- }
-
- @Override
- public NumericDocValues getNumeric(FieldInfo fieldInfo) {
- final OneField field = fields.get(fieldInfo.name);
- Debug.Assert( field != null;
-
- // SegmentCoreReaders already verifies this field is
- // valid:
- Debug.Assert( field != null: "field=" + fieldInfo.name + " fields=" + fields;
-
- final IndexInput in = data.clone();
- final BytesRef scratch = new BytesRef();
- final DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
-
- decoder.setParseBigDecimal(true);
-
- return new NumericDocValues() {
- @Override
- public long get(int docID) {
- try {
- //System.out.println(Thread.currentThread().getName() + ": get docID=" + docID + " in=" + in);
- if (docID < 0 || docID >= maxDoc) {
- throw new IndexOutOfBoundsException("docID must be 0 .. " + (maxDoc-1) + "; got " + docID);
- }
- in.seek(field.dataStartFilePointer + (1+field.pattern.length()+2)*docID);
- SimpleTextUtil.readLine(in, scratch);
- //System.out.println("parsing delta: " + scratch.utf8ToString());
- BigDecimal bd;
- try {
- bd = (BigDecimal) decoder.parse(scratch.utf8ToString());
- } catch (ParseException pe) {
- CorruptIndexException e = new CorruptIndexException("failed to parse BigDecimal value (resource=" + in + ")");
- e.initCause(pe);
- throw e;
- }
- SimpleTextUtil.readLine(in, scratch); // read the line telling us if its real or not
- return BigInteger.valueOf(field.minValue).add(bd.toBigIntegerExact()).longValue();
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
- };
- }
-
- private Bits getNumericDocsWithField(FieldInfo fieldInfo) {
- final OneField field = fields.get(fieldInfo.name);
- final IndexInput in = data.clone();
- final BytesRef scratch = new BytesRef();
- return new Bits() {
- @Override
- public bool get(int index) {
- try {
- in.seek(field.dataStartFilePointer + (1+field.pattern.length()+2)*index);
- SimpleTextUtil.readLine(in, scratch); // data
- SimpleTextUtil.readLine(in, scratch); // 'T' or 'F'
- return scratch.bytes[scratch.offset] == (byte) 'T';
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public int length() {
- return maxDoc;
- }
- };
- }
-
- @Override
- public BinaryDocValues getBinary(FieldInfo fieldInfo) {
- final OneField field = fields.get(fieldInfo.name);
-
- // SegmentCoreReaders already verifies this field is
- // valid:
- Debug.Assert( field != null;
-
- final IndexInput in = data.clone();
- final BytesRef scratch = new BytesRef();
- final DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
-
- return new BinaryDocValues() {
- @Override
- public void get(int docID, BytesRef result) {
- try {
- if (docID < 0 || docID >= maxDoc) {
- throw new IndexOutOfBoundsException("docID must be 0 .. " + (maxDoc-1) + "; got " + docID);
- }
- in.seek(field.dataStartFilePointer + (9+field.pattern.length() + field.maxLength+2)*docID);
- SimpleTextUtil.readLine(in, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, LENGTH);
- int len;
- try {
- len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();
- } catch (ParseException pe) {
- CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");
- e.initCause(pe);
- throw e;
- }
- result.bytes = new byte[len];
- result.offset = 0;
- result.length = len;
- in.readBytes(result.bytes, 0, len);
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
- };
- }
-
- private Bits getBinaryDocsWithField(FieldInfo fieldInfo) {
- final OneField field = fields.get(fieldInfo.name);
- final IndexInput in = data.clone();
- final BytesRef scratch = new BytesRef();
- final DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
-
- return new Bits() {
- @Override
- public bool get(int index) {
- try {
- in.seek(field.dataStartFilePointer + (9+field.pattern.length() + field.maxLength+2)*index);
- SimpleTextUtil.readLine(in, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, LENGTH);
- int len;
- try {
- len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();
- } catch (ParseException pe) {
- CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");
- e.initCause(pe);
- throw e;
- }
- // skip past bytes
- byte bytes[] = new byte[len];
- in.readBytes(bytes, 0, len);
- SimpleTextUtil.readLine(in, scratch); // newline
- SimpleTextUtil.readLine(in, scratch); // 'T' or 'F'
- return scratch.bytes[scratch.offset] == (byte) 'T';
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-
- @Override
- public int length() {
- return maxDoc;
- }
- };
- }
-
- @Override
- public SortedDocValues getSorted(FieldInfo fieldInfo) {
- final OneField field = fields.get(fieldInfo.name);
-
- // SegmentCoreReaders already verifies this field is
- // valid:
- Debug.Assert( field != null;
-
- final IndexInput in = data.clone();
- final BytesRef scratch = new BytesRef();
- final DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
- final DecimalFormat ordDecoder = new DecimalFormat(field.ordPattern, new DecimalFormatSymbols(Locale.ROOT));
-
- return new SortedDocValues() {
- @Override
- public int getOrd(int docID) {
- if (docID < 0 || docID >= maxDoc) {
- throw new IndexOutOfBoundsException("docID must be 0 .. " + (maxDoc-1) + "; got " + docID);
- }
- try {
- in.seek(field.dataStartFilePointer + field.numValues * (9 + field.pattern.length() + field.maxLength) + docID * (1 + field.ordPattern.length()));
- SimpleTextUtil.readLine(in, scratch);
- try {
- return (int) ordDecoder.parse(scratch.utf8ToString()).longValue()-1;
- } catch (ParseException pe) {
- CorruptIndexException e = new CorruptIndexException("failed to parse ord (resource=" + in + ")");
- e.initCause(pe);
- throw e;
- }
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-
- @Override
- public void lookupOrd(int ord, BytesRef result) {
- try {
- if (ord < 0 || ord >= field.numValues) {
- throw new IndexOutOfBoundsException("ord must be 0 .. " + (field.numValues-1) + "; got " + ord);
- }
- in.seek(field.dataStartFilePointer + ord * (9 + field.pattern.length() + field.maxLength));
- SimpleTextUtil.readLine(in, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, LENGTH): "got " + scratch.utf8ToString() + " in=" + in;
- int len;
- try {
- len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();
- } catch (ParseException pe) {
- CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");
- e.initCause(pe);
- throw e;
- }
- result.bytes = new byte[len];
- result.offset = 0;
- result.length = len;
- in.readBytes(result.bytes, 0, len);
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-
- @Override
- public int getValueCount() {
- return (int)field.numValues;
- }
- };
- }
-
- @Override
- public SortedSetDocValues getSortedSet(FieldInfo fieldInfo) {
- final OneField field = fields.get(fieldInfo.name);
-
- // SegmentCoreReaders already verifies this field is
- // valid:
- Debug.Assert( field != null;
-
- final IndexInput in = data.clone();
- final BytesRef scratch = new BytesRef();
- final DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
-
- return new SortedSetDocValues() {
- String[] currentOrds = new String[0];
- int currentIndex = 0;
-
- @Override
- public long nextOrd() {
- if (currentIndex == currentOrds.length) {
- return NO_MORE_ORDS;
- } else {
- return Long.parseLong(currentOrds[currentIndex++]);
- }
- }
-
- @Override
- public void setDocument(int docID) {
- if (docID < 0 || docID >= maxDoc) {
- throw new IndexOutOfBoundsException("docID must be 0 .. " + (maxDoc-1) + "; got " + docID);
- }
- try {
- in.seek(field.dataStartFilePointer + field.numValues * (9 + field.pattern.length() + field.maxLength) + docID * (1 + field.ordPattern.length()));
- SimpleTextUtil.readLine(in, scratch);
- String ordList = scratch.utf8ToString().trim();
- if (ordList.isEmpty()) {
- currentOrds = new String[0];
- } else {
- currentOrds = ordList.split(",");
- }
- currentIndex = 0;
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-
- @Override
- public void lookupOrd(long ord, BytesRef result) {
- try {
- if (ord < 0 || ord >= field.numValues) {
- throw new IndexOutOfBoundsException("ord must be 0 .. " + (field.numValues-1) + "; got " + ord);
- }
- in.seek(field.dataStartFilePointer + ord * (9 + field.pattern.length() + field.maxLength));
- SimpleTextUtil.readLine(in, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, LENGTH): "got " + scratch.utf8ToString() + " in=" + in;
- int len;
- try {
- len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();
- } catch (ParseException pe) {
- CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");
- e.initCause(pe);
- throw e;
- }
- result.bytes = new byte[len];
- result.offset = 0;
- result.length = len;
- in.readBytes(result.bytes, 0, len);
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-
- @Override
- public long getValueCount() {
- return field.numValues;
- }
- };
- }
-
- @Override
- public Bits getDocsWithField(FieldInfo field) {
- switch (field.getDocValuesType()) {
- case SORTED_SET:
- return DocValues.docsWithValue(getSortedSet(field), maxDoc);
- case SORTED:
- return DocValues.docsWithValue(getSorted(field), maxDoc);
- case BINARY:
- return getBinaryDocsWithField(field);
- case NUMERIC:
- return getNumericDocsWithField(field);
- default:
- throw new Debug.Assert(ionError();
- }
- }
-
- @Override
- public void close() {
- data.close();
- }
-
- /** Used only in ctor: */
- private void readLine() {
- SimpleTextUtil.readLine(data, scratch);
- //System.out.println("line: " + scratch.utf8ToString());
- }
-
- /** Used only in ctor: */
- private bool startsWith(BytesRef prefix) {
- return StringHelper.startsWith(scratch, prefix);
- }
-
- /** Used only in ctor: */
- private String stripPrefix(BytesRef prefix) {
- return new String(scratch.bytes, scratch.offset + prefix.length, scratch.length - prefix.length, StandardCharsets.UTF_8);
- }
-
- @Override
- public long ramBytesUsed() {
- return 0;
- }
-
- @Override
- public void checkIntegrity() {
- BytesRef scratch = new BytesRef();
- IndexInput clone = data.clone();
- clone.seek(0);
- ChecksumIndexInput input = new BufferedChecksumIndexInput(clone);
- while(true) {
- SimpleTextUtil.readLine(input, scratch);
- if (scratch.equals(END)) {
- SimpleTextUtil.checkFooter(input);
- break;
- }
- }
- }
-}
+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.
+ */
+
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesWriter.END;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesWriter.FIELD;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesWriter.LENGTH;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesWriter.MAXLENGTH;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesWriter.MINVALUE;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesWriter.NUMVALUES;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesWriter.ORDPATTERN;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesWriter.PATTERN;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesWriter.TYPE;
+
+
+ using BinaryDocValues = Index.BinaryDocValues;
+ using CorruptIndexException = Index.CorruptIndexException;
+ using DocValues = Index.DocValues;
+ using FieldInfo = Index.FieldInfo;
+ using DocValuesType = Index.FieldInfo.DocValuesType;
+ using IndexFileNames = Index.IndexFileNames;
+ using NumericDocValues = Index.NumericDocValues;
+ using SegmentReadState = Index.SegmentReadState;
+ using SortedDocValues = Index.SortedDocValues;
+ using SortedSetDocValues = Index.SortedSetDocValues;
+ using BufferedChecksumIndexInput = Store.BufferedChecksumIndexInput;
+ using ChecksumIndexInput = Store.ChecksumIndexInput;
+ using IndexInput = Store.IndexInput;
+ using Bits = Util.Bits;
+ using BytesRef = Util.BytesRef;
+ using StringHelper = Util.StringHelper;
+
+ public class SimpleTextDocValuesReader : DocValuesProducer
+ {
+
+ internal class OneField
+ {
+ internal long dataStartFilePointer;
+ internal string pattern;
+ internal string ordPattern;
+ internal int maxLength;
+ internal bool fixedLength;
+ internal long minValue;
+ internal long numValues;
+ }
+
+ internal readonly int maxDoc;
+ internal readonly IndexInput data;
+ internal readonly BytesRef scratch = new BytesRef();
+ internal readonly IDictionary<string, OneField> fields = new Dictionary<string, OneField>();
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: public SimpleTextDocValuesReader(index.SegmentReadState state, String ext) throws java.io.IOException
+ public SimpleTextDocValuesReader(SegmentReadState state, string ext)
+ {
+ // System.out.println("dir=" + state.directory + " seg=" + state.segmentInfo.name + " file=" + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext));
+ data = state.directory.openInput(IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext), state.context);
+ maxDoc = state.segmentInfo.DocCount;
+ while (true)
+ {
+ readLine();
+ //System.out.println("READ field=" + scratch.utf8ToString());
+ if (scratch.Equals(END))
+ {
+ break;
+ }
+ Debug.Assert(startsWith(FIELD), scratch.utf8ToString());
+ string fieldName = stripPrefix(FIELD);
+ //System.out.println(" field=" + fieldName);
+
+ OneField field = new OneField();
+ fields[fieldName] = field;
+
+ readLine();
+ Debug.Assert(startsWith(TYPE), scratch.utf8ToString());
+
+ FieldInfo.DocValuesType dvType = FieldInfo.DocValuesType.valueOf(stripPrefix(TYPE));
+ Debug.Assert(dvType != null);
+ if (dvType == FieldInfo.DocValuesType.NUMERIC)
+ {
+ readLine();
+ Debug.Assert(startsWith(MINVALUE), "got " + scratch.utf8ToString() + " field=" + fieldName + " ext=" + ext);
+ field.minValue = Convert.ToInt64(stripPrefix(MINVALUE));
+ readLine();
+ Debug.Assert(startsWith(PATTERN));
+ field.pattern = stripPrefix(PATTERN);
+ field.dataStartFilePointer = data.FilePointer;
+ data.seek(data.FilePointer + (1 + field.pattern.Length + 2) * maxDoc);
+ }
+ else if (dvType == FieldInfo.DocValuesType.BINARY)
+ {
+ readLine();
+ Debug.Assert(startsWith(MAXLENGTH));
+ field.maxLength = Convert.ToInt32(stripPrefix(MAXLENGTH));
+ readLine();
+ Debug.Assert(startsWith(PATTERN));
+ field.pattern = stripPrefix(PATTERN);
+ field.dataStartFilePointer = data.FilePointer;
+ data.seek(data.FilePointer + (9 + field.pattern.Length + field.maxLength + 2) * maxDoc);
+ }
+ else if (dvType == FieldInfo.DocValuesType.SORTED || dvType == FieldInfo.DocValuesType.SORTED_SET)
+ {
+ readLine();
+ Debug.Assert(startsWith(NUMVALUES));
+ field.numValues = Convert.ToInt64(stripPrefix(NUMVALUES));
+ readLine();
+ Debug.Assert(startsWith(MAXLENGTH));
+ field.maxLength = Convert.ToInt32(stripPrefix(MAXLENGTH));
+ readLine();
+ Debug.Assert(startsWith(PATTERN));
+ field.pattern = stripPrefix(PATTERN);
+ readLine();
+ Debug.Assert(startsWith(ORDPATTERN));
+ field.ordPattern = stripPrefix(ORDPATTERN);
+ field.dataStartFilePointer = data.FilePointer;
+ data.seek(data.FilePointer + (9 + field.pattern.Length + field.maxLength) * field.numValues + (1 + field.ordPattern.Length) * maxDoc);
+ }
+ else
+ {
+ throw new AssertionError();
+ }
+ }
+
+ // We should only be called from above if at least one
+ // field has DVs:
+ Debug.Assert(fields.Count > 0);
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public index.NumericDocValues getNumeric(index.FieldInfo fieldInfo) throws java.io.IOException
+ public override NumericDocValues getNumeric(FieldInfo fieldInfo)
+ {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final OneField field = fields.get(fieldInfo.name);
+ OneField field = fields[fieldInfo.name];
+ Debug.Assert(field != null);
+
+ // SegmentCoreReaders already verifies this field is
+ // valid:
+ Debug.Assert(field != null, "field=" + fieldInfo.name + " fields=" + fields);
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final store.IndexInput in = data.clone();
+ IndexInput @in = data.clone();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final util.BytesRef scratch = new util.BytesRef();
+ BytesRef scratch = new BytesRef();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat decoder = new java.text.DecimalFormat(field.pattern, new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
+
+ decoder.ParseBigDecimal = true;
+
+ return new NumericDocValuesAnonymousInnerClassHelper(this, field, @in, scratch, decoder);
+ }
+
+ private class NumericDocValuesAnonymousInnerClassHelper : NumericDocValues
+ {
+ private readonly SimpleTextDocValuesReader outerInstance;
+
+ private Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field;
+ private IndexInput @in;
+ private BytesRef scratch;
+ private DecimalFormat decoder;
+
+ public NumericDocValuesAnonymousInnerClassHelper(SimpleTextDocValuesReader outerInstance, Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field, IndexInput @in, BytesRef scratch, DecimalFormat decoder)
+ {
+ this.outerInstance = outerInstance;
+ this.field = field;
+ this.@in = @in;
+ this.scratch = scratch;
+ this.decoder = decoder;
+ }
+
+ public override long get(int docID)
+ {
+ try
+ {
+ //System.out.println(Thread.currentThread().getName() + ": get docID=" + docID + " in=" + in);
+ if (docID < 0 || docID >= outerInstance.maxDoc)
+ {
+ throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + docID);
+ }
+ @in.seek(field.dataStartFilePointer + (1 + field.pattern.Length + 2) * docID);
+ SimpleTextUtil.ReadLine(@in, scratch);
+ //System.out.println("parsing delta: " + scratch.utf8ToString());
+ decimal bd;
+ try
+ {
+ bd = (decimal) decoder.parse(scratch.utf8ToString());
+ }
+ catch (ParseException pe)
+ {
+ CorruptIndexException e = new CorruptIndexException("failed to parse BigDecimal value (resource=" + @in + ")");
+ e.initCause(pe);
+ throw e;
+ }
+ SimpleTextUtil.ReadLine(@in, scratch); // read the line telling us if its real or not
+ return System.Numerics.BigInteger.valueOf(field.minValue) + (long)bd.toBigIntegerExact();
+ }
+ catch (IOException ioe)
+ {
+ throw new Exception(ioe);
+ }
+ }
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private util.Bits getNumericDocsWithField(index.FieldInfo fieldInfo) throws java.io.IOException
+ private Bits getNumericDocsWithField(FieldInfo fieldInfo)
+ {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final OneField field = fields.get(fieldInfo.name);
+ OneField field = fields[fieldInfo.name];
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final store.IndexInput in = data.clone();
+ IndexInput @in = data.clone();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final util.BytesRef scratch = new util.BytesRef();
+ BytesRef scratch = new BytesRef();
+ return new BitsAnonymousInnerClassHelper(this, field, @in, scratch);
+ }
+
+ private class BitsAnonymousInnerClassHelper : Bits
+ {
+ private readonly SimpleTextDocValuesReader outerInstance;
+
+ private Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field;
+ private IndexInput @in;
+ private BytesRef scratch;
+
+ public BitsAnonymousInnerClassHelper(SimpleTextDocValuesReader outerInstance, Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field, IndexInput @in, BytesRef scratch)
+ {
+ this.outerInstance = outerInstance;
+ this.field = field;
+ this.@in = @in;
+ this.scratch = scratch;
+ }
+
+ public override bool get(int index)
+ {
+ try
+ {
+ @in.seek(field.dataStartFilePointer + (1 + field.pattern.Length + 2) * index);
+ SimpleTextUtil.ReadLine(@in, scratch); // data
+ SimpleTextUtil.ReadLine(@in, scratch); // 'T' or 'F'
+ return scratch.bytes[scratch.offset] == (sbyte) 'T';
+ }
+ catch (IOException e)
+ {
+ throw new Exception(e);
+ }
+ }
+
+ public override int length()
+ {
+ return outerInstance.maxDoc;
+ }
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public index.BinaryDocValues getBinary(index.FieldInfo fieldInfo) throws java.io.IOException
+ public override BinaryDocValues getBinary(FieldInfo fieldInfo)
+ {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final OneField field = fields.get(fieldInfo.name);
+ OneField field = fields[fieldInfo.name];
+
+ // SegmentCoreReaders already verifies this field is
+ // valid:
+ Debug.Assert(field != null);
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final store.IndexInput in = data.clone();
+ IndexInput @in = data.clone();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final util.BytesRef scratch = new util.BytesRef();
+ BytesRef scratch = new BytesRef();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat decoder = new java.text.DecimalFormat(field.pattern, new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
+
+ return new BinaryDocValuesAnonymousInnerClassHelper(this, field, @in, scratch, decoder);
+ }
+
+ private class BinaryDocValuesAnonymousInnerClassHelper : BinaryDocValues
+ {
+ private readonly SimpleTextDocValuesReader outerInstance;
+
+ private Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field;
+ private IndexInput @in;
+ private BytesRef scratch;
+ private DecimalFormat decoder;
+
+ public BinaryDocValuesAnonymousInnerClassHelper(SimpleTextDocValuesReader outerInstance, Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field, IndexInput @in, BytesRef scratch, DecimalFormat decoder)
+ {
+ this.outerInstance = outerInstance;
+ this.field = field;
+ this.@in = @in;
+ this.scratch = scratch;
+ this.decoder = decoder;
+ }
+
+ public override void get(int docID, BytesRef result)
+ {
+ try
+ {
+ if (docID < 0 || docID >= outerInstance.maxDoc)
+ {
+ throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + docID);
+ }
+ @in.seek(field.dataStartFilePointer + (9 + field.pattern.Length + field.maxLength + 2) * docID);
+ SimpleTextUtil.ReadLine(@in, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, LENGTH));
+ int len;
+ try
+ {
+ len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8));
+ }
+ catch (ParseException pe)
+ {
+ CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")");
+ e.initCause(pe);
+ throw e;
+ }
+ result.bytes = new sbyte[len];
+ result.offset = 0;
+ result.length = len;
+ @in.readBytes(result.bytes, 0, len);
+ }
+ catch (IOException ioe)
+ {
+ throw new Exception(ioe);
+ }
+ }
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private util.Bits getBinaryDocsWithField(index.FieldInfo fieldInfo) throws java.io.IOException
+ private Bits getBinaryDocsWithField(FieldInfo fieldInfo)
+ {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final OneField field = fields.get(fieldInfo.name);
+ OneField field = fields[fieldInfo.name];
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final store.IndexInput in = data.clone();
+ IndexInput @in = data.clone();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final util.BytesRef scratch = new util.BytesRef();
+ BytesRef scratch = new BytesRef();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat decoder = new java.text.DecimalFormat(field.pattern, new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
+
+ return new BitsAnonymousInnerClassHelper2(this, field, @in, scratch, decoder);
+ }
+
+ private class BitsAnonymousInnerClassHelper2 : Bits
+ {
+ private readonly SimpleTextDocValuesReader outerInstance;
+
+ private Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field;
+ private IndexInput @in;
+ private BytesRef scratch;
+ private DecimalFormat decoder;
+
+ public BitsAnonymousInnerClassHelper2(SimpleTextDocValuesReader outerInstance, Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field, IndexInput @in, BytesRef scratch, DecimalFormat decoder)
+ {
+ this.outerInstance = outerInstance;
+ this.field = field;
+ this.@in = @in;
+ this.scratch = scratch;
+ this.decoder = decoder;
+ }
+
+ public override bool get(int index)
+ {
+ try
+ {
+ @in.seek(field.dataStartFilePointer + (9 + field.pattern.Length + field.maxLength + 2) * index);
+ SimpleTextUtil.ReadLine(@in, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, LENGTH));
+ int len;
+ try
+ {
+ len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8));
+ }
+ catch (ParseException pe)
+ {
+ CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")");
+ e.initCause(pe);
+ throw e;
+ }
+ // skip past bytes
+ sbyte[] bytes = new sbyte[len];
+ @in.readBytes(bytes, 0, len);
+ SimpleTextUtil.ReadLine(@in, scratch); // newline
+ SimpleTextUtil.ReadLine(@in, scratch); // 'T' or 'F'
+ return scratch.bytes[scratch.offset] == (sbyte) 'T';
+ }
+ catch (IOException ioe)
+ {
+ throw new Exception(ioe);
+ }
+ }
+
+ public override int length()
+ {
+ return outerInstance.maxDoc;
+ }
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public index.SortedDocValues getSorted(index.FieldInfo fieldInfo) throws java.io.IOException
+ public override SortedDocValues getSorted(FieldInfo fieldInfo)
+ {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final OneField field = fields.get(fieldInfo.name);
+ OneField field = fields[fieldInfo.name];
+
+ // SegmentCoreReaders already verifies this field is
+ // valid:
+ Debug.Assert(field != null);
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final store.IndexInput in = data.clone();
+ IndexInput @in = data.clone();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final util.BytesRef scratch = new util.BytesRef();
+ BytesRef scratch = new BytesRef();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat decoder = new java.text.DecimalFormat(field.pattern, new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat ordDecoder = new java.text.DecimalFormat(field.ordPattern, new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat ordDecoder = new DecimalFormat(field.ordPattern, new DecimalFormatSymbols(Locale.ROOT));
+
+ return new SortedDocValuesAnonymousInnerClassHelper(this, field, @in, scratch, decoder, ordDecoder);
+ }
+
+ private class SortedDocValuesAnonymousInnerClassHelper : SortedDocValues
+ {
+ private readonly SimpleTextDocValuesReader outerInstance;
+
+ private Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field;
+ private IndexInput @in;
+ private BytesRef scratch;
+ private DecimalFormat decoder;
+ private DecimalFormat ordDecoder;
+
+ public SortedDocValuesAnonymousInnerClassHelper(SimpleTextDocValuesReader outerInstance, Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field, IndexInput @in, BytesRef scratch, DecimalFormat decoder, DecimalFormat ordDecoder)
+ {
+ this.outerInstance = outerInstance;
+ this.field = field;
+ this.@in = @in;
+ this.scratch = scratch;
+ this.decoder = decoder;
+ this.ordDecoder = ordDecoder;
+ }
+
+ public override int getOrd(int docID)
+ {
+ if (docID < 0 || docID >= outerInstance.maxDoc)
+ {
+ throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + docID);
+ }
+ try
+ {
+ @in.seek(field.dataStartFilePointer + field.numValues * (9 + field.pattern.Length + field.maxLength) + docID * (1 + field.ordPattern.Length));
+ SimpleTextUtil.ReadLine(@in, scratch);
+ try
+ {
+ return (long)(int) ordDecoder.parse(scratch.utf8ToString()) - 1;
+ }
+ catch (ParseException pe)
+ {
+ CorruptIndexException e = new CorruptIndexException("failed to parse ord (resource=" + @in + ")");
+ e.initCause(pe);
+ throw e;
+ }
+ }
+ catch (IOException ioe)
+ {
+ throw new Exception(ioe);
+ }
+ }
+
+ public override void lookupOrd(int ord, BytesRef result)
+ {
+ try
+ {
+ if (ord < 0 || ord >= field.numValues)
+ {
+ throw new System.IndexOutOfRangeException("ord must be 0 .. " + (field.numValues - 1) + "; got " + ord);
+ }
+ @in.seek(field.dataStartFilePointer + ord * (9 + field.pattern.Length + field.maxLength));
+ SimpleTextUtil.ReadLine(@in, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, LENGTH), "got " + scratch.utf8ToString() + " in=" + @in);
+ int len;
+ try
+ {
+ len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8));
+ }
+ catch (ParseException pe)
+ {
+ CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")");
+ e.initCause(pe);
+ throw e;
+ }
+ result.bytes = new sbyte[len];
+ result.offset = 0;
+ result.length = len;
+ @in.readBytes(result.bytes, 0, len);
+ }
+ catch (IOException ioe)
+ {
+ throw new Exception(ioe);
+ }
+ }
+
+ public override int ValueCount
+ {
+ get
+ {
+ return (int)field.numValues;
+ }
+ }
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public index.SortedSetDocValues getSortedSet(index.FieldInfo fieldInfo) throws java.io.IOException
+ public override SortedSetDocValues getSortedSet(FieldInfo fieldInfo)
+ {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final OneField field = fields.get(fieldInfo.name);
+ OneField field = fields[fieldInfo.name];
+
+ // SegmentCoreReaders already verifies this field is
+ // valid:
+ Debug.Assert(field != null);
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final store.IndexInput in = data.clone();
+ IndexInput @in = data.clone();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final util.BytesRef scratch = new util.BytesRef();
+ BytesRef scratch = new BytesRef();
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat decoder = new java.text.DecimalFormat(field.pattern, new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
+
+ return new SortedSetDocValuesAnonymousInnerClassHelper(this, field, @in, scratch, decoder);
+ }
+
+ private class SortedSetDocValuesAnonymousInnerClassHelper : SortedSetDocValues
+ {
+ private readonly SimpleTextDocValuesReader outerInstance;
+
+ private Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field;
+ private IndexInput @in;
+ private BytesRef scratch;
+ private DecimalFormat decoder;
+
+ public SortedSetDocValuesAnonymousInnerClassHelper(SimpleTextDocValuesReader outerInstance, Lucene.Net.Codecs.SimpleText.SimpleTextDocValuesReader.OneField field, IndexInput @in, BytesRef scratch, DecimalFormat decoder)
+ {
+ this.outerInstance = outerInstance;
+ this.field = field;
+ this.@in = @in;
+ this.scratch = scratch;
+ this.decoder = decoder;
+ currentOrds = new string[0];
+ currentIndex = 0;
+ }
+
+ internal string[] currentOrds;
+ internal int currentIndex;
+
+ public override long nextOrd()
+ {
+ if (currentIndex == currentOrds.length)
+ {
+ return NO_MORE_ORDS;
+ }
+ else
+ {
+ return Convert.ToInt64(currentOrds[currentIndex++]);
+ }
+ }
+
+ public override int Document
+ {
+ set
+ {
+ if (value < 0 || value >= outerInstance.maxDoc)
+ {
+ throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + value);
+ }
+ try
+ {
+ @in.seek(field.dataStartFilePointer + field.numValues * (9 + field.pattern.Length + field.maxLength) + value * (1 + field.ordPattern.Length));
+ SimpleTextUtil.ReadLine(@in, scratch);
+ string ordList = scratch.utf8ToString().Trim();
+ if (ordList.Length == 0)
+ {
+ currentOrds = new string[0];
+ }
+ else
+ {
+ currentOrds = ordList.Split(",", true);
+ }
+ currentIndex = 0;
+ }
+ catch (IOException ioe)
+ {
+ throw new Exception(ioe);
+ }
+ }
+ }
+
+ public override void lookupOrd(long ord, BytesRef result)
+ {
+ try
+ {
+ if (ord < 0 || ord >= field.numValues)
+ {
+ throw new System.IndexOutOfRangeException("ord must be 0 .. " + (field.numValues - 1) + "; got " + ord);
+ }
+ @in.seek(field.dataStartFilePointer + ord * (9 + field.pattern.Length + field.maxLength));
+ SimpleTextUtil.ReadLine(@in, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, LENGTH), "got " + scratch.utf8ToString() + " in=" + @in);
+ int len;
+ try
+ {
+ len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8));
+ }
+ catch (ParseException pe)
+ {
+ CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")");
+ e.initCause(pe);
+ throw e;
+ }
+ result.bytes = new sbyte[len];
+ result.offset = 0;
+ result.length = len;
+ @in.readBytes(result.bytes, 0, len);
+ }
+ catch (IOException ioe)
+ {
+ throw new Exception(ioe);
+ }
+ }
+
+ public override long ValueCount
+ {
+ get
+ {
+ return field.numValues;
+ }
+ }
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public util.Bits getDocsWithField(index.FieldInfo field) throws java.io.IOException
+ public override Bits getDocsWithField(FieldInfo field)
+ {
+ switch (field.DocValuesType)
+ {
+ case SORTED_SET:
+ return DocValues.docsWithValue(getSortedSet(field), maxDoc);
+ case SORTED:
+ return DocValues.docsWithValue(getSorted(field), maxDoc);
+ case BINARY:
+ return getBinaryDocsWithField(field);
+ case NUMERIC:
+ return getNumericDocsWithField(field);
+ default:
+ throw new AssertionError();
+ }
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void close() throws java.io.IOException
+ public override void close()
+ {
+ data.close();
+ }
+
+ /// <summary>
+ /// Used only in ctor: </summary>
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void readLine() throws java.io.IOException
+ private void readLine()
+ {
+ SimpleTextUtil.ReadLine(data, scratch);
+ //System.out.println("line: " + scratch.utf8ToString());
+ }
+
+ /// <summary>
+ /// Used only in ctor: </summary>
+ private bool StartsWith(BytesRef prefix)
+ {
+ return StringHelper.StartsWith(scratch, prefix);
+ }
+
+ /// <summary>
+ /// Used only in ctor: </summary>
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private String stripPrefix(util.BytesRef prefix) throws java.io.IOException
+ private string stripPrefix(BytesRef prefix)
+ {
+ return new string(scratch.bytes, scratch.offset + prefix.length, scratch.length - prefix.length, StandardCharsets.UTF_8);
+ }
+
+ public override long ramBytesUsed()
+ {
+ return 0;
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void checkIntegrity() throws java.io.IOException
+ public override void checkIntegrity()
+ {
+ BytesRef scratch = new BytesRef();
+ IndexInput clone = data.clone();
+ clone.seek(0);
+ ChecksumIndexInput input = new BufferedChecksumIndexInput(clone);
+ while (true)
+ {
+ SimpleTextUtil.ReadLine(input, scratch);
+ if (scratch.Equals(END))
+ {
+ SimpleTextUtil.CheckFooter(input);
+ break;
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
index 6f89c10..1afcd00 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
@@ -1,411 +1,485 @@
-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.math.BigInteger;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Set;
-
-import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.index.FieldInfo.DocValuesType;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
-
-class SimpleTextDocValuesWriter extends DocValuesConsumer {
- final static BytesRef END = new BytesRef("END");
- final static BytesRef FIELD = new BytesRef("field ");
- final static BytesRef TYPE = new BytesRef(" type ");
- // used for numerics
- final static BytesRef MINVALUE = new BytesRef(" minvalue ");
- final static BytesRef PATTERN = new BytesRef(" pattern ");
- // used for bytes
- final static BytesRef LENGTH = new BytesRef("length ");
- final static BytesRef MAXLENGTH = new BytesRef(" maxlength ");
- // used for sorted bytes
- final static BytesRef NUMVALUES = new BytesRef(" numvalues ");
- final static BytesRef ORDPATTERN = new BytesRef(" ordpattern ");
-
- IndexOutput data;
- final BytesRef scratch = new BytesRef();
- final int numDocs;
- private final Set<String> fieldsSeen = new HashSet<>(); // for Debug.Assert(ing
-
- public SimpleTextDocValuesWriter(SegmentWriteState state, String ext) {
- // System.out.println("WRITE: " + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext) + " " + state.segmentInfo.getDocCount() + " docs");
- data = state.directory.createOutput(IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext), state.context);
- numDocs = state.segmentInfo.getDocCount();
- }
-
- // for Debug.Assert(ing
- private bool fieldSeen(String field) {
- Debug.Assert( !fieldsSeen.contains(field): "field \"" + field + "\" was added more than once during flush";
- fieldsSeen.add(field);
- return true;
- }
-
- @Override
- public void addNumericField(FieldInfo field, Iterable<Number> values) {
- Debug.Assert( fieldSeen(field.name);
- Debug.Assert( (field.getDocValuesType() == FieldInfo.DocValuesType.NUMERIC ||
- field.getNormType() == FieldInfo.DocValuesType.NUMERIC);
- writeFieldEntry(field, FieldInfo.DocValuesType.NUMERIC);
-
- // first pass to find min/max
- long minValue = Long.MAX_VALUE;
- long maxValue = Long.MIN_VALUE;
- for(Number n : values) {
- long v = n == null ? 0 : n.longValue();
- minValue = Math.min(minValue, v);
- maxValue = Math.max(maxValue, v);
- }
-
- // write our minimum value to the .dat, all entries are deltas from that
- SimpleTextUtil.write(data, MINVALUE);
- SimpleTextUtil.write(data, Long.toString(minValue), scratch);
- SimpleTextUtil.writeNewline(data);
-
- // build up our fixed-width "simple text packed ints"
- // format
- BigInteger maxBig = BigInteger.valueOf(maxValue);
- BigInteger minBig = BigInteger.valueOf(minValue);
- BigInteger diffBig = maxBig.subtract(minBig);
- int maxBytesPerValue = diffBig.toString().length();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < maxBytesPerValue; i++) {
- sb.append('0');
- }
-
- // write our pattern to the .dat
- SimpleTextUtil.write(data, PATTERN);
- SimpleTextUtil.write(data, sb.toString(), scratch);
- SimpleTextUtil.writeNewline(data);
-
- final String patternString = sb.toString();
-
- final DecimalFormat encoder = new DecimalFormat(patternString, new DecimalFormatSymbols(Locale.ROOT));
-
- int numDocsWritten = 0;
-
- // second pass to write the values
- for(Number n : values) {
- long value = n == null ? 0 : n.longValue();
- Debug.Assert( value >= minValue;
- Number delta = BigInteger.valueOf(value).subtract(BigInteger.valueOf(minValue));
- String s = encoder.format(delta);
- Debug.Assert( s.length() == patternString.length();
- SimpleTextUtil.write(data, s, scratch);
- SimpleTextUtil.writeNewline(data);
- if (n == null) {
- SimpleTextUtil.write(data, "F", scratch);
- } else {
- SimpleTextUtil.write(data, "T", scratch);
- }
- SimpleTextUtil.writeNewline(data);
- numDocsWritten++;
- Debug.Assert( numDocsWritten <= numDocs;
- }
-
- Debug.Assert( numDocs == numDocsWritten: "numDocs=" + numDocs + " numDocsWritten=" + numDocsWritten;
- }
-
- @Override
- public void addBinaryField(FieldInfo field, Iterable<BytesRef> values) {
- Debug.Assert( fieldSeen(field.name);
- Debug.Assert( field.getDocValuesType() == DocValuesType.BINARY;
- int maxLength = 0;
- for(BytesRef value : values) {
- final int length = value == null ? 0 : value.length;
- maxLength = Math.max(maxLength, length);
- }
- writeFieldEntry(field, FieldInfo.DocValuesType.BINARY);
-
- // write maxLength
- SimpleTextUtil.write(data, MAXLENGTH);
- SimpleTextUtil.write(data, Integer.toString(maxLength), scratch);
- SimpleTextUtil.writeNewline(data);
-
- int maxBytesLength = Long.toString(maxLength).length();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < maxBytesLength; i++) {
- sb.append('0');
- }
- // write our pattern for encoding lengths
- SimpleTextUtil.write(data, PATTERN);
- SimpleTextUtil.write(data, sb.toString(), scratch);
- SimpleTextUtil.writeNewline(data);
- final DecimalFormat encoder = new DecimalFormat(sb.toString(), new DecimalFormatSymbols(Locale.ROOT));
-
- int numDocsWritten = 0;
- for(BytesRef value : values) {
- // write length
- final int length = value == null ? 0 : value.length;
- SimpleTextUtil.write(data, LENGTH);
- SimpleTextUtil.write(data, encoder.format(length), scratch);
- SimpleTextUtil.writeNewline(data);
-
- // write bytes -- don't use SimpleText.write
- // because it escapes:
- if (value != null) {
- data.writeBytes(value.bytes, value.offset, value.length);
- }
-
- // pad to fit
- for (int i = length; i < maxLength; i++) {
- data.writeByte((byte)' ');
- }
- SimpleTextUtil.writeNewline(data);
- if (value == null) {
- SimpleTextUtil.write(data, "F", scratch);
- } else {
- SimpleTextUtil.write(data, "T", scratch);
- }
- SimpleTextUtil.writeNewline(data);
- numDocsWritten++;
- }
-
- Debug.Assert( numDocs == numDocsWritten;
- }
-
- @Override
- public void addSortedField(FieldInfo field, Iterable<BytesRef> values, Iterable<Number> docToOrd) {
- Debug.Assert( fieldSeen(field.name);
- Debug.Assert( field.getDocValuesType() == DocValuesType.SORTED;
- writeFieldEntry(field, FieldInfo.DocValuesType.SORTED);
-
- int valueCount = 0;
- int maxLength = -1;
- for(BytesRef value : values) {
- maxLength = Math.max(maxLength, value.length);
- valueCount++;
- }
-
- // write numValues
- SimpleTextUtil.write(data, NUMVALUES);
- SimpleTextUtil.write(data, Integer.toString(valueCount), scratch);
- SimpleTextUtil.writeNewline(data);
-
- // write maxLength
- SimpleTextUtil.write(data, MAXLENGTH);
- SimpleTextUtil.write(data, Integer.toString(maxLength), scratch);
- SimpleTextUtil.writeNewline(data);
-
- int maxBytesLength = Integer.toString(maxLength).length();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < maxBytesLength; i++) {
- sb.append('0');
- }
-
- // write our pattern for encoding lengths
- SimpleTextUtil.write(data, PATTERN);
- SimpleTextUtil.write(data, sb.toString(), scratch);
- SimpleTextUtil.writeNewline(data);
- final DecimalFormat encoder = new DecimalFormat(sb.toString(), new DecimalFormatSymbols(Locale.ROOT));
-
- int maxOrdBytes = Long.toString(valueCount+1L).length();
- sb.setLength(0);
- for (int i = 0; i < maxOrdBytes; i++) {
- sb.append('0');
- }
-
- // write our pattern for ords
- SimpleTextUtil.write(data, ORDPATTERN);
- SimpleTextUtil.write(data, sb.toString(), scratch);
- SimpleTextUtil.writeNewline(data);
- final DecimalFormat ordEncoder = new DecimalFormat(sb.toString(), new DecimalFormatSymbols(Locale.ROOT));
-
- // for Debug.Assert(s:
- int valuesSeen = 0;
-
- for(BytesRef value : values) {
- // write length
- SimpleTextUtil.write(data, LENGTH);
- SimpleTextUtil.write(data, encoder.format(value.length), scratch);
- SimpleTextUtil.writeNewline(data);
-
- // write bytes -- don't use SimpleText.write
- // because it escapes:
- data.writeBytes(value.bytes, value.offset, value.length);
-
- // pad to fit
- for (int i = value.length; i < maxLength; i++) {
- data.writeByte((byte)' ');
- }
- SimpleTextUtil.writeNewline(data);
- valuesSeen++;
- Debug.Assert( valuesSeen <= valueCount;
- }
-
- Debug.Assert( valuesSeen == valueCount;
-
- for(Number ord : docToOrd) {
- SimpleTextUtil.write(data, ordEncoder.format(ord.longValue()+1), scratch);
- SimpleTextUtil.writeNewline(data);
- }
- }
-
- @Override
- public void addSortedSetField(FieldInfo field, Iterable<BytesRef> values, Iterable<Number> docToOrdCount, Iterable<Number> ords) {
- Debug.Assert( fieldSeen(field.name);
- Debug.Assert( field.getDocValuesType() == DocValuesType.SORTED_SET;
- writeFieldEntry(field, FieldInfo.DocValuesType.SORTED_SET);
-
- long valueCount = 0;
- int maxLength = 0;
- for(BytesRef value : values) {
- maxLength = Math.max(maxLength, value.length);
- valueCount++;
- }
-
- // write numValues
- SimpleTextUtil.write(data, NUMVALUES);
- SimpleTextUtil.write(data, Long.toString(valueCount), scratch);
- SimpleTextUtil.writeNewline(data);
-
- // write maxLength
- SimpleTextUtil.write(data, MAXLENGTH);
- SimpleTextUtil.write(data, Integer.toString(maxLength), scratch);
- SimpleTextUtil.writeNewline(data);
-
- int maxBytesLength = Integer.toString(maxLength).length();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < maxBytesLength; i++) {
- sb.append('0');
- }
-
- // write our pattern for encoding lengths
- SimpleTextUtil.write(data, PATTERN);
- SimpleTextUtil.write(data, sb.toString(), scratch);
- SimpleTextUtil.writeNewline(data);
- final DecimalFormat encoder = new DecimalFormat(sb.toString(), new DecimalFormatSymbols(Locale.ROOT));
-
- // compute ord pattern: this is funny, we encode all values for all docs to find the maximum length
- int maxOrdListLength = 0;
- StringBuilder sb2 = new StringBuilder();
- Iterator<Number> ordStream = ords.iterator();
- for (Number n : docToOrdCount) {
- sb2.setLength(0);
- int count = n.intValue();
- for (int i = 0; i < count; i++) {
- long ord = ordStream.next().longValue();
- if (sb2.length() > 0) {
- sb2.append(",");
- }
- sb2.append(Long.toString(ord));
- }
- maxOrdListLength = Math.max(maxOrdListLength, sb2.length());
- }
-
- sb2.setLength(0);
- for (int i = 0; i < maxOrdListLength; i++) {
- sb2.append('X');
- }
-
- // write our pattern for ord lists
- SimpleTextUtil.write(data, ORDPATTERN);
- SimpleTextUtil.write(data, sb2.toString(), scratch);
- SimpleTextUtil.writeNewline(data);
-
- // for Debug.Assert(s:
- long valuesSeen = 0;
-
- for(BytesRef value : values) {
- // write length
- SimpleTextUtil.write(data, LENGTH);
- SimpleTextUtil.write(data, encoder.format(value.length), scratch);
- SimpleTextUtil.writeNewline(data);
-
- // write bytes -- don't use SimpleText.write
- // because it escapes:
- data.writeBytes(value.bytes, value.offset, value.length);
-
- // pad to fit
- for (int i = value.length; i < maxLength; i++) {
- data.writeByte((byte)' ');
- }
- SimpleTextUtil.writeNewline(data);
- valuesSeen++;
- Debug.Assert( valuesSeen <= valueCount;
- }
-
- Debug.Assert( valuesSeen == valueCount;
-
- ordStream = ords.iterator();
-
- // write the ords for each doc comma-separated
- for(Number n : docToOrdCount) {
- sb2.setLength(0);
- int count = n.intValue();
- for (int i = 0; i < count; i++) {
- long ord = ordStream.next().longValue();
- if (sb2.length() > 0) {
- sb2.append(",");
- }
- sb2.append(Long.toString(ord));
- }
- // now pad to fit: these are numbers so spaces work well. reader calls trim()
- int numPadding = maxOrdListLength - sb2.length();
- for (int i = 0; i < numPadding; i++) {
- sb2.append(' ');
- }
- SimpleTextUtil.write(data, sb2.toString(), scratch);
- SimpleTextUtil.writeNewline(data);
- }
- }
-
- /** write the header for this field */
- private void writeFieldEntry(FieldInfo field, FieldInfo.DocValuesType type) {
- SimpleTextUtil.write(data, FIELD);
- SimpleTextUtil.write(data, field.name, scratch);
- SimpleTextUtil.writeNewline(data);
-
- SimpleTextUtil.write(data, TYPE);
- SimpleTextUtil.write(data, type.toString(), scratch);
- SimpleTextUtil.writeNewline(data);
- }
-
- @Override
- public void close() {
- if (data != null) {
- bool success = false;
- try {
- Debug.Assert( !fieldsSeen.isEmpty();
- // TODO: sheisty to do this here?
- SimpleTextUtil.write(data, END);
- SimpleTextUtil.writeNewline(data);
- SimpleTextUtil.writeChecksum(data, scratch);
- success = true;
- } finally {
- if (success) {
- IOUtils.close(data);
- } else {
- IOUtils.closeWhileHandlingException(data);
- }
- data = null;
- }
- }
- }
-}
+using System;
+using System.Diagnostics;
+using System.Collections.Generic;
+using System.Text;
+
+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 IndexFileNames = Index.IndexFileNames;
+ using SegmentWriteState = Index.SegmentWriteState;
+ using DocValuesType = Index.FieldInfo.DocValuesType;
+ using IndexOutput = Store.IndexOutput;
+ using BytesRef = Util.BytesRef;
+ using IOUtils = Util.IOUtils;
+
+ public class SimpleTextDocValuesWriter : DocValuesConsumer
+ {
+ internal static readonly BytesRef END = new BytesRef("END");
+ internal static readonly BytesRef FIELD = new BytesRef("field ");
+ internal static readonly BytesRef TYPE = new BytesRef(" type ");
+ // used for numerics
+ internal static readonly BytesRef MINVALUE = new BytesRef(" minvalue ");
+ internal static readonly BytesRef PATTERN = new BytesRef(" pattern ");
+ // used for bytes
+ internal static readonly BytesRef LENGTH = new BytesRef("length ");
+ internal static readonly BytesRef MAXLENGTH = new BytesRef(" maxlength ");
+ // used for sorted bytes
+ internal static readonly BytesRef NUMVALUES = new BytesRef(" numvalues ");
+ internal static readonly BytesRef ORDPATTERN = new BytesRef(" ordpattern ");
+
+ internal IndexOutput data;
+ internal readonly BytesRef scratch = new BytesRef();
+ internal readonly int numDocs;
+ private readonly HashSet<string> fieldsSeen = new HashSet<string>(); // for asserting
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: public SimpleTextDocValuesWriter(index.SegmentWriteState state, String ext) throws java.io.IOException
+ public SimpleTextDocValuesWriter(SegmentWriteState state, string ext)
+ {
+ // System.out.println("WRITE: " + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext) + " " + state.segmentInfo.getDocCount() + " docs");
+ data = state.directory.createOutput(IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext), state.context);
+ numDocs = state.segmentInfo.DocCount;
+ }
+
+ // for asserting
+ private bool fieldSeen(string field)
+ {
+ Debug.Assert(!fieldsSeen.Contains(field), "field \"" + field + "\" was added more than once during flush");
+ fieldsSeen.Add(field);
+ return true;
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void addNumericField(index.FieldInfo field, Iterable<Number> values) throws java.io.IOException
+ public override void addNumericField(FieldInfo field, IEnumerable<Number> values)
+ {
+ Debug.Assert(fieldSeen(field.name));
+ assert(field.DocValuesType == FieldInfo.DocValuesType.NUMERIC || field.NormType == FieldInfo.DocValuesType.NUMERIC);
+ writeFieldEntry(field, FieldInfo.DocValuesType.NUMERIC);
+
+ // first pass to find min/max
+ long minValue = long.MaxValue;
+ long maxValue = long.MinValue;
+ foreach (Number n in values)
+ {
+ long v = n == null ? 0 : (long)n;
+ minValue = Math.Min(minValue, v);
+ maxValue = Math.Max(maxValue, v);
+ }
+
+ // write our minimum value to the .dat, all entries are deltas from that
+ SimpleTextUtil.write(data, MINVALUE);
+ SimpleTextUtil.write(data, Convert.ToString(minValue), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ // build up our fixed-width "simple text packed ints"
+ // format
+ System.Numerics.BigInteger maxBig = System.Numerics.BigInteger.valueOf(maxValue);
+ System.Numerics.BigInteger minBig = System.Numerics.BigInteger.valueOf(minValue);
+ System.Numerics.BigInteger diffBig = maxBig - minBig;
+ int maxBytesPerValue = diffBig.ToString().Length;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < maxBytesPerValue; i++)
+ {
+ sb.Append('0');
+ }
+
+ // write our pattern to the .dat
+ SimpleTextUtil.write(data, PATTERN);
+ SimpleTextUtil.write(data, sb.ToString(), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final String patternString = sb.toString();
+ string patternString = sb.ToString();
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat encoder = new java.text.DecimalFormat(patternString, new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat encoder = new DecimalFormat(patternString, new DecimalFormatSymbols(Locale.ROOT));
+
+ int numDocsWritten = 0;
+
+ // second pass to write the values
+ foreach (Number n in values)
+ {
+ long value = n == null ? 0 : (long)n;
+ Debug.Assert(value >= minValue);
+ Number delta = System.Numerics.BigInteger.valueOf(value) - System.Numerics.BigInteger.valueOf(minValue);
+ string s = encoder.format(delta);
+ Debug.Assert(s.Length == patternString.Length);
+ SimpleTextUtil.write(data, s, scratch);
+ SimpleTextUtil.WriteNewline(data);
+ if (n == null)
+ {
+ SimpleTextUtil.write(data, "F", scratch);
+ }
+ else
+ {
+ SimpleTextUtil.write(data, "T", scratch);
+ }
+ SimpleTextUtil.WriteNewline(data);
+ numDocsWritten++;
+ Debug.Assert(numDocsWritten <= numDocs);
+ }
+
+ Debug.Assert(numDocs == numDocsWritten, "numDocs=" + numDocs + " numDocsWritten=" + numDocsWritten);
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void addBinaryField(index.FieldInfo field, Iterable<util.BytesRef> values) throws java.io.IOException
+ public override void addBinaryField(FieldInfo field, IEnumerable<BytesRef> values)
+ {
+ Debug.Assert(fieldSeen(field.name));
+ Debug.Assert(field.DocValuesType == FieldInfo.DocValuesType.BINARY);
+ int maxLength = 0;
+ foreach (BytesRef value in values)
+ {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final int length = value == null ? 0 : value.length;
+ int length = value == null ? 0 : value.length;
+ maxLength = Math.Max(maxLength, length);
+ }
+ writeFieldEntry(field, FieldInfo.DocValuesType.BINARY);
+
+ // write maxLength
+ SimpleTextUtil.write(data, MAXLENGTH);
+ SimpleTextUtil.write(data, Convert.ToString(maxLength), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ int maxBytesLength = Convert.ToString(maxLength).Length;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < maxBytesLength; i++)
+ {
+ sb.Append('0');
+ }
+ // write our pattern for encoding lengths
+ SimpleTextUtil.write(data, PATTERN);
+ SimpleTextUtil.write(data, sb.ToString(), scratch);
+ SimpleTextUtil.WriteNewline(data);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat encoder = new java.text.DecimalFormat(sb.toString(), new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat encoder = new DecimalFormat(sb.ToString(), new DecimalFormatSymbols(Locale.ROOT));
+
+ int numDocsWritten = 0;
+ foreach (BytesRef value in values)
+ {
+ // write length
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final int length = value == null ? 0 : value.length;
+ int length = value == null ? 0 : value.length;
+ SimpleTextUtil.write(data, LENGTH);
+ SimpleTextUtil.write(data, encoder.format(length), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ // write bytes -- don't use SimpleText.write
+ // because it escapes:
+ if (value != null)
+ {
+ data.writeBytes(value.bytes, value.offset, value.length);
+ }
+
+ // pad to fit
+ for (int i = length; i < maxLength; i++)
+ {
+ data.writeByte((sbyte)' ');
+ }
+ SimpleTextUtil.WriteNewline(data);
+ if (value == null)
+ {
+ SimpleTextUtil.write(data, "F", scratch);
+ }
+ else
+ {
+ SimpleTextUtil.write(data, "T", scratch);
+ }
+ SimpleTextUtil.WriteNewline(data);
+ numDocsWritten++;
+ }
+
+ Debug.Assert(numDocs == numDocsWritten);
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void addSortedField(index.FieldInfo field, Iterable<util.BytesRef> values, Iterable<Number> docToOrd) throws java.io.IOException
+ public override void addSortedField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<Number> docToOrd)
+ {
+ Debug.Assert(fieldSeen(field.name));
+ Debug.Assert(field.DocValuesType == FieldInfo.DocValuesType.SORTED);
+ writeFieldEntry(field, FieldInfo.DocValuesType.SORTED);
+
+ int valueCount = 0;
+ int maxLength = -1;
+ foreach (BytesRef value in values)
+ {
+ maxLength = Math.Max(maxLength, value.length);
+ valueCount++;
+ }
+
+ // write numValues
+ SimpleTextUtil.write(data, NUMVALUES);
+ SimpleTextUtil.write(data, Convert.ToString(valueCount), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ // write maxLength
+ SimpleTextUtil.write(data, MAXLENGTH);
+ SimpleTextUtil.write(data, Convert.ToString(maxLength), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ int maxBytesLength = Convert.ToString(maxLength).Length;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < maxBytesLength; i++)
+ {
+ sb.Append('0');
+ }
+
+ // write our pattern for encoding lengths
+ SimpleTextUtil.write(data, PATTERN);
+ SimpleTextUtil.write(data, sb.ToString(), scratch);
+ SimpleTextUtil.WriteNewline(data);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat encoder = new java.text.DecimalFormat(sb.toString(), new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat encoder = new DecimalFormat(sb.ToString(), new DecimalFormatSymbols(Locale.ROOT));
+
+ int maxOrdBytes = Convert.ToString(valueCount + 1L).Length;
+ sb.Length = 0;
+ for (int i = 0; i < maxOrdBytes; i++)
+ {
+ sb.Append('0');
+ }
+
+ // write our pattern for ords
+ SimpleTextUtil.write(data, ORDPATTERN);
+ SimpleTextUtil.write(data, sb.ToString(), scratch);
+ SimpleTextUtil.WriteNewline(data);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat ordEncoder = new java.text.DecimalFormat(sb.toString(), new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat ordEncoder = new DecimalFormat(sb.ToString(), new DecimalFormatSymbols(Locale.ROOT));
+
+ // for asserts:
+ int valuesSeen = 0;
+
+ foreach (BytesRef value in values)
+ {
+ // write length
+ SimpleTextUtil.write(data, LENGTH);
+ SimpleTextUtil.write(data, encoder.format(value.length), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ // write bytes -- don't use SimpleText.write
+ // because it escapes:
+ data.writeBytes(value.bytes, value.offset, value.length);
+
+ // pad to fit
+ for (int i = value.length; i < maxLength; i++)
+ {
+ data.writeByte((sbyte)' ');
+ }
+ SimpleTextUtil.WriteNewline(data);
+ valuesSeen++;
+ Debug.Assert(valuesSeen <= valueCount);
+ }
+
+ Debug.Assert(valuesSeen == valueCount);
+
+ foreach (Number ord in docToOrd)
+ {
+ SimpleTextUtil.write(data, ordEncoder.format((long)ord + 1), scratch);
+ SimpleTextUtil.WriteNewline(data);
+ }
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void addSortedSetField(index.FieldInfo field, Iterable<util.BytesRef> values, Iterable<Number> docToOrdCount, Iterable<Number> ords) throws java.io.IOException
+ public override void addSortedSetField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<Number> docToOrdCount, IEnumerable<Number> ords)
+ {
+ Debug.Assert(fieldSeen(field.name));
+ Debug.Assert(field.DocValuesType == FieldInfo.DocValuesType.SORTED_SET);
+ writeFieldEntry(field, FieldInfo.DocValuesType.SORTED_SET);
+
+ long valueCount = 0;
+ int maxLength = 0;
+ foreach (BytesRef value in values)
+ {
+ maxLength = Math.Max(maxLength, value.length);
+ valueCount++;
+ }
+
+ // write numValues
+ SimpleTextUtil.write(data, NUMVALUES);
+ SimpleTextUtil.write(data, Convert.ToString(valueCount), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ // write maxLength
+ SimpleTextUtil.write(data, MAXLENGTH);
+ SimpleTextUtil.write(data, Convert.ToString(maxLength), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ int maxBytesLength = Convert.ToString(maxLength).Length;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < maxBytesLength; i++)
+ {
+ sb.Append('0');
+ }
+
+ // write our pattern for encoding lengths
+ SimpleTextUtil.write(data, PATTERN);
+ SimpleTextUtil.write(data, sb.ToString(), scratch);
+ SimpleTextUtil.WriteNewline(data);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.text.DecimalFormat encoder = new java.text.DecimalFormat(sb.toString(), new java.text.DecimalFormatSymbols(java.util.Locale.ROOT));
+ DecimalFormat encoder = new DecimalFormat(sb.ToString(), new DecimalFormatSymbols(Locale.ROOT));
+
+ // compute ord pattern: this is funny, we encode all values for all docs to find the maximum length
+ int maxOrdListLength = 0;
+ StringBuilder sb2 = new StringBuilder();
+ IEnumerator<Number> ordStream = ords.GetEnumerator();
+ foreach (Number n in docToOrdCount)
+ {
+ sb2.Length = 0;
+ int count = (int)n;
+ for (int i = 0; i < count; i++)
+ {
+//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
+ long ord = (long)ordStream.next();
+ if (sb2.Length > 0)
+ {
+ sb2.Append(",");
+ }
+ sb2.Append(Convert.ToString(ord));
+ }
+ maxOrdListLength = Math.Max(maxOrdListLength, sb2.Length);
+ }
+
+ sb2.Length = 0;
+ for (int i = 0; i < maxOrdListLength; i++)
+ {
+ sb2.Append('X');
+ }
+
+ // write our pattern for ord lists
+ SimpleTextUtil.write(data, ORDPATTERN);
+ SimpleTextUtil.write(data, sb2.ToString(), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ // for asserts:
+ long valuesSeen = 0;
+
+ foreach (BytesRef value in values)
+ {
+ // write length
+ SimpleTextUtil.write(data, LENGTH);
+ SimpleTextUtil.write(data, encoder.format(value.length), scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ // write bytes -- don't use SimpleText.write
+ // because it escapes:
+ data.writeBytes(value.bytes, value.offset, value.length);
+
+ // pad to fit
+ for (int i = value.length; i < maxLength; i++)
+ {
+ data.writeByte((sbyte)' ');
+ }
+ SimpleTextUtil.WriteNewline(data);
+ valuesSeen++;
+ Debug.Assert(valuesSeen <= valueCount);
+ }
+
+ Debug.Assert(valuesSeen == valueCount);
+
+ ordStream = ords.GetEnumerator();
+
+ // write the ords for each doc comma-separated
+ foreach (Number n in docToOrdCount)
+ {
+ sb2.Length = 0;
+ int count = (int)n;
+ for (int i = 0; i < count; i++)
+ {
+//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
+ long ord = (long)ordStream.next();
+ if (sb2.Length > 0)
+ {
+ sb2.Append(",");
+ }
+ sb2.Append(Convert.ToString(ord));
+ }
+ // now pad to fit: these are numbers so spaces work well. reader calls trim()
+ int numPadding = maxOrdListLength - sb2.Length;
+ for (int i = 0; i < numPadding; i++)
+ {
+ sb2.Append(' ');
+ }
+ SimpleTextUtil.write(data, sb2.ToString(), scratch);
+ SimpleTextUtil.WriteNewline(data);
+ }
+ }
+
+ /// <summary>
+ /// write the header for this field </summary>
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void writeFieldEntry(index.FieldInfo field, index.FieldInfo.DocValuesType type) throws java.io.IOException
+ private void writeFieldEntry(FieldInfo field, FieldInfo.DocValuesType type)
+ {
+ SimpleTextUtil.write(data, FIELD);
+ SimpleTextUtil.write(data, field.name, scratch);
+ SimpleTextUtil.WriteNewline(data);
+
+ SimpleTextUtil.write(data, TYPE);
+ SimpleTextUtil.write(data, type.ToString(), scratch);
+ SimpleTextUtil.WriteNewline(data);
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void close() throws java.io.IOException
+ public override void close()
+ {
+ if (data != null)
+ {
+ bool success = false;
+ try
+ {
+ Debug.Assert(fieldsSeen.Count > 0);
+ // TODO: sheisty to do this here?
+ SimpleTextUtil.write(data, END);
+ SimpleTextUtil.WriteNewline(data);
+ SimpleTextUtil.WriteChecksum(data, scratch);
+ success = true;
+ }
+ finally
+ {
+ if (success)
+ {
+ IOUtils.close(data);
+ }
+ else
+ {
+ IOUtils.closeWhileHandlingException(data);
+ }
+ data = null;
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosFormat.cs
index 9c6b0e3..f8852ea 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldInfosFormat.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,29 +15,29 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import java.io.IOException;
-
-import org.apache.lucene.codecs.FieldInfosFormat;
-import org.apache.lucene.codecs.FieldInfosReader;
-import org.apache.lucene.codecs.FieldInfosWriter;
+namespace Lucene.Net.Codecs.SimpleText
+{
-/**
- * plaintext field infos format
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextFieldInfosFormat extends FieldInfosFormat {
- private final FieldInfosReader reader = new SimpleTextFieldInfosReader();
- private final FieldInfosWriter writer = new SimpleTextFieldInfosWriter();
+ /// <summary>
+ /// plaintext field infos format
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextFieldInfosFormat : FieldInfosFormat
+ {
+ private readonly FieldInfosReader _reader = new SimpleTextFieldInfosReader();
+ private readonly FieldInfosWriter _writer = new SimpleTextFieldInfosWriter();
- @Override
- public FieldInfosReader getFieldInfosReader() {
- return reader;
- }
+ public override FieldInfosReader FieldInfosReader
+ {
+ get { return _reader; }
+ }
- @Override
- public FieldInfosWriter getFieldInfosWriter() {
- return writer;
- }
-}
+ public override FieldInfosWriter FieldInfosWriter
+ {
+ get { return _writer; }
+ }
+ }
+}
\ No newline at end of file
[7/7] git commit: Cleanup of codes, mostly SimpleText in this commit
Posted by pn...@apache.org.
Cleanup of codes, mostly SimpleText in this commit
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/cf1df6be
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/cf1df6be
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/cf1df6be
Branch: refs/heads/master
Commit: cf1df6becb10be6b3958b4092483357ac18be288
Parents: 68c7f0c
Author: Prescott Nasser <pn...@apache.org>
Authored: Sun Sep 21 09:47:02 2014 -0700
Committer: Prescott Nasser <pn...@apache.org>
Committed: Sun Sep 21 09:47:02 2014 -0700
----------------------------------------------------------------------
.../Intblock/FixedIntBlockIndexOutput.cs | 8 +-
.../Intblock/VariableIntBlockIndexInput.cs | 8 +-
.../Intblock/VariableIntBlockIndexOutput.cs | 8 +-
src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj | 1 +
.../Memory/DirectDocValuesConsumer.cs | 28 +-
.../Memory/DirectDocValuesFormat.cs | 16 +-
.../Memory/DirectDocValuesProducer.cs | 40 +-
.../Memory/DirectPostingsFormat.cs | 50 +-
.../Memory/FSTOrdPostingsFormat.cs | 24 +-
.../Memory/FSTOrdPulsing41PostingsFormat.cs | 32 +-
.../Memory/FSTOrdTermsReader.cs | 68 +-
.../Memory/FSTOrdTermsWriter.cs | 48 +-
.../Memory/FSTPostingsFormat.cs | 24 +-
.../Memory/FSTPulsing41PostingsFormat.cs | 32 +-
src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs | 14 +-
src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs | 62 +-
src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs | 46 +-
.../Memory/MemoryDocValuesConsumer.cs | 62 +-
.../Memory/MemoryDocValuesFormat.cs | 14 +-
.../Memory/MemoryDocValuesProducer.cs | 72 +-
.../Memory/MemoryPostingsFormat.cs | 72 +-
src/Lucene.Net.Codecs/Sep/IntIndexInput.cs | 4 +-
src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs | 4 +-
src/Lucene.Net.Codecs/Sep/IntStreamFactory.cs | 6 +-
src/Lucene.Net.Codecs/Sep/SepPostingsReader.cs | 42 +-
src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs | 30 +-
src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs | 8 +-
src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs | 8 +-
.../SimpleText/SimpleTextCodec.cs | 131 +-
.../SimpleText/SimpleTextDocValuesFormat.cs | 235 +--
.../SimpleText/SimpleTextDocValuesReader.cs | 1257 +++++++++------
.../SimpleText/SimpleTextDocValuesWriter.cs | 896 ++++++-----
.../SimpleText/SimpleTextFieldInfosFormat.cs | 50 +-
.../SimpleText/SimpleTextFieldInfosReader.cs | 347 +++--
.../SimpleText/SimpleTextFieldInfosWriter.cs | 320 ++--
.../SimpleText/SimpleTextFieldsReader.cs | 1435 ++++++++++--------
.../SimpleText/SimpleTextFieldsWriter.cs | 367 ++---
.../SimpleText/SimpleTextLiveDocsFormat.cs | 397 ++---
.../SimpleText/SimpleTextNormsFormat.cs | 120 +-
.../SimpleText/SimpleTextPostingsFormat.cs | 90 +-
.../SimpleText/SimpleTextSegmentInfoFormat.cs | 54 +-
.../SimpleText/SimpleTextSegmentInfoReader.cs | 225 +--
.../SimpleText/SimpleTextSegmentInfoWriter.cs | 261 ++--
.../SimpleText/SimpleTextStoredFieldsFormat.cs | 54 +-
.../SimpleText/SimpleTextStoredFieldsReader.cs | 485 +++---
.../SimpleText/SimpleTextStoredFieldsWriter.cs | 403 ++---
.../SimpleText/SimpleTextTermVectorsFormat.cs | 55 +-
.../SimpleText/SimpleTextTermVectorsReader.cs | 1101 +++++++-------
.../SimpleText/SimpleTextTermVectorsWriter.cs | 411 ++---
.../SimpleText/SimpleTextUtil.cs | 58 +-
src/Lucene.Net.Codecs/StringHelperClass.cs | 119 ++
src/Lucene.Net.Core/Search/MultiTermQuery.cs | 2 +-
src/Lucene.Net.Core/Store/Directory.cs | 10 +-
53 files changed, 5338 insertions(+), 4376 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexOutput.cs b/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexOutput.cs
index a83fd38..db74098 100644
--- a/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexOutput.cs
+++ b/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexOutput.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.intblock;
+package codecs.intblock;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,9 +23,9 @@ package org.apache.lucene.codecs.intblock;
import java.io.IOException;
-import org.apache.lucene.codecs.sep.IntIndexOutput;
-import org.apache.lucene.store.DataOutput;
-import org.apache.lucene.store.IndexOutput;
+import codecs.sep.IntIndexOutput;
+import store.DataOutput;
+import store.IndexOutput;
/** Abstract base class that writes fixed-size blocks of ints
* to an IndexOutput. While this is a simple approach, a
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexInput.cs b/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexInput.cs
index 85c711a..1ce9712 100644
--- a/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexInput.cs
+++ b/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexInput.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.intblock;
+package codecs.intblock;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,9 +23,9 @@ package org.apache.lucene.codecs.intblock;
import java.io.IOException;
-import org.apache.lucene.codecs.sep.IntIndexInput;
-import org.apache.lucene.store.DataInput;
-import org.apache.lucene.store.IndexInput;
+import codecs.sep.IntIndexInput;
+import store.DataInput;
+import store.IndexInput;
// TODO: much of this can be shared code w/ the fixed case
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexOutput.cs b/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexOutput.cs
index 574b7f4..b76f69e 100644
--- a/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexOutput.cs
+++ b/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexOutput.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.intblock;
+package codecs.intblock;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,9 +23,9 @@ package org.apache.lucene.codecs.intblock;
import java.io.IOException;
-import org.apache.lucene.codecs.sep.IntIndexOutput;
-import org.apache.lucene.store.DataOutput;
-import org.apache.lucene.store.IndexOutput;
+import codecs.sep.IntIndexOutput;
+import store.DataOutput;
+import store.IndexOutput;
// TODO: much of this can be shared code w/ the fixed case
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj b/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj
index 06e1908..31340ae 100644
--- a/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj
+++ b/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj
@@ -118,6 +118,7 @@
<Compile Include="SimpleText\SimpleTextTermVectorsReader.cs" />
<Compile Include="SimpleText\SimpleTextTermVectorsWriter.cs" />
<Compile Include="SimpleText\SimpleTextUtil.cs" />
+ <Compile Include="StringHelperClass.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs b/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
index 2e7e013..ddddf6f 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,20 +20,20 @@ package org.apache.lucene.codecs.memory;
import java.io.IOException;
import java.util.Iterator;
-import org.apache.lucene.codecs.CodecUtil;
-import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
+import codecs.CodecUtil;
+import codecs.DocValuesConsumer;
+import index.FieldInfo;
+import index.IndexFileNames;
+import index.SegmentWriteState;
+import store.IndexOutput;
+import util.BytesRef;
+import util.IOUtils;
-import static org.apache.lucene.codecs.memory.DirectDocValuesProducer.VERSION_CURRENT;
-import static org.apache.lucene.codecs.memory.DirectDocValuesProducer.BYTES;
-import static org.apache.lucene.codecs.memory.DirectDocValuesProducer.SORTED;
-import static org.apache.lucene.codecs.memory.DirectDocValuesProducer.SORTED_SET;
-import static org.apache.lucene.codecs.memory.DirectDocValuesProducer.NUMBER;
+import static codecs.memory.DirectDocValuesProducer.VERSION_CURRENT;
+import static codecs.memory.DirectDocValuesProducer.BYTES;
+import static codecs.memory.DirectDocValuesProducer.SORTED;
+import static codecs.memory.DirectDocValuesProducer.SORTED_SET;
+import static codecs.memory.DirectDocValuesProducer.NUMBER;
/**
* Writer for {@link DirectDocValuesFormat}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/DirectDocValuesFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectDocValuesFormat.cs b/src/Lucene.Net.Codecs/Memory/DirectDocValuesFormat.cs
index 1f89e43..fb98c99 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectDocValuesFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectDocValuesFormat.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,13 +19,13 @@ package org.apache.lucene.codecs.memory;
import java.io.IOException;
-import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.codecs.DocValuesFormat;
-import org.apache.lucene.codecs.DocValuesProducer;
-import org.apache.lucene.document.SortedSetDocValuesField; // javadocs
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.util.ArrayUtil;
+import codecs.DocValuesConsumer;
+import codecs.DocValuesFormat;
+import codecs.DocValuesProducer;
+import document.SortedSetDocValuesField; // javadocs
+import index.SegmentReadState;
+import index.SegmentWriteState;
+import util.ArrayUtil;
/** In-memory docvalues format that does no (or very little)
* compression. Indexed values are stored on disk, but
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs b/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
index a95f384..6d63d5b 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -22,25 +22,25 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
-import org.apache.lucene.codecs.CodecUtil;
-import org.apache.lucene.codecs.DocValuesProducer;
-import org.apache.lucene.index.BinaryDocValues;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.lucene.index.RandomAccessOrds;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SortedDocValues;
-import org.apache.lucene.index.SortedSetDocValues;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.FixedBitSet;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.RamUsageEstimator;
+import codecs.CodecUtil;
+import codecs.DocValuesProducer;
+import index.BinaryDocValues;
+import index.CorruptIndexException;
+import index.DocValues;
+import index.FieldInfo;
+import index.IndexFileNames;
+import index.NumericDocValues;
+import index.RandomAccessOrds;
+import index.SegmentReadState;
+import index.SortedDocValues;
+import index.SortedSetDocValues;
+import store.ChecksumIndexInput;
+import store.IndexInput;
+import util.Bits;
+import util.BytesRef;
+import util.FixedBitSet;
+import util.IOUtils;
+import util.RamUsageEstimator;
/**
* Reader for {@link DirectDocValuesFormat}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
index 5d90e98..c28a147 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectPostingsFormat.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -24,30 +24,30 @@ import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat; // javadocs
-import org.apache.lucene.index.DocsAndPositionsEnum;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.Fields;
-import org.apache.lucene.index.OrdTermState;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.index.TermState;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.RAMOutputStream;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.RamUsageEstimator;
-import org.apache.lucene.util.automaton.CompiledAutomaton;
-import org.apache.lucene.util.automaton.RunAutomaton;
-import org.apache.lucene.util.automaton.Transition;
+import codecs.FieldsConsumer;
+import codecs.FieldsProducer;
+import codecs.PostingsFormat;
+import codecs.lucene41.Lucene41PostingsFormat; // javadocs
+import index.DocsAndPositionsEnum;
+import index.DocsEnum;
+import index.FieldInfo.IndexOptions;
+import index.FieldInfo;
+import index.Fields;
+import index.OrdTermState;
+import index.SegmentReadState;
+import index.SegmentWriteState;
+import index.TermState;
+import index.Terms;
+import index.TermsEnum;
+import store.IOContext;
+import store.RAMOutputStream;
+import util.ArrayUtil;
+import util.Bits;
+import util.BytesRef;
+import util.RamUsageEstimator;
+import util.automaton.CompiledAutomaton;
+import util.automaton.RunAutomaton;
+import util.automaton.Transition;
// TODO:
// - build depth-N prefix hash?
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/FSTOrdPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTOrdPostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/FSTOrdPostingsFormat.cs
index d8be831..0545afc 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTOrdPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTOrdPostingsFormat.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
@@ -20,17 +20,17 @@ package org.apache.lucene.codecs.memory;
import java.io.IOException;
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.codecs.PostingsReaderBase;
-import org.apache.lucene.codecs.PostingsWriterBase;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsWriter;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsReader;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.util.IOUtils;
+import codecs.FieldsConsumer;
+import codecs.FieldsProducer;
+import codecs.PostingsFormat;
+import codecs.PostingsReaderBase;
+import codecs.PostingsWriterBase;
+import codecs.lucene41.Lucene41PostingsWriter;
+import codecs.lucene41.Lucene41PostingsReader;
+import index.FieldInfo.IndexOptions;
+import index.SegmentReadState;
+import index.SegmentWriteState;
+import util.IOUtils;
/**
* FSTOrd term dict + Lucene41PBF
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/FSTOrdPulsing41PostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTOrdPulsing41PostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/FSTOrdPulsing41PostingsFormat.cs
index 257d2eb..acb5645 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTOrdPulsing41PostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTOrdPulsing41PostingsFormat.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,21 +19,21 @@ package org.apache.lucene.codecs.memory;
import java.io.IOException;
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.codecs.PostingsBaseFormat;
-import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.codecs.PostingsReaderBase;
-import org.apache.lucene.codecs.PostingsWriterBase;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsWriter;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsReader;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsBaseFormat;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat;
-import org.apache.lucene.codecs.pulsing.PulsingPostingsWriter;
-import org.apache.lucene.codecs.pulsing.PulsingPostingsReader;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.util.IOUtils;
+import codecs.FieldsConsumer;
+import codecs.FieldsProducer;
+import codecs.PostingsBaseFormat;
+import codecs.PostingsFormat;
+import codecs.PostingsReaderBase;
+import codecs.PostingsWriterBase;
+import codecs.lucene41.Lucene41PostingsWriter;
+import codecs.lucene41.Lucene41PostingsReader;
+import codecs.lucene41.Lucene41PostingsBaseFormat;
+import codecs.lucene41.Lucene41PostingsFormat;
+import codecs.pulsing.PulsingPostingsWriter;
+import codecs.pulsing.PulsingPostingsReader;
+import index.SegmentReadState;
+import index.SegmentWriteState;
+import util.IOUtils;
/** FSTOrd + Pulsing41
* @lucene.experimental */
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs
index 67eaa6e..53d0d69 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsReader.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -26,39 +26,39 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeMap;
-import org.apache.lucene.codecs.BlockTermState;
-import org.apache.lucene.codecs.CodecUtil;
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.codecs.PostingsReaderBase;
-import org.apache.lucene.codecs.memory.FSTTermsReader.TermsReader;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.DocsAndPositionsEnum;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.TermState;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.store.ByteArrayDataInput;
-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.IOUtils;
-import org.apache.lucene.util.RamUsageEstimator;
-import org.apache.lucene.util.automaton.ByteRunAutomaton;
-import org.apache.lucene.util.automaton.CompiledAutomaton;
-import org.apache.lucene.util.fst.BytesRefFSTEnum.InputOutput;
-import org.apache.lucene.util.fst.BytesRefFSTEnum;
-import org.apache.lucene.util.fst.FST;
-import org.apache.lucene.util.fst.Outputs;
-import org.apache.lucene.util.fst.PositiveIntOutputs;
-import org.apache.lucene.util.fst.Util;
+import codecs.BlockTermState;
+import codecs.CodecUtil;
+import codecs.FieldsProducer;
+import codecs.PostingsReaderBase;
+import codecs.memory.FSTTermsReader.TermsReader;
+import index.CorruptIndexException;
+import index.DocsAndPositionsEnum;
+import index.DocsEnum;
+import index.FieldInfo.IndexOptions;
+import index.FieldInfo;
+import index.FieldInfos;
+import index.IndexFileNames;
+import index.SegmentInfo;
+import index.SegmentReadState;
+import index.TermState;
+import index.Terms;
+import index.TermsEnum;
+import store.ByteArrayDataInput;
+import store.ChecksumIndexInput;
+import store.IndexInput;
+import util.ArrayUtil;
+import util.Bits;
+import util.BytesRef;
+import util.IOUtils;
+import util.RamUsageEstimator;
+import util.automaton.ByteRunAutomaton;
+import util.automaton.CompiledAutomaton;
+import util.fst.BytesRefFSTEnum.InputOutput;
+import util.fst.BytesRefFSTEnum;
+import util.fst.FST;
+import util.fst.Outputs;
+import util.fst.PositiveIntOutputs;
+import util.fst.Util;
/**
* FST-based terms dictionary reader.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs
index 33997fd..76d0092 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -22,29 +22,29 @@ import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.store.DataOutput;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.store.RAMOutputStream;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.IntsRef;
-import org.apache.lucene.util.fst.Builder;
-import org.apache.lucene.util.fst.FST;
-import org.apache.lucene.util.fst.PositiveIntOutputs;
-import org.apache.lucene.util.fst.Util;
-import org.apache.lucene.codecs.BlockTermState;
-import org.apache.lucene.codecs.PostingsWriterBase;
-import org.apache.lucene.codecs.PostingsConsumer;
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.TermsConsumer;
-import org.apache.lucene.codecs.TermStats;
-import org.apache.lucene.codecs.CodecUtil;
+import index.FieldInfo.IndexOptions;
+import index.FieldInfo;
+import index.FieldInfos;
+import index.IndexFileNames;
+import index.SegmentWriteState;
+import store.DataOutput;
+import store.IndexOutput;
+import store.RAMOutputStream;
+import util.ArrayUtil;
+import util.BytesRef;
+import util.IOUtils;
+import util.IntsRef;
+import util.fst.Builder;
+import util.fst.FST;
+import util.fst.PositiveIntOutputs;
+import util.fst.Util;
+import codecs.BlockTermState;
+import codecs.PostingsWriterBase;
+import codecs.PostingsConsumer;
+import codecs.FieldsConsumer;
+import codecs.TermsConsumer;
+import codecs.TermStats;
+import codecs.CodecUtil;
/**
* FST-based term dict, using ord as FST output.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/FSTPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTPostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/FSTPostingsFormat.cs
index 5a54abd..c5ea2f1 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTPostingsFormat.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
@@ -20,17 +20,17 @@ package org.apache.lucene.codecs.memory;
import java.io.IOException;
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.codecs.PostingsReaderBase;
-import org.apache.lucene.codecs.PostingsWriterBase;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsWriter;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsReader;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.util.IOUtils;
+import codecs.FieldsConsumer;
+import codecs.FieldsProducer;
+import codecs.PostingsFormat;
+import codecs.PostingsReaderBase;
+import codecs.PostingsWriterBase;
+import codecs.lucene41.Lucene41PostingsWriter;
+import codecs.lucene41.Lucene41PostingsReader;
+import index.FieldInfo.IndexOptions;
+import index.SegmentReadState;
+import index.SegmentWriteState;
+import util.IOUtils;
/**
* FST term dict + Lucene41PBF
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/FSTPulsing41PostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTPulsing41PostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/FSTPulsing41PostingsFormat.cs
index 74c4296..0db3cbd 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTPulsing41PostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTPulsing41PostingsFormat.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,21 +19,21 @@ package org.apache.lucene.codecs.memory;
import java.io.IOException;
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.codecs.PostingsBaseFormat;
-import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.codecs.PostingsReaderBase;
-import org.apache.lucene.codecs.PostingsWriterBase;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsWriter;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsReader;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsBaseFormat;
-import org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat;
-import org.apache.lucene.codecs.pulsing.PulsingPostingsWriter;
-import org.apache.lucene.codecs.pulsing.PulsingPostingsReader;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.util.IOUtils;
+import codecs.FieldsConsumer;
+import codecs.FieldsProducer;
+import codecs.PostingsBaseFormat;
+import codecs.PostingsFormat;
+import codecs.PostingsReaderBase;
+import codecs.PostingsWriterBase;
+import codecs.lucene41.Lucene41PostingsWriter;
+import codecs.lucene41.Lucene41PostingsReader;
+import codecs.lucene41.Lucene41PostingsBaseFormat;
+import codecs.lucene41.Lucene41PostingsFormat;
+import codecs.pulsing.PulsingPostingsWriter;
+import codecs.pulsing.PulsingPostingsReader;
+import index.SegmentReadState;
+import index.SegmentWriteState;
+import util.IOUtils;
/** FST + Pulsing41, test only, since
* FST does no delta encoding here!
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs b/src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs
index e0a91e8..55a2bd6 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,12 +20,12 @@ package org.apache.lucene.codecs.memory;
import java.io.IOException;
import java.util.Arrays;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.store.DataInput;
-import org.apache.lucene.store.DataOutput;
-import org.apache.lucene.util.fst.Outputs;
-import org.apache.lucene.util.LongsRef;
+import index.FieldInfo;
+import index.FieldInfo.IndexOptions;
+import store.DataInput;
+import store.DataOutput;
+import util.fst.Outputs;
+import util.LongsRef;
/**
* An FST {@link Outputs} implementation for
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs b/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs
index e38bb59..da1d517 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,36 +25,36 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeMap;
-import org.apache.lucene.codecs.BlockTermState;
-import org.apache.lucene.codecs.CodecUtil;
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.codecs.PostingsReaderBase;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.DocsAndPositionsEnum;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.TermState;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.store.ByteArrayDataInput;
-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.IOUtils;
-import org.apache.lucene.util.RamUsageEstimator;
-import org.apache.lucene.util.automaton.ByteRunAutomaton;
-import org.apache.lucene.util.automaton.CompiledAutomaton;
-import org.apache.lucene.util.fst.BytesRefFSTEnum.InputOutput;
-import org.apache.lucene.util.fst.BytesRefFSTEnum;
-import org.apache.lucene.util.fst.FST;
-import org.apache.lucene.util.fst.Outputs;
-import org.apache.lucene.util.fst.Util;
+import codecs.BlockTermState;
+import codecs.CodecUtil;
+import codecs.FieldsProducer;
+import codecs.PostingsReaderBase;
+import index.CorruptIndexException;
+import index.DocsAndPositionsEnum;
+import index.DocsEnum;
+import index.FieldInfo.IndexOptions;
+import index.FieldInfo;
+import index.FieldInfos;
+import index.IndexFileNames;
+import index.SegmentInfo;
+import index.SegmentReadState;
+import index.TermState;
+import index.Terms;
+import index.TermsEnum;
+import store.ByteArrayDataInput;
+import store.IndexInput;
+import util.ArrayUtil;
+import util.Bits;
+import util.BytesRef;
+import util.IOUtils;
+import util.RamUsageEstimator;
+import util.automaton.ByteRunAutomaton;
+import util.automaton.CompiledAutomaton;
+import util.fst.BytesRefFSTEnum.InputOutput;
+import util.fst.BytesRefFSTEnum;
+import util.fst.FST;
+import util.fst.Outputs;
+import util.fst.Util;
/**
* FST-based terms dictionary reader.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs b/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs
index 367b83d..4b587b7 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -22,28 +22,28 @@ import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.store.DataOutput;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.store.RAMOutputStream;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.IntsRef;
-import org.apache.lucene.util.fst.Builder;
-import org.apache.lucene.util.fst.FST;
-import org.apache.lucene.util.fst.Util;
-import org.apache.lucene.codecs.BlockTermState;
-import org.apache.lucene.codecs.PostingsWriterBase;
-import org.apache.lucene.codecs.PostingsConsumer;
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.TermsConsumer;
-import org.apache.lucene.codecs.TermStats;
-import org.apache.lucene.codecs.CodecUtil;
+import index.FieldInfo.IndexOptions;
+import index.FieldInfo;
+import index.FieldInfos;
+import index.IndexFileNames;
+import index.SegmentWriteState;
+import store.DataOutput;
+import store.IndexOutput;
+import store.RAMOutputStream;
+import util.ArrayUtil;
+import util.BytesRef;
+import util.IOUtils;
+import util.IntsRef;
+import util.fst.Builder;
+import util.fst.FST;
+import util.fst.Util;
+import codecs.BlockTermState;
+import codecs.PostingsWriterBase;
+import codecs.PostingsConsumer;
+import codecs.FieldsConsumer;
+import codecs.TermsConsumer;
+import codecs.TermStats;
+import codecs.CodecUtil;
/**
* FST-based term dict, using metadata as FST output.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs
index e8026df..285c243 100644
--- a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs
+++ b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,37 +23,37 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import org.apache.lucene.codecs.CodecUtil;
-import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.store.ByteArrayDataOutput;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.IntsRef;
-import org.apache.lucene.util.MathUtil;
-import org.apache.lucene.util.fst.Builder;
-import org.apache.lucene.util.fst.FST.INPUT_TYPE;
-import org.apache.lucene.util.fst.FST;
-import org.apache.lucene.util.fst.PositiveIntOutputs;
-import org.apache.lucene.util.fst.Util;
-import org.apache.lucene.util.packed.BlockPackedWriter;
-import org.apache.lucene.util.packed.MonotonicBlockPackedWriter;
-import org.apache.lucene.util.packed.PackedInts.FormatAndBits;
-import org.apache.lucene.util.packed.PackedInts;
+import codecs.CodecUtil;
+import codecs.DocValuesConsumer;
+import index.FieldInfo;
+import index.IndexFileNames;
+import index.SegmentWriteState;
+import store.ByteArrayDataOutput;
+import store.IndexOutput;
+import util.ArrayUtil;
+import util.BytesRef;
+import util.IOUtils;
+import util.IntsRef;
+import util.MathUtil;
+import util.fst.Builder;
+import util.fst.FST.INPUT_TYPE;
+import util.fst.FST;
+import util.fst.PositiveIntOutputs;
+import util.fst.Util;
+import util.packed.BlockPackedWriter;
+import util.packed.MonotonicBlockPackedWriter;
+import util.packed.PackedInts.FormatAndBits;
+import util.packed.PackedInts;
-import static org.apache.lucene.codecs.memory.MemoryDocValuesProducer.VERSION_CURRENT;
-import static org.apache.lucene.codecs.memory.MemoryDocValuesProducer.BLOCK_SIZE;
-import static org.apache.lucene.codecs.memory.MemoryDocValuesProducer.BYTES;
-import static org.apache.lucene.codecs.memory.MemoryDocValuesProducer.NUMBER;
-import static org.apache.lucene.codecs.memory.MemoryDocValuesProducer.FST;
-import static org.apache.lucene.codecs.memory.MemoryDocValuesProducer.DELTA_COMPRESSED;
-import static org.apache.lucene.codecs.memory.MemoryDocValuesProducer.GCD_COMPRESSED;
-import static org.apache.lucene.codecs.memory.MemoryDocValuesProducer.TABLE_COMPRESSED;
-import static org.apache.lucene.codecs.memory.MemoryDocValuesProducer.UNCOMPRESSED;
+import static codecs.memory.MemoryDocValuesProducer.VERSION_CURRENT;
+import static codecs.memory.MemoryDocValuesProducer.BLOCK_SIZE;
+import static codecs.memory.MemoryDocValuesProducer.BYTES;
+import static codecs.memory.MemoryDocValuesProducer.NUMBER;
+import static codecs.memory.MemoryDocValuesProducer.FST;
+import static codecs.memory.MemoryDocValuesProducer.DELTA_COMPRESSED;
+import static codecs.memory.MemoryDocValuesProducer.GCD_COMPRESSED;
+import static codecs.memory.MemoryDocValuesProducer.TABLE_COMPRESSED;
+import static codecs.memory.MemoryDocValuesProducer.UNCOMPRESSED;
/**
* Writer for {@link MemoryDocValuesFormat}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/MemoryDocValuesFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesFormat.cs b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesFormat.cs
index efc1aba..34b360c 100644
--- a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesFormat.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,12 +19,12 @@ package org.apache.lucene.codecs.memory;
import java.io.IOException;
-import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.codecs.DocValuesProducer;
-import org.apache.lucene.codecs.DocValuesFormat;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.util.packed.PackedInts;
+import codecs.DocValuesConsumer;
+import codecs.DocValuesProducer;
+import codecs.DocValuesFormat;
+import index.SegmentReadState;
+import index.SegmentWriteState;
+import util.packed.PackedInts;
/** In-memory docvalues format */
public class MemoryDocValuesFormat extends DocValuesFormat {
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs
index ce004b4..015a1af 100644
--- a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs
+++ b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesProducer.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,41 +23,41 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
-import org.apache.lucene.codecs.CodecUtil;
-import org.apache.lucene.codecs.DocValuesProducer;
-import org.apache.lucene.index.BinaryDocValues;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.DocsAndPositionsEnum;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SortedDocValues;
-import org.apache.lucene.index.SortedSetDocValues;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.store.ByteArrayDataInput;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.FixedBitSet;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.IntsRef;
-import org.apache.lucene.util.PagedBytes;
-import org.apache.lucene.util.RamUsageEstimator;
-import org.apache.lucene.util.fst.BytesRefFSTEnum;
-import org.apache.lucene.util.fst.BytesRefFSTEnum.InputOutput;
-import org.apache.lucene.util.fst.FST;
-import org.apache.lucene.util.fst.FST.Arc;
-import org.apache.lucene.util.fst.FST.BytesReader;
-import org.apache.lucene.util.fst.PositiveIntOutputs;
-import org.apache.lucene.util.fst.Util;
-import org.apache.lucene.util.packed.BlockPackedReader;
-import org.apache.lucene.util.packed.MonotonicBlockPackedReader;
-import org.apache.lucene.util.packed.PackedInts;
+import codecs.CodecUtil;
+import codecs.DocValuesProducer;
+import index.BinaryDocValues;
+import index.CorruptIndexException;
+import index.DocValues;
+import index.DocsAndPositionsEnum;
+import index.DocsEnum;
+import index.FieldInfo;
+import index.FieldInfos;
+import index.IndexFileNames;
+import index.NumericDocValues;
+import index.SegmentReadState;
+import index.SortedDocValues;
+import index.SortedSetDocValues;
+import index.TermsEnum;
+import store.ByteArrayDataInput;
+import store.ChecksumIndexInput;
+import store.IndexInput;
+import util.Bits;
+import util.BytesRef;
+import util.FixedBitSet;
+import util.IOUtils;
+import util.IntsRef;
+import util.PagedBytes;
+import util.RamUsageEstimator;
+import util.fst.BytesRefFSTEnum;
+import util.fst.BytesRefFSTEnum.InputOutput;
+import util.fst.FST;
+import util.fst.FST.Arc;
+import util.fst.FST.BytesReader;
+import util.fst.PositiveIntOutputs;
+import util.fst.Util;
+import util.packed.BlockPackedReader;
+import util.packed.MonotonicBlockPackedReader;
+import util.packed.PackedInts;
/**
* Reader for {@link MemoryDocValuesFormat}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
index ae5abca..90e4a53 100644
--- a/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.memory;
+package codecs.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,41 +25,41 @@ import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
-import org.apache.lucene.codecs.CodecUtil;
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.codecs.PostingsConsumer;
-import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.codecs.TermStats;
-import org.apache.lucene.codecs.TermsConsumer;
-import org.apache.lucene.index.DocsAndPositionsEnum;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.store.ByteArrayDataInput;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.store.RAMOutputStream;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.IntsRef;
-import org.apache.lucene.util.RamUsageEstimator;
-import org.apache.lucene.util.fst.Builder;
-import org.apache.lucene.util.fst.ByteSequenceOutputs;
-import org.apache.lucene.util.fst.BytesRefFSTEnum;
-import org.apache.lucene.util.fst.FST;
-import org.apache.lucene.util.fst.Util;
-import org.apache.lucene.util.packed.PackedInts;
+import codecs.CodecUtil;
+import codecs.FieldsConsumer;
+import codecs.FieldsProducer;
+import codecs.PostingsConsumer;
+import codecs.PostingsFormat;
+import codecs.TermStats;
+import codecs.TermsConsumer;
+import index.DocsAndPositionsEnum;
+import index.DocsEnum;
+import index.FieldInfo.IndexOptions;
+import index.FieldInfo;
+import index.FieldInfos;
+import index.IndexFileNames;
+import index.SegmentReadState;
+import index.SegmentWriteState;
+import index.Terms;
+import index.TermsEnum;
+import store.ByteArrayDataInput;
+import store.ChecksumIndexInput;
+import store.IOContext;
+import store.IndexInput;
+import store.IndexOutput;
+import store.RAMOutputStream;
+import util.ArrayUtil;
+import util.Bits;
+import util.BytesRef;
+import util.IOUtils;
+import util.IntsRef;
+import util.RamUsageEstimator;
+import util.fst.Builder;
+import util.fst.ByteSequenceOutputs;
+import util.fst.BytesRefFSTEnum;
+import util.fst.FST;
+import util.fst.Util;
+import util.packed.PackedInts;
// TODO: would be nice to somehow allow this to act like
// InstantiatedIndex, by never writing to disk; ie you write
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Sep/IntIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/IntIndexInput.cs b/src/Lucene.Net.Codecs/Sep/IntIndexInput.cs
index ebe0d27..057b25b 100644
--- a/src/Lucene.Net.Codecs/Sep/IntIndexInput.cs
+++ b/src/Lucene.Net.Codecs/Sep/IntIndexInput.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.sep;
+package codecs.sep;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,7 +20,7 @@ package org.apache.lucene.codecs.sep;
import java.io.Closeable;
import java.io.IOException;
-import org.apache.lucene.store.DataInput;
+import store.DataInput;
/** Defines basic API for writing ints to an IndexOutput.
* IntBlockCodec interacts with this API. @see
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs b/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
index 3f608d5..b5fe3f9 100644
--- a/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
+++ b/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.sep;
+package codecs.sep;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,7 +20,7 @@ package org.apache.lucene.codecs.sep;
// TODO: we may want tighter integration w/ IndexOutput --
// may give better perf:
-import org.apache.lucene.store.DataOutput;
+import store.DataOutput;
import java.io.IOException;
import java.io.Closeable;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Sep/IntStreamFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/IntStreamFactory.cs b/src/Lucene.Net.Codecs/Sep/IntStreamFactory.cs
index a6d42ba..8e23a76 100644
--- a/src/Lucene.Net.Codecs/Sep/IntStreamFactory.cs
+++ b/src/Lucene.Net.Codecs/Sep/IntStreamFactory.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.sep;
+package codecs.sep;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -17,8 +17,8 @@ package org.apache.lucene.codecs.sep;
* limitations under the License.
*/
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
+import store.Directory;
+import store.IOContext;
import java.io.IOException;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Sep/SepPostingsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/SepPostingsReader.cs b/src/Lucene.Net.Codecs/Sep/SepPostingsReader.cs
index 3aa45fa..e7b09e4 100644
--- a/src/Lucene.Net.Codecs/Sep/SepPostingsReader.cs
+++ b/src/Lucene.Net.Codecs/Sep/SepPostingsReader.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.sep;
+package codecs.sep;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,26 +19,26 @@ package org.apache.lucene.codecs.sep;
import java.io.IOException;
-import org.apache.lucene.codecs.BlockTermState;
-import org.apache.lucene.codecs.CodecUtil;
-import org.apache.lucene.codecs.PostingsReaderBase;
-import org.apache.lucene.index.DocsAndPositionsEnum;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.index.TermState;
-import org.apache.lucene.store.ByteArrayDataInput;
-import org.apache.lucene.store.DataInput;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-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.IOUtils;
+import codecs.BlockTermState;
+import codecs.CodecUtil;
+import codecs.PostingsReaderBase;
+import index.DocsAndPositionsEnum;
+import index.DocsEnum;
+import index.FieldInfo.IndexOptions;
+import index.FieldInfo;
+import index.FieldInfos;
+import index.IndexFileNames;
+import index.SegmentInfo;
+import index.TermState;
+import store.ByteArrayDataInput;
+import store.DataInput;
+import store.Directory;
+import store.IOContext;
+import store.IndexInput;
+import util.ArrayUtil;
+import util.Bits;
+import util.BytesRef;
+import util.IOUtils;
/** Concrete class that reads the current doc/freq/skip
* postings format.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs b/src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs
index ced150e..eba7022 100644
--- a/src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs
+++ b/src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.sep;
+package codecs.sep;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,20 +19,20 @@ package org.apache.lucene.codecs.sep;
import java.io.IOException;
-import org.apache.lucene.codecs.BlockTermState;
-import org.apache.lucene.codecs.CodecUtil;
-import org.apache.lucene.codecs.PostingsWriterBase;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.store.DataOutput;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.store.RAMOutputStream;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
+import codecs.BlockTermState;
+import codecs.CodecUtil;
+import codecs.PostingsWriterBase;
+import index.CorruptIndexException;
+import index.DocsEnum;
+import index.FieldInfo;
+import index.FieldInfo.IndexOptions;
+import index.IndexFileNames;
+import index.SegmentWriteState;
+import store.DataOutput;
+import store.IndexOutput;
+import store.RAMOutputStream;
+import util.BytesRef;
+import util.IOUtils;
/** Writes frq to .frq, docs to .doc, pos to .pos, payloads
* to .pyl, skip data to .skp
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs b/src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs
index df6dda1..aee9180 100644
--- a/src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs
+++ b/src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.sep;
+package codecs.sep;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,9 +20,9 @@ package org.apache.lucene.codecs.sep;
import java.io.IOException;
import java.util.Arrays;
-import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.codecs.MultiLevelSkipListReader;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
+import store.IndexInput;
+import codecs.MultiLevelSkipListReader;
+import index.FieldInfo.IndexOptions;
/**
* Implements the skip list reader for the default posting list format
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs b/src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs
index 7ace983..b4ba4cf 100644
--- a/src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs
+++ b/src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.sep;
+package codecs.sep;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,9 +20,9 @@ package org.apache.lucene.codecs.sep;
import java.io.IOException;
import java.util.Arrays;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.codecs.MultiLevelSkipListWriter;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
+import store.IndexOutput;
+import codecs.MultiLevelSkipListWriter;
+import index.FieldInfo.IndexOptions;
// TODO: -- skip data should somehow be more local to the
// particular stream (doc, freq, pos, payload)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextCodec.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextCodec.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextCodec.cs
index a26ed0e..d173137 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextCodec.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextCodec.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,73 +15,70 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import org.apache.lucene.codecs.Codec;
-import org.apache.lucene.codecs.FieldInfosFormat;
-import org.apache.lucene.codecs.LiveDocsFormat;
-import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.codecs.SegmentInfoFormat;
-import org.apache.lucene.codecs.DocValuesFormat;
-import org.apache.lucene.codecs.NormsFormat;
-import org.apache.lucene.codecs.StoredFieldsFormat;
-import org.apache.lucene.codecs.TermVectorsFormat;
+namespace Lucene.Net.Codecs.SimpleText
+{
-/**
- * plain text index format.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public final class SimpleTextCodec extends Codec {
- private final PostingsFormat postings = new SimpleTextPostingsFormat();
- private final StoredFieldsFormat storedFields = new SimpleTextStoredFieldsFormat();
- private final SegmentInfoFormat segmentInfos = new SimpleTextSegmentInfoFormat();
- private final FieldInfosFormat fieldInfosFormat = new SimpleTextFieldInfosFormat();
- private final TermVectorsFormat vectorsFormat = new SimpleTextTermVectorsFormat();
- private final NormsFormat normsFormat = new SimpleTextNormsFormat();
- private final LiveDocsFormat liveDocs = new SimpleTextLiveDocsFormat();
- private final DocValuesFormat dvFormat = new SimpleTextDocValuesFormat();
-
- public SimpleTextCodec() {
- super("SimpleText");
- }
-
- @Override
- public PostingsFormat postingsFormat() {
- return postings;
- }
+ /// <summary>
+ /// plain text index format.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public sealed class SimpleTextCodec : Codec
+ {
+ private readonly PostingsFormat _postings = new SimpleTextPostingsFormat();
+ private readonly StoredFieldsFormat _storedFields = new SimpleTextStoredFieldsFormat();
+ private readonly SegmentInfoFormat _segmentInfos = new SimpleTextSegmentInfoFormat();
+ private readonly FieldInfosFormat _fieldInfosFormatRenamed = new SimpleTextFieldInfosFormat();
+ private readonly TermVectorsFormat _vectorsFormat = new SimpleTextTermVectorsFormat();
+ private readonly NormsFormat _normsFormatRenamed = new SimpleTextNormsFormat();
+ private readonly LiveDocsFormat _liveDocs = new SimpleTextLiveDocsFormat();
+ private readonly DocValuesFormat _dvFormat = new SimpleTextDocValuesFormat();
+
+ public SimpleTextCodec() : base("SimpleText")
+ {
+ }
+
+ public override PostingsFormat PostingsFormat()
+ {
+ return _postings;
+ }
+
+ public override StoredFieldsFormat StoredFieldsFormat()
+ {
+ return _storedFields;
+ }
+
+ public override TermVectorsFormat TermVectorsFormat()
+ {
+ return _vectorsFormat;
+ }
+
+ public override FieldInfosFormat FieldInfosFormat()
+ {
+ return _fieldInfosFormatRenamed;
+ }
+
+ public override SegmentInfoFormat SegmentInfoFormat()
+ {
+ return _segmentInfos;
+ }
- @Override
- public StoredFieldsFormat storedFieldsFormat() {
- return storedFields;
- }
-
- @Override
- public TermVectorsFormat termVectorsFormat() {
- return vectorsFormat;
- }
-
- @Override
- public FieldInfosFormat fieldInfosFormat() {
- return fieldInfosFormat;
- }
+ public override NormsFormat NormsFormat()
+ {
+ return _normsFormatRenamed;
+ }
- @Override
- public SegmentInfoFormat segmentInfoFormat() {
- return segmentInfos;
- }
+ public override LiveDocsFormat LiveDocsFormat()
+ {
+ return _liveDocs;
+ }
- @Override
- public NormsFormat normsFormat() {
- return normsFormat;
- }
-
- @Override
- public LiveDocsFormat liveDocsFormat() {
- return liveDocs;
- }
+ public override DocValuesFormat DocValuesFormat()
+ {
+ return _dvFormat;
+ }
+ }
- @Override
- public DocValuesFormat docValuesFormat() {
- return dvFormat;
- }
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesFormat.cs
index 83dd776..fdbda1d 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesFormat.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,121 +15,124 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import java.io.IOException;
+namespace Lucene.Net.Codecs.SimpleText
+{
-import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.codecs.DocValuesProducer;
-import org.apache.lucene.codecs.DocValuesFormat;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
+ using SegmentReadState = Index.SegmentReadState;
+ using SegmentWriteState = Index.SegmentWriteState;
-/**
- * plain text doc values format.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * <p>
- * the .dat file contains the data.
- * for numbers this is a "fixed-width" file, for example a single byte range:
- * <pre>
- * field myField
- * type NUMERIC
- * minvalue 0
- * pattern 000
- * 005
- * T
- * 234
- * T
- * 123
- * T
- * ...
- * </pre>
- * so a document's value (delta encoded from minvalue) can be retrieved by
- * seeking to startOffset + (1+pattern.length()+2)*docid. The extra 1 is the newline.
- * The extra 2 is another newline and 'T' or 'F': true if the value is real, false if missing.
- *
- * for bytes this is also a "fixed-width" file, for example:
- * <pre>
- * field myField
- * type BINARY
- * maxlength 6
- * pattern 0
- * length 6
- * foobar[space][space]
- * T
- * length 3
- * baz[space][space][space][space][space]
- * T
- * ...
- * </pre>
- * so a doc's value can be retrieved by seeking to startOffset + (9+pattern.length+maxlength+2)*doc
- * the extra 9 is 2 newlines, plus "length " itself.
- * the extra 2 is another newline and 'T' or 'F': true if the value is real, false if missing.
- *
- * for sorted bytes this is a fixed-width file, for example:
- * <pre>
- * field myField
- * type SORTED
- * numvalues 10
- * maxLength 8
- * pattern 0
- * ordpattern 00
- * length 6
- * foobar[space][space]
- * length 3
- * baz[space][space][space][space][space]
- * ...
- * 03
- * 06
- * 01
- * 10
- * ...
- * </pre>
- * so the "ord section" begins at startOffset + (9+pattern.length+maxlength)*numValues.
- * a document's ord can be retrieved by seeking to "ord section" + (1+ordpattern.length())*docid
- * an ord's value can be retrieved by seeking to startOffset + (9+pattern.length+maxlength)*ord
- *
- * for sorted set this is a fixed-width file very similar to the SORTED case, for example:
- * <pre>
- * field myField
- * type SORTED_SET
- * numvalues 10
- * maxLength 8
- * pattern 0
- * ordpattern XXXXX
- * length 6
- * foobar[space][space]
- * length 3
- * baz[space][space][space][space][space]
- * ...
- * 0,3,5
- * 1,2
- *
- * 10
- * ...
- * </pre>
- * so the "ord section" begins at startOffset + (9+pattern.length+maxlength)*numValues.
- * a document's ord list can be retrieved by seeking to "ord section" + (1+ordpattern.length())*docid
- * this is a comma-separated list, and its padded with spaces to be fixed width. so trim() and split() it.
- * and beware the empty string!
- * an ord's value can be retrieved by seeking to startOffset + (9+pattern.length+maxlength)*ord
- *
- * the reader can just scan this file when it opens, skipping over the data blocks
- * and saving the offset/etc for each field.
- * @lucene.experimental
- */
-public class SimpleTextDocValuesFormat extends DocValuesFormat {
-
- public SimpleTextDocValuesFormat() {
- super("SimpleText");
- }
+ /// <summary>
+ /// plain text doc values format.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// </para>
+ /// <para>
+ /// the .dat file contains the data.
+ /// for numbers this is a "fixed-width" file, for example a single byte range:
+ /// <pre>
+ /// field myField
+ /// type NUMERIC
+ /// minvalue 0
+ /// pattern 000
+ /// 005
+ /// T
+ /// 234
+ /// T
+ /// 123
+ /// T
+ /// ...
+ /// </pre>
+ /// so a document's value (delta encoded from minvalue) can be retrieved by
+ /// seeking to startOffset + (1+pattern.length()+2)*docid. The extra 1 is the newline.
+ /// The extra 2 is another newline and 'T' or 'F': true if the value is real, false if missing.
+ ///
+ /// for bytes this is also a "fixed-width" file, for example:
+ /// <pre>
+ /// field myField
+ /// type BINARY
+ /// maxlength 6
+ /// pattern 0
+ /// length 6
+ /// foobar[space][space]
+ /// T
+ /// length 3
+ /// baz[space][space][space][space][space]
+ /// T
+ /// ...
+ /// </pre>
+ /// so a doc's value can be retrieved by seeking to startOffset + (9+pattern.length+maxlength+2)*doc
+ /// the extra 9 is 2 newlines, plus "length " itself.
+ /// the extra 2 is another newline and 'T' or 'F': true if the value is real, false if missing.
+ ///
+ /// for sorted bytes this is a fixed-width file, for example:
+ /// <pre>
+ /// field myField
+ /// type SORTED
+ /// numvalues 10
+ /// maxLength 8
+ /// pattern 0
+ /// ordpattern 00
+ /// length 6
+ /// foobar[space][space]
+ /// length 3
+ /// baz[space][space][space][space][space]
+ /// ...
+ /// 03
+ /// 06
+ /// 01
+ /// 10
+ /// ...
+ /// </pre>
+ /// so the "ord section" begins at startOffset + (9+pattern.length+maxlength)*numValues.
+ /// a document's ord can be retrieved by seeking to "ord section" + (1+ordpattern.length())*docid
+ /// an ord's value can be retrieved by seeking to startOffset + (9+pattern.length+maxlength)*ord
+ ///
+ /// for sorted set this is a fixed-width file very similar to the SORTED case, for example:
+ /// <pre>
+ /// field myField
+ /// type SORTED_SET
+ /// numvalues 10
+ /// maxLength 8
+ /// pattern 0
+ /// ordpattern XXXXX
+ /// length 6
+ /// foobar[space][space]
+ /// length 3
+ /// baz[space][space][space][space][space]
+ /// ...
+ /// 0,3,5
+ /// 1,2
+ ///
+ /// 10
+ /// ...
+ /// </pre>
+ /// so the "ord section" begins at startOffset + (9+pattern.length+maxlength)*numValues.
+ /// a document's ord list can be retrieved by seeking to "ord section" + (1+ordpattern.length())*docid
+ /// this is a comma-separated list, and its padded with spaces to be fixed width. so trim() and split() it.
+ /// and beware the empty string!
+ /// an ord's value can be retrieved by seeking to startOffset + (9+pattern.length+maxlength)*ord
+ ///
+ /// the reader can just scan this file when it opens, skipping over the data blocks
+ /// and saving the offset/etc for each field.
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextDocValuesFormat : DocValuesFormat
+ {
+
+ public SimpleTextDocValuesFormat() : base("SimpleText")
+ {
+ }
+
+ public override DocValuesConsumer FieldsConsumer(SegmentWriteState state)
+ {
+ return new SimpleTextDocValuesWriter(state, "dat");
+ }
+ public override DocValuesProducer FieldsProducer(SegmentReadState state)
+ {
+ return new SimpleTextDocValuesReader(state, "dat");
+ }
- @Override
- public DocValuesConsumer fieldsConsumer(SegmentWriteState state) {
- return new SimpleTextDocValuesWriter(state, "dat");
- }
+ }
- @Override
- public DocValuesProducer fieldsProducer(SegmentReadState state) {
- return new SimpleTextDocValuesReader(state, "dat");
- }
-}
+}
\ No newline at end of file
[4/7] Cleanup of codes, mostly SimpleText in this commit
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
index b9be9f1..d7db938 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,175 +15,200 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import java.io.IOException;
-import java.util.Comparator;
-
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.PostingsConsumer;
-import org.apache.lucene.codecs.TermStats;
-import org.apache.lucene.codecs.TermsConsumer;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.BytesRef;
-
-class SimpleTextFieldsWriter extends FieldsConsumer {
-
- private IndexOutput out;
- private final BytesRef scratch = new BytesRef(10);
-
- final static BytesRef END = new BytesRef("END");
- final static BytesRef FIELD = new BytesRef("field ");
- final static BytesRef TERM = new BytesRef(" term ");
- final static BytesRef DOC = new BytesRef(" doc ");
- final static BytesRef FREQ = new BytesRef(" freq ");
- final static BytesRef POS = new BytesRef(" pos ");
- final static BytesRef START_OFFSET = new BytesRef(" startOffset ");
- final static BytesRef END_OFFSET = new BytesRef(" endOffset ");
- final static BytesRef PAYLOAD = new BytesRef(" payload ");
-
- public SimpleTextFieldsWriter(SegmentWriteState state) {
- final String fileName = SimpleTextPostingsFormat.getPostingsFileName(state.segmentInfo.name, state.segmentSuffix);
- out = state.directory.createOutput(fileName, state.context);
- }
-
- private void write(String s) {
- SimpleTextUtil.write(out, s, scratch);
- }
-
- private void write(BytesRef b) {
- SimpleTextUtil.write(out, b);
- }
-
- private void newline() {
- SimpleTextUtil.writeNewline(out);
- }
-
- @Override
- public TermsConsumer addField(FieldInfo field) {
- write(FIELD);
- write(field.name);
- newline();
- return new SimpleTextTermsWriter(field);
- }
-
- private class SimpleTextTermsWriter extends TermsConsumer {
- private final SimpleTextPostingsWriter postingsWriter;
-
- public SimpleTextTermsWriter(FieldInfo field) {
- postingsWriter = new SimpleTextPostingsWriter(field);
- }
-
- @Override
- public PostingsConsumer startTerm(BytesRef term) {
- return postingsWriter.reset(term);
- }
-
- @Override
- public void finishTerm(BytesRef term, TermStats stats) {
- }
-
- @Override
- public void finish(long sumTotalTermFreq, long sumDocFreq, int docCount) {
- }
-
- @Override
- public Comparator<BytesRef> getComparator() {
- return BytesRef.getUTF8SortedAsUnicodeComparator();
- }
- }
-
- private class SimpleTextPostingsWriter extends PostingsConsumer {
- private BytesRef term;
- private bool wroteTerm;
- private final IndexOptions indexOptions;
- private final bool writePositions;
- private final bool writeOffsets;
-
- // for Debug.Assert(:
- private int lastStartOffset = 0;
-
- public SimpleTextPostingsWriter(FieldInfo field) {
- this.indexOptions = field.getIndexOptions();
- writePositions = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
- writeOffsets = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
- //System.out.println("writeOffsets=" + writeOffsets);
- //System.out.println("writePos=" + writePositions);
- }
-
- @Override
- public void startDoc(int docID, int termDocFreq) {
- if (!wroteTerm) {
- // we lazily do this, in case the term had zero docs
- write(TERM);
- write(term);
- newline();
- wroteTerm = true;
- }
-
- write(DOC);
- write(Integer.toString(docID));
- newline();
- if (indexOptions != IndexOptions.DOCS_ONLY) {
- write(FREQ);
- write(Integer.toString(termDocFreq));
- newline();
- }
-
- lastStartOffset = 0;
- }
-
- public PostingsConsumer reset(BytesRef term) {
- this.term = term;
- wroteTerm = false;
- return this;
- }
+using System;
+using System.Diagnostics;
+using System.Collections.Generic;
+
+namespace Lucene.Net.Codecs.SimpleText
+{
+ using IndexOptions = Index.FieldInfo.IndexOptions;
+ using FieldInfo = Index.FieldInfo;
+ using SegmentWriteState = Index.SegmentWriteState;
+ using IndexOutput = Store.IndexOutput;
+ using BytesRef = Util.BytesRef;
+
+ internal class SimpleTextFieldsWriter : FieldsConsumer
+ {
+
+ private IndexOutput _output;
+ private readonly BytesRef _scratch = new BytesRef(10);
+
+ internal static readonly BytesRef END = new BytesRef("END");
+ internal static readonly BytesRef FIELD = new BytesRef("field ");
+ internal static readonly BytesRef TERM = new BytesRef(" term ");
+ internal static readonly BytesRef DOC = new BytesRef(" doc ");
+ internal static readonly BytesRef FREQ = new BytesRef(" freq ");
+ internal static readonly BytesRef POS = new BytesRef(" pos ");
+ internal static readonly BytesRef START_OFFSET = new BytesRef(" startOffset ");
+ internal static readonly BytesRef END_OFFSET = new BytesRef(" endOffset ");
+ internal static readonly BytesRef PAYLOAD = new BytesRef(" payload ");
+
+ public SimpleTextFieldsWriter(SegmentWriteState state)
+ {
+ var fileName = SimpleTextPostingsFormat.GetPostingsFileName(state.SegmentInfo.Name, state.SegmentSuffix);
+ _output = state.Directory.CreateOutput(fileName, state.Context);
+ }
+
+ private void Write(string s)
+ {
+ SimpleTextUtil.Write(_output, s, _scratch);
+ }
+
+ private void Write(BytesRef b)
+ {
+ SimpleTextUtil.Write(_output, b);
+ }
+
+ private void Newline()
+ {
+ SimpleTextUtil.WriteNewline(_output);
+ }
+
+ public override TermsConsumer AddField(FieldInfo field)
+ {
+ Write(FIELD);
+ Write(field.Name);
+ Newline();
+ return new SimpleTextTermsWriter(this, field);
+ }
+
+ public override void Dispose()
+ {
+ if (_output != null)
+ {
+ try
+ {
+ Write(END);
+ Newline();
+ SimpleTextUtil.WriteChecksum(_output, _scratch);
+ }
+ finally
+ {
+ _output.Dispose();
+ _output = null;
+ }
+ }
+ }
+
+ private class SimpleTextTermsWriter : TermsConsumer
+ {
+ private readonly SimpleTextFieldsWriter _outerInstance;
+ private readonly SimpleTextPostingsWriter _postingsWriter;
+
+ public SimpleTextTermsWriter(SimpleTextFieldsWriter outerInstance, FieldInfo field)
+ {
+ this._outerInstance = outerInstance;
+ _postingsWriter = new SimpleTextPostingsWriter(outerInstance, field);
+ }
+
+ public override PostingsConsumer StartTerm(BytesRef term)
+ {
+ return _postingsWriter.Reset(term);
+ }
+
+ public override void FinishTerm(BytesRef term, TermStats stats)
+ {
+ }
+
+ public override void Finish(long sumTotalTermFreq, long sumDocFreq, int docCount)
+ {
+ }
+
+ public override IComparer<BytesRef> Comparator
+ {
+ get { return BytesRef.UTF8SortedAsUnicodeComparer; }
+ }
+ }
+
+ private sealed class SimpleTextPostingsWriter : PostingsConsumer
+ {
+ private readonly SimpleTextFieldsWriter _outerInstance;
+
+ private BytesRef _term;
+ private bool _wroteTerm;
+ private readonly IndexOptions _indexOptions;
+ private readonly bool _writePositions;
+ private readonly bool _writeOffsets;
+
+ // for assert:
+ private int _lastStartOffset = 0;
+
+ public SimpleTextPostingsWriter(SimpleTextFieldsWriter outerInstance, FieldInfo field)
+ {
+ _outerInstance = outerInstance;
+ _indexOptions = field.FieldIndexOptions.Value;
+ _writePositions = _indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
+ _writeOffsets = _indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
+ }
+
+ public override void StartDoc(int docID, int termDocFreq)
+ {
+ if (!_wroteTerm)
+ {
+ // we lazily do this, in case the term had zero docs
+ _outerInstance.Write(TERM);
+ _outerInstance.Write(_term);
+ _outerInstance.Newline();
+ _wroteTerm = true;
+ }
+
+ _outerInstance.Write(DOC);
+ _outerInstance.Write(Convert.ToString(docID));
+ _outerInstance.Newline();
+ if (_indexOptions != IndexOptions.DOCS_ONLY)
+ {
+ _outerInstance.Write(FREQ);
+ _outerInstance.Write(Convert.ToString(termDocFreq));
+ _outerInstance.Newline();
+ }
+
+ _lastStartOffset = 0;
+ }
+
+ public PostingsConsumer Reset(BytesRef term)
+ {
+ this._term = term;
+ _wroteTerm = false;
+ return this;
+ }
+
+ public override void AddPosition(int position, BytesRef payload, int startOffset, int endOffset)
+ {
+ if (_writePositions)
+ {
+ _outerInstance.Write(POS);
+ _outerInstance.Write(Convert.ToString(position));
+ _outerInstance.Newline();
+ }
+
+ if (_writeOffsets)
+ {
+ Debug.Assert(endOffset >= startOffset);
+ Debug.Assert(startOffset >= _lastStartOffset,
+ "startOffset=" + startOffset + " lastStartOffset=" + _lastStartOffset);
+ _lastStartOffset = startOffset;
+ _outerInstance.Write(START_OFFSET);
+ _outerInstance.Write(Convert.ToString(startOffset));
+ _outerInstance.Newline();
+ _outerInstance.Write(END_OFFSET);
+ _outerInstance.Write(Convert.ToString(endOffset));
+ _outerInstance.Newline();
+ }
+
+ if (payload != null && payload.Length > 0)
+ {
+ Debug.Assert(payload.Length != 0);
+ _outerInstance.Write(PAYLOAD);
+ _outerInstance.Write(payload);
+ _outerInstance.Newline();
+ }
+ }
+
+ public override void FinishDoc()
+ {
+ }
+ }
- @Override
- public void addPosition(int position, BytesRef payload, int startOffset, int endOffset) {
- if (writePositions) {
- write(POS);
- write(Integer.toString(position));
- newline();
- }
-
- if (writeOffsets) {
- Debug.Assert( endOffset >= startOffset;
- Debug.Assert( startOffset >= lastStartOffset: "startOffset=" + startOffset + " lastStartOffset=" + lastStartOffset;
- lastStartOffset = startOffset;
- write(START_OFFSET);
- write(Integer.toString(startOffset));
- newline();
- write(END_OFFSET);
- write(Integer.toString(endOffset));
- newline();
- }
-
- if (payload != null && payload.length > 0) {
- Debug.Assert( payload.length != 0;
- write(PAYLOAD);
- write(payload);
- newline();
- }
}
- @Override
- public void finishDoc() {
- }
- }
-
- @Override
- public void close() {
- if (out != null) {
- try {
- write(END);
- newline();
- SimpleTextUtil.writeChecksum(out, scratch);
- } finally {
- out.close();
- out = null;
- }
- }
- }
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
index 55cbbe1..d5ec0b3 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
@@ -1,188 +1,215 @@
-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.BitSet;
-import java.util.Collection;
-
-import org.apache.lucene.codecs.LiveDocsFormat;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentCommitInfo;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.IndexOutput;
-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.IOUtils;
-import org.apache.lucene.util.MutableBits;
-import org.apache.lucene.util.StringHelper;
-import org.apache.lucene.util.UnicodeUtil;
-
-/**
- * reads/writes plaintext live docs
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextLiveDocsFormat extends LiveDocsFormat {
-
- static final String LIVEDOCS_EXTENSION = "liv";
-
- final static BytesRef SIZE = new BytesRef("size ");
- final static BytesRef DOC = new BytesRef(" doc ");
- final static BytesRef END = new BytesRef("END");
-
- @Override
- public MutableBits newLiveDocs(int size) {
- return new SimpleTextMutableBits(size);
- }
-
- @Override
- public MutableBits newLiveDocs(Bits existing) {
- final SimpleTextBits bits = (SimpleTextBits) existing;
- return new SimpleTextMutableBits((BitSet)bits.bits.clone(), bits.size);
- }
-
- @Override
- public Bits readLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context) {
- Debug.Assert( info.hasDeletions();
- BytesRef scratch = new BytesRef();
- CharsRef scratchUTF16 = new CharsRef();
-
- String fileName = IndexFileNames.fileNameFromGeneration(info.info.name, LIVEDOCS_EXTENSION, info.getDelGen());
- ChecksumIndexInput in = null;
- bool success = false;
- try {
- in = dir.openChecksumInput(fileName, context);
-
- SimpleTextUtil.readLine(in, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, SIZE);
- int size = parseIntAt(scratch, SIZE.length, scratchUTF16);
-
- BitSet bits = new BitSet(size);
-
- SimpleTextUtil.readLine(in, scratch);
- while (!scratch.equals(END)) {
- Debug.Assert( StringHelper.startsWith(scratch, DOC);
- int docid = parseIntAt(scratch, DOC.length, scratchUTF16);
- bits.set(docid);
- SimpleTextUtil.readLine(in, scratch);
- }
-
- SimpleTextUtil.checkFooter(in);
-
- success = true;
- return new SimpleTextBits(bits, size);
- } finally {
- if (success) {
- IOUtils.close(in);
- } else {
- IOUtils.closeWhileHandlingException(in);
- }
- }
- }
-
- private int parseIntAt(BytesRef bytes, int offset, CharsRef scratch) {
- UnicodeUtil.UTF8toUTF16(bytes.bytes, bytes.offset+offset, bytes.length-offset, scratch);
- return ArrayUtil.parseInt(scratch.chars, 0, scratch.length);
- }
-
- @Override
- public void writeLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context) {
- BitSet set = ((SimpleTextBits) bits).bits;
- int size = bits.length();
- BytesRef scratch = new BytesRef();
-
- String fileName = IndexFileNames.fileNameFromGeneration(info.info.name, LIVEDOCS_EXTENSION, info.getNextDelGen());
- IndexOutput out = null;
- bool success = false;
- try {
- out = dir.createOutput(fileName, context);
- SimpleTextUtil.write(out, SIZE);
- SimpleTextUtil.write(out, Integer.toString(size), scratch);
- SimpleTextUtil.writeNewline(out);
-
- for (int i = set.nextSetBit(0); i >= 0; i=set.nextSetBit(i + 1)) {
- SimpleTextUtil.write(out, DOC);
- SimpleTextUtil.write(out, Integer.toString(i), scratch);
- SimpleTextUtil.writeNewline(out);
- }
-
- SimpleTextUtil.write(out, END);
- SimpleTextUtil.writeNewline(out);
- SimpleTextUtil.writeChecksum(out, scratch);
- success = true;
- } finally {
- if (success) {
- IOUtils.close(out);
- } else {
- IOUtils.closeWhileHandlingException(out);
- }
- }
- }
+/*
+* 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.
+*/
- @Override
- public void files(SegmentCommitInfo info, Collection<String> files) {
- if (info.hasDeletions()) {
- files.add(IndexFileNames.fileNameFromGeneration(info.info.name, LIVEDOCS_EXTENSION, info.getDelGen()));
- }
- }
-
- // read-only
- static class SimpleTextBits implements Bits {
- final BitSet bits;
- final int size;
-
- SimpleTextBits(BitSet bits, int size) {
- this.bits = bits;
- this.size = size;
- }
-
- @Override
- public bool get(int index) {
- return bits.get(index);
- }
+namespace Lucene.Net.Codecs.SimpleText
+{
- @Override
- public int length() {
- return size;
- }
- }
-
- // read-write
- static class SimpleTextMutableBits extends SimpleTextBits implements MutableBits {
-
- SimpleTextMutableBits(int size) {
- this(new BitSet(size), size);
- bits.set(0, size);
- }
-
- SimpleTextMutableBits(BitSet bits, int size) {
- super(bits, size);
- }
-
- @Override
- public void clear(int bit) {
- bits.clear(bit);
+ using System;
+ using System.Diagnostics;
+ using System.Collections;
+ using System.Collections.Generic;
+ using Support;
+
+ using IndexFileNames = Index.IndexFileNames;
+ using SegmentCommitInfo = Index.SegmentCommitInfo;
+ using ChecksumIndexInput = Store.ChecksumIndexInput;
+ using Directory = Store.Directory;
+ using IOContext = Store.IOContext;
+ using IndexOutput = Store.IndexOutput;
+ using ArrayUtil = Util.ArrayUtil;
+ using Bits = Util.Bits;
+ using BytesRef = Util.BytesRef;
+ using CharsRef = Util.CharsRef;
+ using IOUtils = Util.IOUtils;
+ using MutableBits = Util.MutableBits;
+ using StringHelper = Util.StringHelper;
+ using UnicodeUtil = Util.UnicodeUtil;
+
+ /// <summary>
+ /// reads/writes plaintext live docs
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextLiveDocsFormat : LiveDocsFormat
+ {
+
+ internal const string LIVEDOCS_EXTENSION = "liv";
+
+ internal static readonly BytesRef SIZE = new BytesRef("size ");
+ internal static readonly BytesRef DOC = new BytesRef(" doc ");
+ internal static readonly BytesRef END = new BytesRef("END");
+
+ public override MutableBits NewLiveDocs(int size)
+ {
+ return new SimpleTextMutableBits(size);
+ }
+
+ public override MutableBits NewLiveDocs(Bits existing)
+ {
+ var bits = (SimpleTextBits) existing;
+ return new SimpleTextMutableBits((BitArray) bits.BITS.Clone(), bits.SIZE);
+ }
+
+ public override Bits ReadLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context)
+ {
+ Debug.Assert(info.HasDeletions());
+ var scratch = new BytesRef();
+ var scratchUtf16 = new CharsRef();
+
+ var fileName = IndexFileNames.FileNameFromGeneration(info.Info.Name, LIVEDOCS_EXTENSION, info.DelGen);
+ ChecksumIndexInput input = null;
+ var success = false;
+
+ try
+ {
+ input = dir.OpenChecksumInput(fileName, context);
+
+ SimpleTextUtil.ReadLine(input, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, SIZE));
+ var size = ParseIntAt(scratch, SIZE.Length, scratchUtf16);
+
+ var bits = new BitArray(size);
+
+ SimpleTextUtil.ReadLine(input, scratch);
+ while (!scratch.Equals(END))
+ {
+ Debug.Assert(StringHelper.StartsWith(scratch, DOC));
+ var docid = ParseIntAt(scratch, DOC.Length, scratchUtf16);
+ bits.Set(docid, true);
+ SimpleTextUtil.ReadLine(input, scratch);
+ }
+
+ SimpleTextUtil.CheckFooter(input);
+
+ success = true;
+ return new SimpleTextBits(bits, size);
+ }
+ finally
+ {
+ if (success)
+ {
+ IOUtils.Close(input);
+ }
+ else
+ {
+ IOUtils.CloseWhileHandlingException(input);
+ }
+ }
+ }
+
+ private static int ParseIntAt(BytesRef bytes, int offset, CharsRef scratch)
+ {
+ UnicodeUtil.UTF8toUTF16(bytes.Bytes, bytes.Offset + offset, bytes.Length - offset, scratch);
+ return ArrayUtil.ParseInt(scratch.Chars, 0, scratch.length);
+ }
+
+ public override void WriteLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount,
+ IOContext context)
+ {
+ var set = ((SimpleTextBits) bits).BITS;
+ var size = bits.Length();
+ var scratch = new BytesRef();
+
+ var fileName = IndexFileNames.FileNameFromGeneration(info.Info.Name, LIVEDOCS_EXTENSION, info.NextDelGen);
+ IndexOutput output = null;
+ var success = false;
+ try
+ {
+ output = dir.CreateOutput(fileName, context);
+ SimpleTextUtil.Write(output, SIZE);
+ SimpleTextUtil.Write(output, Convert.ToString(size), scratch);
+ SimpleTextUtil.WriteNewline(output);
+
+ for (int i = set.NextSetBit(0); i >= 0; i = set.NextSetBit(i + 1))
+ {
+ SimpleTextUtil.Write(output, DOC);
+ SimpleTextUtil.Write(output, Convert.ToString(i), scratch);
+ SimpleTextUtil.WriteNewline(output);
+ }
+
+ SimpleTextUtil.Write(output, END);
+ SimpleTextUtil.WriteNewline(output);
+ SimpleTextUtil.WriteChecksum(output, scratch);
+ success = true;
+ }
+ finally
+ {
+ if (success)
+ {
+ IOUtils.Close(output);
+ }
+ else
+ {
+ IOUtils.CloseWhileHandlingException(output);
+ }
+ }
+ }
+
+ public override void Files(SegmentCommitInfo info, ICollection<string> files)
+ {
+ if (info.HasDeletions())
+ {
+ files.Add(IndexFileNames.FileNameFromGeneration(info.Info.Name, LIVEDOCS_EXTENSION, info.DelGen));
+ }
+ }
+
+ // read-only
+ internal class SimpleTextBits : Bits
+ {
+ internal readonly BitArray BITS;
+ internal readonly int SIZE;
+
+ internal SimpleTextBits(BitArray bits, int size)
+ {
+ BITS = bits;
+ SIZE = size;
+ }
+
+ public bool Get(int index)
+ {
+ return BITS.Get(index);
+ }
+
+ public int Length()
+ {
+ return SIZE;
+ }
+ }
+
+ // read-write
+ internal class SimpleTextMutableBits : SimpleTextBits, MutableBits
+ {
+
+ internal SimpleTextMutableBits(int size) : this(new BitArray(size), size)
+ {
+ BITS.Set(0, size);
+ }
+
+ internal SimpleTextMutableBits(BitArray bits, int size) : base(bits, size)
+ {
+ }
+
+ public void Clear(int bit)
+ {
+ BITS.Set(bit, false);
+ }
+ }
}
- }
-}
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextNormsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextNormsFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextNormsFormat.cs
index 0f7c3a3..75a0ccc 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextNormsFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextNormsFormat.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,61 +15,67 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import java.io.IOException;
+namespace Lucene.Net.Codecs.SimpleText
+{
-import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.codecs.DocValuesProducer;
-import org.apache.lucene.codecs.NormsFormat;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
+ using SegmentReadState = Index.SegmentReadState;
+ using SegmentWriteState = Index.SegmentWriteState;
-/**
- * plain-text norms format.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- *
- * @lucene.experimental
- */
-public class SimpleTextNormsFormat extends NormsFormat {
- private static final String NORMS_SEG_EXTENSION = "len";
-
- @Override
- public DocValuesConsumer normsConsumer(SegmentWriteState state) {
- return new SimpleTextNormsConsumer(state);
- }
-
- @Override
- public DocValuesProducer normsProducer(SegmentReadState state) {
- return new SimpleTextNormsProducer(state);
- }
-
- /**
- * Reads plain-text norms.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- *
- * @lucene.experimental
- */
- public static class SimpleTextNormsProducer extends SimpleTextDocValuesReader {
- public SimpleTextNormsProducer(SegmentReadState state) {
- // All we do is change the extension from .dat -> .len;
- // otherwise this is a normal simple doc values file:
- super(state, NORMS_SEG_EXTENSION);
- }
- }
-
- /**
- * Writes plain-text norms.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- *
- * @lucene.experimental
- */
- public static class SimpleTextNormsConsumer extends SimpleTextDocValuesWriter {
- public SimpleTextNormsConsumer(SegmentWriteState state) {
- // All we do is change the extension from .dat -> .len;
- // otherwise this is a normal simple doc values file:
- super(state, NORMS_SEG_EXTENSION);
+ /// <summary>
+ /// plain-text norms format.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ ///
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextNormsFormat : NormsFormat
+ {
+ private const string NORMS_SEG_EXTENSION = "len";
+
+ public override DocValuesConsumer NormsConsumer(SegmentWriteState state)
+ {
+ return new SimpleTextNormsConsumer(state);
+ }
+
+ public override DocValuesProducer NormsProducer(SegmentReadState state)
+ {
+ return new SimpleTextNormsProducer(state);
+ }
+
+ /// <summary>
+ /// Reads plain-text norms.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ ///
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextNormsProducer : SimpleTextDocValuesReader
+ {
+ public SimpleTextNormsProducer(SegmentReadState state) : base(state, NORMS_SEG_EXTENSION)
+ {
+ // All we do is change the extension from .dat -> .len;
+ // otherwise this is a normal simple doc values file:
+ }
+ }
+
+ /// <summary>
+ /// Writes plain-text norms.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ ///
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextNormsConsumer : SimpleTextDocValuesWriter
+ {
+ public SimpleTextNormsConsumer(SegmentWriteState state) : base(state, NORMS_SEG_EXTENSION)
+ {
+ // All we do is change the extension from .dat -> .len;
+ // otherwise this is a normal simple doc values file:
+ }
+ }
}
- }
-}
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextPostingsFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextPostingsFormat.cs
index 5e2c782..0027065 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextPostingsFormat.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,43 +15,49 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import java.io.IOException;
-
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.IndexFileNames;
-
-/** For debugging, curiosity, transparency only!! Do not
- * use this codec in production.
- *
- * <p>This codec stores all postings data in a single
- * human-readable text file (_N.pst). You can view this in
- * any text editor, and even edit it to alter your index.
- *
- * @lucene.experimental */
-public final class SimpleTextPostingsFormat extends PostingsFormat {
-
- public SimpleTextPostingsFormat() {
- super("SimpleText");
- }
-
- @Override
- public FieldsConsumer fieldsConsumer(SegmentWriteState state) {
- return new SimpleTextFieldsWriter(state);
- }
-
- @Override
- public FieldsProducer fieldsProducer(SegmentReadState state) {
- return new SimpleTextFieldsReader(state);
- }
-
- /** Extension of freq postings file */
- static final String POSTINGS_EXTENSION = "pst";
-
- static String getPostingsFileName(String segment, String segmentSuffix) {
- return IndexFileNames.segmentFileName(segment, segmentSuffix, POSTINGS_EXTENSION);
- }
-}
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+ using SegmentWriteState = Index.SegmentWriteState;
+ using SegmentReadState = Index.SegmentReadState;
+ using IndexFileNames = Index.IndexFileNames;
+
+ /// <summary>
+ /// For debugging, curiosity, transparency only!! Do not
+ /// use this codec in production.
+ ///
+ /// <para>This codec stores all postings data in a single
+ /// human-readable text file (_N.pst). You can view this in
+ /// any text editor, and even edit it to alter your index.
+ ///
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public sealed class SimpleTextPostingsFormat : PostingsFormat
+ {
+
+ /// <summary>
+ /// Extension of freq postings file </summary>
+ internal const string POSTINGS_EXTENSION = "pst";
+
+ public SimpleTextPostingsFormat() : base("SimpleText")
+ {
+ }
+
+ public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
+ {
+ return new SimpleTextFieldsWriter(state);
+ }
+
+ public override FieldsProducer FieldsProducer(SegmentReadState state)
+ {
+ return new SimpleTextFieldsReader(state);
+ }
+
+ internal static string GetPostingsFileName(string segment, string segmentSuffix)
+ {
+ return IndexFileNames.SegmentFileName(segment, segmentSuffix, POSTINGS_EXTENSION);
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoFormat.cs
index 53440e7..11c4940 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoFormat.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,29 +15,33 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import org.apache.lucene.codecs.SegmentInfoFormat;
-import org.apache.lucene.codecs.SegmentInfoReader;
-import org.apache.lucene.codecs.SegmentInfoWriter;
+namespace Lucene.Net.Codecs.SimpleText
+{
-/**
- * plain text segments file format.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {
- private final SegmentInfoReader reader = new SimpleTextSegmentInfoReader();
- private final SegmentInfoWriter writer = new SimpleTextSegmentInfoWriter();
+ /// <summary>
+ /// plain text segments file format.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextSegmentInfoFormat : SegmentInfoFormat
+ {
+ private readonly SegmentInfoReader _reader = new SimpleTextSegmentInfoReader();
+ private readonly SegmentInfoWriter _writer = new SimpleTextSegmentInfoWriter();
+
+ public const string SI_EXTENSION = "si";
+
+ public override SegmentInfoReader SegmentInfoReader
+ {
+ get { return _reader; }
+ }
+
+ public override SegmentInfoWriter SegmentInfoWriter
+ {
+ get { return _writer; }
+ }
- public static final String SI_EXTENSION = "si";
-
- @Override
- public SegmentInfoReader getSegmentInfoReader() {
- return reader;
- }
+ }
- @Override
- public SegmentInfoWriter getSegmentInfoWriter() {
- return writer;
- }
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoReader.cs
index cd87509..f67b9b2 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoReader.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,104 +15,125 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_DIAG_KEY;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_DIAG_VALUE;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_DOCCOUNT;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_FILE;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_NUM_DIAG;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_NUM_FILES;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_USECOMPOUND;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_VERSION;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.lucene.codecs.SegmentInfoReader;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-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;
-
-/**
- * reads plaintext segments files
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextSegmentInfoReader extends SegmentInfoReader {
-
- @Override
- public SegmentInfo read(Directory directory, String segmentName, IOContext context) {
- BytesRef scratch = new BytesRef();
- String segFileName = IndexFileNames.segmentFileName(segmentName, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);
- ChecksumIndexInput input = directory.openChecksumInput(segFileName, context);
- bool success = false;
- try {
- SimpleTextUtil.readLine(input, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, SI_VERSION);
- final String version = readString(SI_VERSION.length, scratch);
-
- SimpleTextUtil.readLine(input, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, SI_DOCCOUNT);
- final int docCount = Integer.parseInt(readString(SI_DOCCOUNT.length, scratch));
-
- SimpleTextUtil.readLine(input, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, SI_USECOMPOUND);
- final bool isCompoundFile = bool.parsebool(readString(SI_USECOMPOUND.length, scratch));
-
- SimpleTextUtil.readLine(input, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, SI_NUM_DIAG);
- int numDiag = Integer.parseInt(readString(SI_NUM_DIAG.length, scratch));
- Map<String,String> diagnostics = new HashMap<>();
-
- for (int i = 0; i < numDiag; i++) {
- SimpleTextUtil.readLine(input, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, SI_DIAG_KEY);
- String key = readString(SI_DIAG_KEY.length, scratch);
-
- SimpleTextUtil.readLine(input, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, SI_DIAG_VALUE);
- String value = readString(SI_DIAG_VALUE.length, scratch);
- diagnostics.put(key, value);
- }
-
- SimpleTextUtil.readLine(input, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, SI_NUM_FILES);
- int numFiles = Integer.parseInt(readString(SI_NUM_FILES.length, scratch));
- Set<String> files = new HashSet<>();
-
- for (int i = 0; i < numFiles; i++) {
- SimpleTextUtil.readLine(input, scratch);
- Debug.Assert( StringHelper.startsWith(scratch, SI_FILE);
- String fileName = readString(SI_FILE.length, scratch);
- files.add(fileName);
- }
-
- SimpleTextUtil.checkFooter(input);
-
- SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount,
- isCompoundFile, null, diagnostics);
- info.setFiles(files);
- success = true;
- return info;
- } finally {
- if (!success) {
- IOUtils.closeWhileHandlingException(input);
- } else {
- input.close();
- }
- }
- }
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_DIAG_KEY;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_DIAG_VALUE;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_DOCCOUNT;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_FILE;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_NUM_DIAG;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_NUM_FILES;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_USECOMPOUND;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+// import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_VERSION;
+
+
+ using System;
+ using System.Diagnostics;
+ using System.Collections.Generic;
+
+ using IndexFileNames = Index.IndexFileNames;
+ using SegmentInfo = Index.SegmentInfo;
+ using ChecksumIndexInput = Store.ChecksumIndexInput;
+ using Directory = Store.Directory;
+ using IOContext = Store.IOContext;
+ using BytesRef = Util.BytesRef;
+ using IOUtils = Util.IOUtils;
+ using StringHelper = Util.StringHelper;
+
+ /// <summary>
+ /// reads plaintext segments files
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextSegmentInfoReader : SegmentInfoReader
+ {
+
+ public override SegmentInfo Read(Directory directory, string segmentName, IOContext context)
+ {
+ BytesRef scratch = new BytesRef();
+ string segFileName = IndexFileNames.SegmentFileName(segmentName, "",
+ SimpleTextSegmentInfoFormat.SI_EXTENSION);
+ ChecksumIndexInput input = directory.OpenChecksumInput(segFileName, context);
+ bool success = false;
+ try
+ {
+ SimpleTextUtil.ReadLine(input, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, SI_VERSION));
+ string version = ReadString(SI_VERSION.length, scratch);
+
+ SimpleTextUtil.ReadLine(input, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, SI_DOCCOUNT));
+ int docCount = Convert.ToInt32(ReadString(SI_DOCCOUNT.length, scratch));
- private String readString(int offset, BytesRef scratch) {
- return new String(scratch.bytes, scratch.offset+offset, scratch.length-offset, StandardCharsets.UTF_8);
- }
-}
+ SimpleTextUtil.ReadLine(input, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, SI_USECOMPOUND));
+ bool isCompoundFile = Convert.ToBoolean(ReadString(SI_USECOMPOUND.length, scratch));
+
+ SimpleTextUtil.ReadLine(input, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, SI_NUM_DIAG));
+ int numDiag = Convert.ToInt32(ReadString(SI_NUM_DIAG.length, scratch));
+ IDictionary<string, string> diagnostics = new Dictionary<string, string>();
+
+ for (int i = 0; i < numDiag; i++)
+ {
+ SimpleTextUtil.ReadLine(input, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, SI_DIAG_KEY));
+ string key = ReadString(SI_DIAG_KEY.length, scratch);
+
+ SimpleTextUtil.ReadLine(input, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, SI_DIAG_VALUE));
+ string value = ReadString(SI_DIAG_VALUE.length, scratch);
+ diagnostics[key] = value;
+ }
+
+ SimpleTextUtil.ReadLine(input, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, SI_NUM_FILES));
+ int numFiles = Convert.ToInt32(ReadString(SI_NUM_FILES.length, scratch));
+ HashSet<string> files = new HashSet<string>();
+
+ for (int i = 0; i < numFiles; i++)
+ {
+ SimpleTextUtil.ReadLine(input, scratch);
+ Debug.Assert(StringHelper.StartsWith(scratch, SI_FILE));
+ string fileName = ReadString(SI_FILE.length, scratch);
+ files.Add(fileName);
+ }
+
+ SimpleTextUtil.CheckFooter(input);
+
+ SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount, isCompoundFile, null,
+ diagnostics);
+ info.Files = files;
+ success = true;
+ return info;
+ }
+ finally
+ {
+ if (!success)
+ {
+ IOUtils.CloseWhileHandlingException(input);
+ }
+ else
+ {
+ input.Close();
+ }
+ }
+ }
+
+ 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/SimpleTextSegmentInfoWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
index e32f001..808c9c3 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
@@ -1,121 +1,140 @@
-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 java.util.Set;
-
-import org.apache.lucene.codecs.SegmentInfoWriter;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-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 segments files
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextSegmentInfoWriter extends SegmentInfoWriter {
-
- final static BytesRef SI_VERSION = new BytesRef(" version ");
- final static BytesRef SI_DOCCOUNT = new BytesRef(" number of documents ");
- final static BytesRef SI_USECOMPOUND = new BytesRef(" uses compound file ");
- final static BytesRef SI_NUM_DIAG = new BytesRef(" diagnostics ");
- final static BytesRef SI_DIAG_KEY = new BytesRef(" key ");
- final static BytesRef SI_DIAG_VALUE = new BytesRef(" value ");
- final static BytesRef SI_NUM_FILES = new BytesRef(" files ");
- final static BytesRef SI_FILE = new BytesRef(" file ");
-
- @Override
- public void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) {
-
- String segFileName = IndexFileNames.segmentFileName(si.name, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);
- si.addFile(segFileName);
-
- bool success = false;
- IndexOutput output = dir.createOutput(segFileName, ioContext);
-
- try {
- BytesRef scratch = new BytesRef();
-
- SimpleTextUtil.write(output, SI_VERSION);
- SimpleTextUtil.write(output, si.getVersion(), scratch);
- SimpleTextUtil.writeNewline(output);
-
- SimpleTextUtil.write(output, SI_DOCCOUNT);
- SimpleTextUtil.write(output, Integer.toString(si.getDocCount()), scratch);
- SimpleTextUtil.writeNewline(output);
-
- SimpleTextUtil.write(output, SI_USECOMPOUND);
- SimpleTextUtil.write(output, bool.toString(si.getUseCompoundFile()), scratch);
- SimpleTextUtil.writeNewline(output);
-
- Map<String,String> diagnostics = si.getDiagnostics();
- int numDiagnostics = diagnostics == null ? 0 : diagnostics.size();
- SimpleTextUtil.write(output, SI_NUM_DIAG);
- SimpleTextUtil.write(output, Integer.toString(numDiagnostics), scratch);
- SimpleTextUtil.writeNewline(output);
-
- if (numDiagnostics > 0) {
- for (Map.Entry<String,String> diagEntry : diagnostics.entrySet()) {
- SimpleTextUtil.write(output, SI_DIAG_KEY);
- SimpleTextUtil.write(output, diagEntry.getKey(), scratch);
- SimpleTextUtil.writeNewline(output);
-
- SimpleTextUtil.write(output, SI_DIAG_VALUE);
- SimpleTextUtil.write(output, diagEntry.getValue(), scratch);
- SimpleTextUtil.writeNewline(output);
- }
- }
-
- Set<String> files = si.files();
- int numFiles = files == null ? 0 : files.size();
- SimpleTextUtil.write(output, SI_NUM_FILES);
- SimpleTextUtil.write(output, Integer.toString(numFiles), scratch);
- SimpleTextUtil.writeNewline(output);
-
- if (numFiles > 0) {
- for(String fileName : files) {
- SimpleTextUtil.write(output, SI_FILE);
- SimpleTextUtil.write(output, fileName, scratch);
- SimpleTextUtil.writeNewline(output);
- }
- }
-
- SimpleTextUtil.writeChecksum(output, scratch);
- success = true;
- } finally {
- if (!success) {
- IOUtils.closeWhileHandlingException(output);
- try {
- dir.deleteFile(segFileName);
- } catch (Throwable t) {
- }
- } else {
- output.close();
- }
- }
- }
-}
+using System;
+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 FieldInfos = index.FieldInfos;
+ using IndexFileNames = index.IndexFileNames;
+ using SegmentInfo = index.SegmentInfo;
+ using Directory = store.Directory;
+ using IOContext = store.IOContext;
+ using IndexOutput = store.IndexOutput;
+ using BytesRef = util.BytesRef;
+ using IOUtils = util.IOUtils;
+
+ /// <summary>
+ /// writes plaintext segments files
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextSegmentInfoWriter : SegmentInfoWriter
+ {
+
+ internal static readonly BytesRef SI_VERSION = new BytesRef(" version ");
+ internal static readonly BytesRef SI_DOCCOUNT = new BytesRef(" number of documents ");
+ internal static readonly BytesRef SI_USECOMPOUND = new BytesRef(" uses compound file ");
+ internal static readonly BytesRef SI_NUM_DIAG = new BytesRef(" diagnostics ");
+ internal static readonly BytesRef SI_DIAG_KEY = new BytesRef(" key ");
+ internal static readonly BytesRef SI_DIAG_VALUE = new BytesRef(" value ");
+ internal static readonly BytesRef SI_NUM_FILES = new BytesRef(" files ");
+ internal static readonly BytesRef SI_FILE = new BytesRef(" file ");
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void write(store.Directory dir, index.SegmentInfo si, index.FieldInfos fis, store.IOContext ioContext) throws java.io.IOException
+ public override void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext)
+ {
+
+ string segFileName = IndexFileNames.segmentFileName(si.name, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);
+ si.addFile(segFileName);
+
+ bool success = false;
+ IndexOutput output = dir.createOutput(segFileName, ioContext);
+
+ try
+ {
+ BytesRef scratch = new BytesRef();
+
+ SimpleTextUtil.write(output, SI_VERSION);
+ SimpleTextUtil.write(output, si.Version, scratch);
+ SimpleTextUtil.WriteNewline(output);
+
+ SimpleTextUtil.write(output, SI_DOCCOUNT);
+ SimpleTextUtil.write(output, Convert.ToString(si.DocCount), scratch);
+ SimpleTextUtil.WriteNewline(output);
+
+ SimpleTextUtil.write(output, SI_USECOMPOUND);
+ SimpleTextUtil.write(output, Convert.ToString(si.UseCompoundFile), scratch);
+ SimpleTextUtil.WriteNewline(output);
+
+ IDictionary<string, string> diagnostics = si.Diagnostics;
+ int numDiagnostics = diagnostics == null ? 0 : diagnostics.Count;
+ SimpleTextUtil.write(output, SI_NUM_DIAG);
+ SimpleTextUtil.write(output, Convert.ToString(numDiagnostics), scratch);
+ SimpleTextUtil.WriteNewline(output);
+
+ if (numDiagnostics > 0)
+ {
+ foreach (KeyValuePair<string, string> diagEntry in diagnostics.SetOfKeyValuePairs())
+ {
+ SimpleTextUtil.write(output, SI_DIAG_KEY);
+ SimpleTextUtil.write(output, diagEntry.Key, scratch);
+ SimpleTextUtil.WriteNewline(output);
+
+ SimpleTextUtil.write(output, SI_DIAG_VALUE);
+ SimpleTextUtil.write(output, diagEntry.Value, scratch);
+ SimpleTextUtil.WriteNewline(output);
+ }
+ }
+
+ HashSet<string> files = si.files();
+ int numFiles = files == null ? 0 : files.Count;
+ SimpleTextUtil.write(output, SI_NUM_FILES);
+ SimpleTextUtil.write(output, Convert.ToString(numFiles), scratch);
+ SimpleTextUtil.WriteNewline(output);
+
+ if (numFiles > 0)
+ {
+ foreach (string fileName in files)
+ {
+ SimpleTextUtil.write(output, SI_FILE);
+ SimpleTextUtil.write(output, fileName, scratch);
+ SimpleTextUtil.WriteNewline(output);
+ }
+ }
+
+ SimpleTextUtil.WriteChecksum(output, scratch);
+ success = true;
+ }
+ finally
+ {
+ if (!success)
+ {
+ IOUtils.closeWhileHandlingException(output);
+ try
+ {
+ dir.deleteFile(segFileName);
+ }
+ catch (Exception)
+ {
+ }
+ }
+ else
+ {
+ output.close();
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsFormat.cs
index 2af7ad9..ffe698f 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsFormat.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,31 +15,33 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import java.io.IOException;
+namespace Lucene.Net.Codecs.SimpleText
+{
-import org.apache.lucene.codecs.StoredFieldsFormat;
-import org.apache.lucene.codecs.StoredFieldsReader;
-import org.apache.lucene.codecs.StoredFieldsWriter;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
+ using FieldInfos = Index.FieldInfos;
+ using SegmentInfo = Index.SegmentInfo;
+ using Directory = Store.Directory;
+ using IOContext = Store.IOContext;
-/**
- * plain text stored fields format.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextStoredFieldsFormat extends StoredFieldsFormat {
+ /// <summary>
+ /// plain text stored fields format.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextStoredFieldsFormat : StoredFieldsFormat
+ {
- @Override
- public StoredFieldsReader fieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context) {;
- return new SimpleTextStoredFieldsReader(directory, si, fn, context);
- }
+ public override StoredFieldsReader FieldsReader(Directory directory, SegmentInfo si, FieldInfos fn,
+ IOContext context)
+ {
+ return new SimpleTextStoredFieldsReader(directory, si, fn, context);
+ }
- @Override
- public StoredFieldsWriter fieldsWriter(Directory directory, SegmentInfo si, IOContext context) {
- return new SimpleTextStoredFieldsWriter(directory, si.name, context);
- }
-}
+ public override StoredFieldsWriter FieldsWriter(Directory directory, SegmentInfo si, IOContext context)
+ {
+ return new SimpleTextStoredFieldsWriter(directory, si.Name, context);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
index 7405838..6f2c9ea 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
@@ -1,208 +1,277 @@
-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 org.apache.lucene.codecs.StoredFieldsReader;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.index.StoredFieldVisitor;
-import org.apache.lucene.store.AlreadyClosedException;
-import org.apache.lucene.store.BufferedChecksumIndexInput;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.StringHelper;
-import org.apache.lucene.util.UnicodeUtil;
-
-import static org.apache.lucene.codecs.simpletext.SimpleTextStoredFieldsWriter.*;
-
-/**
- * reads plaintext stored fields
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextStoredFieldsReader extends StoredFieldsReader {
- private long offsets[]; /* docid -> offset in .fld file */
- private IndexInput in;
- private BytesRef scratch = new BytesRef();
- private CharsRef scratchUTF16 = new CharsRef();
- private final FieldInfos fieldInfos;
-
- public SimpleTextStoredFieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context) {
- this.fieldInfos = fn;
- bool success = false;
- try {
- in = directory.openInput(IndexFileNames.segmentFileName(si.name, "", SimpleTextStoredFieldsWriter.FIELDS_EXTENSION), context);
- success = true;
- } finally {
- if (!success) {
- try {
- close();
- } catch (Throwable t) {} // ensure we throw our original exception
- }
- }
- readIndex(si.getDocCount());
- }
-
- // used by clone
- SimpleTextStoredFieldsReader(long offsets[], IndexInput in, FieldInfos fieldInfos) {
- this.offsets = offsets;
- this.in = in;
- this.fieldInfos = fieldInfos;
- }
-
- // we don't actually write a .fdx-like index, instead we read the
- // stored fields file in entirety up-front and save the offsets
- // so we can seek to the documents later.
- private void readIndex(int size) {
- ChecksumIndexInput input = new BufferedChecksumIndexInput(in);
- offsets = new long[size];
- int upto = 0;
- while (!scratch.equals(END)) {
- SimpleTextUtil.readLine(input, scratch);
- if (StringHelper.startsWith(scratch, DOC)) {
- offsets[upto] = input.getFilePointer();
- upto++;
- }
- }
- SimpleTextUtil.checkFooter(input);
- Debug.Assert( upto == offsets.length;
- }
-
- @Override
- public void visitDocument(int n, StoredFieldVisitor visitor) {
- in.seek(offsets[n]);
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, NUM);
- int numFields = parseIntAt(NUM.length);
-
- for (int i = 0; i < numFields; i++) {
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, FIELD);
- int fieldNumber = parseIntAt(FIELD.length);
- FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldNumber);
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, NAME);
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, TYPE);
-
- final BytesRef type;
- if (equalsAt(TYPE_STRING, scratch, TYPE.length)) {
- type = TYPE_STRING;
- } else if (equalsAt(TYPE_BINARY, scratch, TYPE.length)) {
- type = TYPE_BINARY;
- } else if (equalsAt(TYPE_INT, scratch, TYPE.length)) {
- type = TYPE_INT;
- } else if (equalsAt(TYPE_LONG, scratch, TYPE.length)) {
- type = TYPE_LONG;
- } else if (equalsAt(TYPE_FLOAT, scratch, TYPE.length)) {
- type = TYPE_FLOAT;
- } else if (equalsAt(TYPE_DOUBLE, scratch, TYPE.length)) {
- type = TYPE_DOUBLE;
- } else {
- throw new RuntimeException("unknown field type");
- }
-
- switch (visitor.needsField(fieldInfo)) {
- case YES:
- readField(type, fieldInfo, visitor);
- break;
- case NO:
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, VALUE);
- break;
- case STOP: return;
- }
- }
- }
-
- private void readField(BytesRef type, FieldInfo fieldInfo, StoredFieldVisitor visitor) {
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, VALUE);
- if (type == TYPE_STRING) {
- visitor.stringField(fieldInfo, new String(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, StandardCharsets.UTF_8));
- } else if (type == TYPE_BINARY) {
- byte[] copy = new byte[scratch.length-VALUE.length];
- System.arraycopy(scratch.bytes, scratch.offset+VALUE.length, copy, 0, copy.length);
- visitor.binaryField(fieldInfo, copy);
- } else if (type == TYPE_INT) {
- UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16);
- visitor.intField(fieldInfo, Integer.parseInt(scratchUTF16.toString()));
- } else if (type == TYPE_LONG) {
- UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16);
- visitor.longField(fieldInfo, Long.parseLong(scratchUTF16.toString()));
- } else if (type == TYPE_FLOAT) {
- UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16);
- visitor.floatField(fieldInfo, Float.parseFloat(scratchUTF16.toString()));
- } else if (type == TYPE_DOUBLE) {
- UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16);
- visitor.doubleField(fieldInfo, Double.parseDouble(scratchUTF16.toString()));
- }
- }
-
- @Override
- public StoredFieldsReader clone() {
- if (in == null) {
- throw new AlreadyClosedException("this FieldsReader is closed");
- }
- return new SimpleTextStoredFieldsReader(offsets, in.clone(), fieldInfos);
- }
-
- @Override
- public void close() {
- try {
- IOUtils.close(in);
- } finally {
- in = null;
- offsets = null;
- }
- }
-
- private void readLine() {
- SimpleTextUtil.readLine(in, scratch);
- }
-
- private int parseIntAt(int offset) {
- UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+offset, scratch.length-offset, scratchUTF16);
- return ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
- }
-
- private bool equalsAt(BytesRef a, BytesRef b, int bOffset) {
- return a.length == b.length - bOffset &&
- ArrayUtil.equals(a.bytes, a.offset, b.bytes, b.offset + bOffset, b.length - bOffset);
- }
-
- @Override
- public long ramBytesUsed() {
- return 0;
- }
-
- @Override
- public void checkIntegrity() {}
-}
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+ using System;
+ using System.Diagnostics;
+
+ using FieldInfo = Index.FieldInfo;
+ using FieldInfos = Index.FieldInfos;
+ using IndexFileNames = Index.IndexFileNames;
+ using SegmentInfo = Index.SegmentInfo;
+ using StoredFieldVisitor = Index.StoredFieldVisitor;
+ using AlreadyClosedException = Store.AlreadyClosedException;
+ using BufferedChecksumIndexInput = Store.BufferedChecksumIndexInput;
+ using ChecksumIndexInput = Store.ChecksumIndexInput;
+ using Directory = Store.Directory;
+ using IOContext = Store.IOContext;
+ using IndexInput = Store.IndexInput;
+ using ArrayUtil = Util.ArrayUtil;
+ using BytesRef = Util.BytesRef;
+ using CharsRef = Util.CharsRef;
+ using IOUtils = Util.IOUtils;
+ using StringHelper = Util.StringHelper;
+ using UnicodeUtil = Util.UnicodeUtil;
+
+//JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+ import static Lucene.Net.Codecs.SimpleText.SimpleTextStoredFieldsWriter.*;
+
+ /// <summary>
+ /// reads plaintext stored fields
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextStoredFieldsReader : StoredFieldsReader
+ {
+ private long[] offsets; // docid -> offset in .fld file
+ private IndexInput @in;
+ private BytesRef scratch = new BytesRef();
+ private CharsRef scratchUTF16 = new CharsRef();
+ private readonly FieldInfos fieldInfos;
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: public SimpleTextStoredFieldsReader(store.Directory directory, index.SegmentInfo si, index.FieldInfos fn, store.IOContext context) throws java.io.IOException
+ public SimpleTextStoredFieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context)
+ {
+ this.fieldInfos = fn;
+ bool success = false;
+ try
+ {
+ @in = directory.openInput(IndexFileNames.segmentFileName(si.name, "", SimpleTextStoredFieldsWriter.FIELDS_EXTENSION), context);
+ success = true;
+ }
+ finally
+ {
+ if (!success)
+ {
+ try
+ {
+ close();
+ } // ensure we throw our original exception
+ catch (Exception)
+ {
+ }
+ }
+ }
+ readIndex(si.DocCount);
+ }
+
+ // used by clone
+ internal SimpleTextStoredFieldsReader(long[] offsets, IndexInput @in, FieldInfos fieldInfos)
+ {
+ this.offsets = offsets;
+ this.@in = @in;
+ this.fieldInfos = fieldInfos;
+ }
+
+ // we don't actually write a .fdx-like index, instead we read the
+ // stored fields file in entirety up-front and save the offsets
+ // so we can seek to the documents later.
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void readIndex(int size) throws java.io.IOException
+ private void readIndex(int size)
+ {
+ ChecksumIndexInput input = new BufferedChecksumIndexInput(@in);
+ offsets = new long[size];
+ int upto = 0;
+ while (!scratch.Equals(END))
+ {
+ SimpleTextUtil.ReadLine(input, scratch);
+ if (StringHelper.StartsWith(scratch, DOC))
+ {
+ offsets[upto] = input.FilePointer;
+ upto++;
+ }
+ }
+ SimpleTextUtil.CheckFooter(input);
+ Debug.Assert(upto == offsets.Length);
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void visitDocument(int n, index.StoredFieldVisitor visitor) throws java.io.IOException
+ public override void visitDocument(int n, StoredFieldVisitor visitor)
+ {
+ @in.seek(offsets[n]);
+ readLine();
+ Debug.Assert(StringHelper.StartsWith(scratch, NUM));
+ int numFields = parseIntAt(NUM.length);
+
+ for (int i = 0; i < numFields; i++)
+ {
+ readLine();
+ Debug.Assert(StringHelper.StartsWith(scratch, FIELD));
+ int fieldNumber = parseIntAt(FIELD.length);
+ FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldNumber);
+ readLine();
+ Debug.Assert(StringHelper.StartsWith(scratch, NAME));
+ readLine();
+ Debug.Assert(StringHelper.StartsWith(scratch, TYPE));
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final util.BytesRef type;
+ BytesRef type;
+ if (equalsAt(TYPE_STRING, scratch, TYPE.length))
+ {
+ type = TYPE_STRING;
+ }
+ else if (equalsAt(TYPE_BINARY, scratch, TYPE.length))
+ {
+ type = TYPE_BINARY;
+ }
+ else if (equalsAt(TYPE_INT, scratch, TYPE.length))
+ {
+ type = TYPE_INT;
+ }
+ else if (equalsAt(TYPE_LONG, scratch, TYPE.length))
+ {
+ type = TYPE_LONG;
+ }
+ else if (equalsAt(TYPE_FLOAT, scratch, TYPE.length))
+ {
+ type = TYPE_FLOAT;
+ }
+ else if (equalsAt(TYPE_DOUBLE, scratch, TYPE.length))
+ {
+ type = TYPE_DOUBLE;
+ }
+ else
+ {
+ throw new Exception("unknown field type");
+ }
+
+ switch (visitor.needsField(fieldInfo))
+ {
+ case YES:
+ readField(type, fieldInfo, visitor);
+ break;
+ case NO:
+ readLine();
+ Debug.Assert(StringHelper.StartsWith(scratch, VALUE));
+ break;
+ case STOP:
+ return;
+ }
+ }
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void readField(util.BytesRef type, index.FieldInfo fieldInfo, index.StoredFieldVisitor visitor) throws java.io.IOException
+ private void readField(BytesRef type, FieldInfo fieldInfo, StoredFieldVisitor visitor)
+ {
+ readLine();
+ Debug.Assert(StringHelper.StartsWith(scratch, VALUE));
+ if (type == TYPE_STRING)
+ {
+ visitor.stringField(fieldInfo, new string(scratch.bytes, scratch.offset + VALUE.length, scratch.length - VALUE.length, StandardCharsets.UTF_8));
+ }
+ else if (type == TYPE_BINARY)
+ {
+ sbyte[] copy = new sbyte[scratch.length - VALUE.length];
+ Array.Copy(scratch.bytes, scratch.offset + VALUE.length, copy, 0, copy.Length);
+ visitor.binaryField(fieldInfo, copy);
+ }
+ else if (type == TYPE_INT)
+ {
+ UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length - VALUE.length, scratchUTF16);
+ visitor.intField(fieldInfo, Convert.ToInt32(scratchUTF16.ToString()));
+ }
+ else if (type == TYPE_LONG)
+ {
+ UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length - VALUE.length, scratchUTF16);
+ visitor.longField(fieldInfo, Convert.ToInt64(scratchUTF16.ToString()));
+ }
+ else if (type == TYPE_FLOAT)
+ {
+ UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length - VALUE.length, scratchUTF16);
+ visitor.floatField(fieldInfo, Convert.ToSingle(scratchUTF16.ToString()));
+ }
+ else if (type == TYPE_DOUBLE)
+ {
+ UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length - VALUE.length, scratchUTF16);
+ visitor.doubleField(fieldInfo, Convert.ToDouble(scratchUTF16.ToString()));
+ }
+ }
+
+ public override StoredFieldsReader clone()
+ {
+ if (@in == null)
+ {
+ throw new AlreadyClosedException("this FieldsReader is closed");
+ }
+ return new SimpleTextStoredFieldsReader(offsets, @in.clone(), fieldInfos);
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void close() throws java.io.IOException
+ public override void close()
+ {
+ try
+ {
+ IOUtils.close(@in);
+ }
+ finally
+ {
+ @in = null;
+ offsets = null;
+ }
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void readLine() throws java.io.IOException
+ private void readLine()
+ {
+ SimpleTextUtil.ReadLine(@in, scratch);
+ }
+
+ private int parseIntAt(int offset)
+ {
+ UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + offset, scratch.length - offset, scratchUTF16);
+ return ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
+ }
+
+ private bool equalsAt(BytesRef a, BytesRef b, int bOffset)
+ {
+ return a.length == b.length - bOffset && ArrayUtil.Equals(a.bytes, a.offset, b.bytes, b.offset + bOffset, b.length - bOffset);
+ }
+
+ public override long ramBytesUsed()
+ {
+ return 0;
+ }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void checkIntegrity() throws java.io.IOException
+ public override void checkIntegrity()
+ {
+ }
+ }
+
+}
\ No newline at end of file
[5/7] Cleanup of codes, mostly SimpleText in this commit
Posted by pn...@apache.org.
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
[2/7] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/lucenenet
Posted by pn...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/lucenenet
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/68c7f0c2
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/68c7f0c2
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/68c7f0c2
Branch: refs/heads/master
Commit: 68c7f0c22352dc7bd79df2b07eab4b56d3e3ea1a
Parents: 0fffb73 a853887
Author: Prescott Nasser <pn...@apache.org>
Authored: Sun Sep 21 09:45:57 2014 -0700
Committer: Prescott Nasser <pn...@apache.org>
Committed: Sun Sep 21 09:45:57 2014 -0700
----------------------------------------------------------------------
src/Lucene.Net.Core/Analysis/AnalyzerWrapper.cs | 4 +-
.../Analysis/Tokenattributes/FlagsAttribute.cs | 14 +-
.../Tokenattributes/KeywordAttribute.cs | 14 +-
.../Analysis/Tokenattributes/OffsetAttribute.cs | 24 +-
.../Tokenattributes/PayloadAttribute.cs | 24 +-
.../Tokenattributes/PositionLengthAttribute.cs | 14 +-
.../Codecs/BlockTreeTermsReader.cs | 8 +-
.../CompressingStoredFieldsWriter.cs | 2 +-
.../Compressing/CompressingTermVectorsReader.cs | 12 +-
.../Compressing/CompressingTermVectorsWriter.cs | 6 +-
src/Lucene.Net.Core/Codecs/DocValuesConsumer.cs | 28 +-
.../Codecs/Lucene3x/Lucene3xFields.cs | 9 +-
.../Lucene3x/Lucene3xTermVectorsReader.cs | 21 +-
.../Lucene40/Lucene40StoredFieldsWriter.cs | 4 +-
.../Lucene40/Lucene40TermVectorsReader.cs | 41 +-
.../Lucene40/Lucene40TermVectorsWriter.cs | 4 +-
.../Codecs/MappingMultiDocsEnum.cs | 2 +-
.../Codecs/Perfield/PerFieldPostingsFormat.cs | 4 +-
.../Codecs/StoredFieldsWriter.cs | 2 +-
src/Lucene.Net.Core/Codecs/TermVectorsWriter.cs | 4 +-
.../Document/DoubleDocValuesField.cs | 2 +-
src/Lucene.Net.Core/Document/DoubleField.cs | 2 +-
.../Document/FloatDocValuesField.cs | 6 +-
src/Lucene.Net.Core/Document/FloatField.cs | 2 +-
src/Lucene.Net.Core/Document/IntField.cs | 2 +-
src/Lucene.Net.Core/Index/AtomicReader.cs | 12 +-
.../Index/AtomicReaderContext.cs | 21 +-
.../Index/BaseCompositeReader.cs | 25 +-
.../Index/BufferedUpdatesStream.cs | 6 +-
src/Lucene.Net.Core/Index/CheckIndex.cs | 44 +-
.../Index/CompositeReaderContext.cs | 41 +-
src/Lucene.Net.Core/Index/DocTermOrds.cs | 8 +-
src/Lucene.Net.Core/Index/Fields.cs | 9 +-
src/Lucene.Net.Core/Index/FilterAtomicReader.cs | 44 +-
src/Lucene.Net.Core/Index/IndexReader.cs | 21 +-
src/Lucene.Net.Core/Index/IndexReaderContext.cs | 8 +-
src/Lucene.Net.Core/Index/IndexWriter.cs | 23 +-
src/Lucene.Net.Core/Index/IndexableField.cs | 2 +
src/Lucene.Net.Core/Index/MergePolicy.cs | 2 +-
src/Lucene.Net.Core/Index/MergeState.cs | 34 +-
src/Lucene.Net.Core/Index/MultiDocValues.cs | 30 +-
src/Lucene.Net.Core/Index/MultiFields.cs | 24 +-
.../Index/ParallelAtomicReader.cs | 47 +-
.../Index/ParallelCompositeReader.cs | 10 +-
src/Lucene.Net.Core/Index/ReadersAndUpdates.cs | 10 +-
src/Lucene.Net.Core/Index/SegmentMerger.cs | 12 +-
src/Lucene.Net.Core/Index/SegmentReader.cs | 43 +-
.../Index/SlowCompositeReaderWrapper.cs | 43 +-
.../Index/StandardDirectoryReader.cs | 6 +-
src/Lucene.Net.Core/Index/TermContext.cs | 8 +-
src/Lucene.Net.Core/Search/BooleanQuery.cs | 4 +-
.../Search/CachingWrapperFilter.cs | 8 +-
.../Search/CollectionStatistics.cs | 4 +-
.../Search/ConstantScoreAutoRewrite.cs | 2 +-
.../Search/ConstantScoreQuery.cs | 2 +-
.../Search/DocTermOrdsRangeFilter.cs | 14 +-
.../Search/DocTermOrdsRewriteMethod.cs | 4 +-
src/Lucene.Net.Core/Search/Explanation.cs | 28 +-
src/Lucene.Net.Core/Search/FieldCache.cs | 61 +-
src/Lucene.Net.Core/Search/FieldCacheImpl.cs | 190 +--
.../Search/FieldCacheRangeFilter.cs | 154 +-
.../Search/FieldCacheRewriteMethod.cs | 4 +-
.../Search/FieldCacheTermsFilter.cs | 8 +-
src/Lucene.Net.Core/Search/FieldComparator.cs | 72 +-
src/Lucene.Net.Core/Search/FieldValueFilter.cs | 10 +-
src/Lucene.Net.Core/Search/Filter.cs | 3 +-
src/Lucene.Net.Core/Search/FilteredQuery.cs | 2 +-
src/Lucene.Net.Core/Search/IndexSearcher.cs | 20 +-
src/Lucene.Net.Core/Search/MatchAllDocsQuery.cs | 4 +-
src/Lucene.Net.Core/Search/MultiPhraseQuery.cs | 4 +-
.../Search/MultiTermQueryWrapperFilter.cs | 6 +-
.../Search/Payloads/PayloadNearQuery.cs | 2 +-
.../Search/Payloads/PayloadSpanUtil.cs | 4 +-
.../Search/Payloads/PayloadTermQuery.cs | 2 +-
src/Lucene.Net.Core/Search/PhraseQuery.cs | 2 +-
src/Lucene.Net.Core/Search/QueryRescorer.cs | 4 +-
src/Lucene.Net.Core/Search/SearcherManager.cs | 1 +
.../Search/Similarities/BM25Similarity.cs | 8 +-
.../Search/Similarities/SimilarityBase.cs | 2 +-
.../Search/Similarities/TFIDFSimilarity.cs | 4 +-
src/Lucene.Net.Core/Search/SortField.cs | 36 +-
src/Lucene.Net.Core/Search/SortRescorer.cs | 4 +-
.../Search/Spans/SpanTermQuery.cs | 2 +-
.../Search/TermCollectingRewrite.cs | 4 +-
src/Lucene.Net.Core/Search/Weight.cs | 2 +
src/Lucene.Net.Core/Support/Arrays.cs | 6 +-
src/Lucene.Net.Core/Support/BitSetSupport.cs | 52 +-
src/Lucene.Net.Core/Support/Number.cs | 7 +-
src/Lucene.Net.Core/Support/Single.cs | 15 -
src/Lucene.Net.Core/Util/Attribute.cs | 6 +-
.../Util/FieldCacheSanityChecker.cs | 44 +-
src/Lucene.Net.Core/Util/IOUtils.cs | 20 +-
src/Lucene.Net.Core/Util/LongBitSet.cs | 82 +-
.../Util/Mutable/MutableValue.cs | 19 +-
src/Lucene.Net.Core/Util/OfflineSorter.cs | 72 +-
src/Lucene.Net.Core/Util/OpenBitSet.cs | 5 +-
src/Lucene.Net.Core/Util/SloppyMath.cs | 3 +
src/Lucene.Net.Core/Util/VirtualMethod.cs | 24 +-
src/Lucene.Net.Memory/HashMapHelperClass.cs | 26 +
src/Lucene.Net.Memory/Lucene.Net.Memory.csproj | 61 +
src/Lucene.Net.Memory/MemoryIndex.cs | 1606 ++++++++++++++++++
.../MemoryIndexNormDocValues.cs | 47 +
.../Properties/AssemblyInfo.cs | 35 +
src/Lucene.Net.Misc/ByteBuffer.cs | 325 ++++
src/Lucene.Net.Misc/Document/LazyDocument.cs | 226 +++
.../Index/CompoundFileExtractor.cs | 165 ++
src/Lucene.Net.Misc/Index/IndexSplitter.cs | 200 +++
.../Index/MultiPassIndexSplitter.cs | 329 ++++
src/Lucene.Net.Misc/Index/PKIndexSplitter.cs | 220 +++
.../Index/Sorter/BlockJoinComparatorSource.cs | 321 ++++
.../Sorter/EarlyTerminatingSortingCollector.cs | 147 ++
src/Lucene.Net.Misc/Index/Sorter/Sorter.cs | 404 +++++
.../Index/Sorter/SortingAtomicReader.cs | 1081 ++++++++++++
.../Index/Sorter/SortingMergePolicy.cs | 309 ++++
src/Lucene.Net.Misc/Lucene.Net.Misc.csproj | 73 +
src/Lucene.Net.Misc/Misc/GetTermInfo.cs | 74 +
src/Lucene.Net.Misc/Misc/HighFreqTerms.cs | 230 +++
src/Lucene.Net.Misc/Misc/IndexMergeTool.cs | 66 +
src/Lucene.Net.Misc/Misc/SweetSpotSimilarity.cs | 238 +++
src/Lucene.Net.Misc/Misc/TermStats.cs | 55 +
src/Lucene.Net.Misc/Properties/AssemblyInfo.cs | 35 +
src/Lucene.Net.Misc/Store/NativePosixUtil.cs | 64 +
.../Store/NativeUnixDirectory.cs | 527 ++++++
src/Lucene.Net.Misc/Store/WindowsDirectory.cs | 181 ++
src/Lucene.Net.Misc/Util/Fst/ListOfOutputs.cs | 246 +++
.../Util/Fst/UpToTwoPositiveIntOutputs.cs | 328 ++++
src/Lucene.Net.Queries/BooleanFilter.cs | 202 +++
src/Lucene.Net.Queries/BoostingQuery.cs | 178 ++
src/Lucene.Net.Queries/ChainedFilter.cs | 266 +++
src/Lucene.Net.Queries/CommonTermsQuery.cs | 480 ++++++
src/Lucene.Net.Queries/CustomScoreProvider.cs | 177 ++
src/Lucene.Net.Queries/CustomScoreQuery.cs | 439 +++++
src/Lucene.Net.Queries/FilterClause.cs | 91 +
src/Lucene.Net.Queries/Function/BoostedQuery.cs | 272 +++
.../Function/DocValues/BoolDocValues.cs | 118 ++
.../DocValues/DocTermsIndexDocValues.cs | 215 +++
.../Function/DocValues/DoubleDocValues.cs | 251 +++
.../Function/DocValues/FloatDocValues.cs | 113 ++
.../Function/DocValues/IntDocValues.cs | 177 ++
.../Function/DocValues/LongDocValues.cs | 187 ++
.../Function/DocValues/StrDocValues.cs | 87 +
.../Function/FunctionQuery.cs | 255 +++
.../Function/FunctionValues.cs | 365 ++++
src/Lucene.Net.Queries/Function/ValueSource.cs | 202 +++
.../Function/ValueSourceScorer.cs | 116 ++
.../Function/ValueSources/BoolFunction.cs | 28 +
.../Function/ValueSources/ByteFieldSource.cs | 136 ++
.../ValueSources/BytesRefFieldSource.cs | 125 ++
.../Function/ValueSources/ConstNumberSource.cs | 35 +
.../Function/ValueSources/ConstValueSource.cs | 151 ++
.../Function/ValueSources/DefFunction.cs | 131 ++
.../Function/ValueSources/DivFloatFunction.cs | 42 +
.../Function/ValueSources/DocFreqValueSource.cs | 175 ++
.../ValueSources/DoubleConstValueSource.cs | 159 ++
.../Function/ValueSources/DoubleFieldSource.cs | 139 ++
.../Function/ValueSources/DualFloatFunction.cs | 109 ++
.../Function/ValueSources/EnumFieldSource.cs | 327 ++++
.../Function/ValueSources/FieldCacheSource.cs | 74 +
.../Function/ValueSources/FloatFieldSource.cs | 146 ++
.../Function/ValueSources/IDFValueSource.cs | 79 +
.../Function/ValueSources/IfFunction.cs | 177 ++
.../Function/ValueSources/IntFieldSource.cs | 174 ++
.../ValueSources/JoinDocFreqValueSource.cs | 122 ++
.../ValueSources/LinearFloatFunction.cs | 108 ++
.../Function/ValueSources/LiteralValueSource.cs | 112 ++
.../Function/ValueSources/LongFieldSource.cs | 175 ++
.../Function/ValueSources/MaxDocValueSource.cs | 68 +
.../Function/ValueSources/MaxFloatFunction.cs | 53 +
.../Function/ValueSources/MinFloatFunction.cs | 53 +
.../Function/ValueSources/MultiBoolFunction.cs | 143 ++
.../Function/ValueSources/MultiFloatFunction.cs | 140 ++
.../Function/ValueSources/MultiFunction.cs | 140 ++
.../Function/ValueSources/MultiValueSource.cs | 32 +
.../Function/ValueSources/NormValueSource.cs | 118 ++
.../Function/ValueSources/NumDocsValueSource.cs | 59 +
.../Function/ValueSources/OrdFieldSource.cs | 162 ++
.../Function/ValueSources/PowFloatFunction.cs | 48 +
.../ValueSources/ProductFloatFunction.cs | 49 +
.../Function/ValueSources/QueryValueSource.cs | 319 ++++
.../ValueSources/RangeMapFloatFunction.cs | 133 ++
.../ValueSources/ReciprocalFloatFunction.cs | 125 ++
.../ValueSources/ReverseOrdFieldSource.cs | 124 ++
.../Function/ValueSources/ScaleFloatFunction.cs | 195 +++
.../Function/ValueSources/ShortFieldSource.cs | 132 ++
.../Function/ValueSources/SimpleBoolFunction.cs | 103 ++
.../ValueSources/SimpleFloatFunction.cs | 64 +
.../Function/ValueSources/SingleFunction.cs | 62 +
.../Function/ValueSources/SumFloatFunction.cs | 48 +
.../ValueSources/SumTotalTermFreqValueSource.cs | 124 ++
.../Function/ValueSources/TFValueSource.cs | 189 +++
.../ValueSources/TermFreqValueSource.cs | 180 ++
.../ValueSources/TotalTermFreqValueSource.cs | 120 ++
.../Function/ValueSources/VectorValueSource.cs | 288 ++++
.../Lucene.Net.Queries.csproj | 129 ++
src/Lucene.Net.Queries/Mlt/MoreLikeThis.cs | 785 +++++++++
src/Lucene.Net.Queries/Mlt/MoreLikeThisQuery.cs | 298 ++++
.../Properties/AssemblyInfo.cs | 35 +
src/Lucene.Net.Queries/TermFilter.cs | 122 ++
src/Lucene.Net.Queries/TermsFilter.cs | 412 +++++
.../Lucene.Net.Suggest.csproj | 108 ++
.../Properties/AssemblyInfo.cs | 36 +
src/Lucene.Net.Suggest/RectangularArrays.cs | 29 +
.../Spell/CombineSuggestion.cs | 47 +
src/Lucene.Net.Suggest/Spell/Dictionary.cs | 35 +
.../Spell/DirectSpellChecker.cs | 575 +++++++
.../Spell/HighFrequencyDictionary.cs | 151 ++
.../Spell/JaroWinklerDistance.cs | 173 ++
.../Spell/LevensteinDistance.cs | 144 ++
.../Spell/LuceneDictionary.cs | 58 +
.../Spell/LuceneLevenshteinDistance.cs | 136 ++
src/Lucene.Net.Suggest/Spell/NGramDistance.cs | 195 +++
.../Spell/PlainTextDictionary.cs | 134 ++
src/Lucene.Net.Suggest/Spell/SpellChecker.cs | 748 ++++++++
src/Lucene.Net.Suggest/Spell/StringDistance.cs | 36 +
src/Lucene.Net.Suggest/Spell/SuggestMode.cs | 46 +
src/Lucene.Net.Suggest/Spell/SuggestWord.cs | 53 +
.../Spell/SuggestWordFrequencyComparator.cs | 64 +
.../Spell/SuggestWordQueue.cs | 65 +
.../Spell/SuggestWordScoreComparator.cs | 64 +
.../Spell/TermFreqIterator.cs | 68 +
.../Spell/WordBreakSpellChecker.cs | 542 ++++++
src/Lucene.Net.Suggest/StringHelperClass.cs | 90 +
.../Analyzing/AnalyzingInfixSuggester.cs | 792 +++++++++
.../Suggest/Analyzing/AnalyzingSuggester.cs | 1093 ++++++++++++
.../Suggest/Analyzing/BlendedInfixSuggester.cs | 316 ++++
.../Suggest/Analyzing/FSTUtil.cs | 146 ++
.../Suggest/Analyzing/FreeTextSuggester.cs | 929 ++++++++++
.../Suggest/Analyzing/FuzzySuggester.cs | 271 +++
.../Suggest/Analyzing/SuggestStopFilter.cs | 138 ++
.../Suggest/BufferedInputIterator.cs | 139 ++
.../Suggest/BufferingTermFreqIteratorWrapper.cs | 89 +
.../Suggest/DocumentDictionary.cs | 278 +++
.../Suggest/DocumentValueSourceDictionary.cs | 169 ++
.../Suggest/FileDictionary.cs | 284 ++++
.../Suggest/Fst/BytesRefSorter.cs | 34 +
.../Suggest/Fst/ExternalRefSorter.cs | 150 ++
.../Suggest/Fst/FSTCompletion.cs | 467 +++++
.../Suggest/Fst/FSTCompletionBuilder.cs | 274 +++
.../Suggest/Fst/FSTCompletionLookup.cs | 337 ++++
.../Suggest/Fst/WFSTCompletionLookup.cs | 348 ++++
.../Suggest/InMemorySorter.cs | 70 +
src/Lucene.Net.Suggest/Suggest/InputIterator.cs | 124 ++
.../Suggest/Jaspell/JaspellLookup.cs | 258 +++
.../Suggest/Jaspell/JaspellTernarySearchTrie.cs | 986 +++++++++++
src/Lucene.Net.Suggest/Suggest/Lookup.cs | 299 ++++
.../Suggest/SortedInputIterator.cs | 353 ++++
.../Suggest/SortedTermFreqIteratorWrapper.cs | 230 +++
.../Suggest/Tst/TSTAutocomplete.cs | 207 +++
src/Lucene.Net.Suggest/Suggest/Tst/TSTLookup.cs | 295 ++++
.../Suggest/Tst/TernaryTreeNode.cs | 78 +
.../Suggest/UnsortedInputIterator.cs | 108 ++
.../Codecs/asserting/AssertingPostingsFormat.cs | 4 +-
.../Codecs/ramonly/RAMOnlyPostingsFormat.cs | 4 +-
.../Index/AllDeletedFilterReader.cs | 8 +-
.../Index/AssertingAtomicReader.cs | 35 +-
.../Index/BaseDocValuesFormatTestCase.cs | 224 +--
.../Index/BaseStoredFieldsFormatTestCase.cs | 18 +-
.../Index/BaseTermVectorsFormatTestCase.cs | 2 +-
.../Index/FieldFilterAtomicReader.cs | 18 +-
.../Index/RandomIndexWriter.cs | 2 +-
.../ThreadedIndexingAndSearchingTestCase.cs | 10 +-
.../JavaCompatibility/LuceneTestCase.cs | 5 -
.../Search/CheckHits.cs | 2 +-
.../Search/QueryUtils.cs | 20 +-
.../Search/SearchEquivalenceTestBase.cs | 4 +-
.../Search/ShardSearchingTestBase.cs | 8 +-
.../Store/MockDirectoryWrapper.cs | 4 +-
.../Util/BaseDocIdSetTestCase.cs | 3 +-
.../Util/LuceneTestCase.cs | 54 +-
.../Util/TestRuleSetupAndRestoreClassEnv.cs | 4 +-
src/Lucene.Net.TestFramework/Util/TestUtil.cs | 9 +-
.../core/Analysis/TestMockAnalyzer.cs | 38 +-
.../Tokenattributes/TestSimpleAttributeImpl.cs | 3 +-
.../core/Codecs/Lucene40/TestReuseDocsEnum.cs | 26 +-
.../Codecs/Lucene41/TestBlockPostingsFormat3.cs | 4 +-
.../Perfield/TestPerFieldDocValuesFormat.cs | 6 +-
.../Perfield/TestPerFieldPostingsFormat2.cs | 2 +-
.../core/Document/TestBinaryDocument.cs | 2 +-
.../core/Index/Test2BBinaryDocValues.cs | 12 +-
src/Lucene.Net.Tests/core/Index/Test2BDocs.cs | 4 +-
.../core/Index/Test2BNumericDocValues.cs | 6 +-
.../core/Index/Test2BSortedDocValues.cs | 12 +-
.../core/Index/TestAddIndexes.cs | 76 +-
.../core/Index/TestAtomicUpdate.cs | 4 +-
.../core/Index/TestBagOfPositions.cs | 4 +-
.../core/Index/TestBagOfPostings.cs | 6 +-
.../core/Index/TestBinaryDocValuesUpdates.cs | 110 +-
.../core/Index/TestCodecHoldsOpenFiles.cs | 8 +-
src/Lucene.Net.Tests/core/Index/TestCodecs.cs | 4 +-
.../core/Index/TestConcurrentMergeScheduler.cs | 6 +-
src/Lucene.Net.Tests/core/Index/TestCrash.cs | 12 +-
.../core/Index/TestCustomNorms.cs | 2 +-
.../core/Index/TestDeletionPolicy.cs | 24 +-
.../core/Index/TestDirectoryReader.cs | 44 +-
.../core/Index/TestDirectoryReaderReopen.cs | 16 +-
src/Lucene.Net.Tests/core/Index/TestDoc.cs | 4 +-
src/Lucene.Net.Tests/core/Index/TestDocCount.cs | 2 +-
.../core/Index/TestDocTermOrds.cs | 34 +-
.../core/Index/TestDocValuesIndexing.cs | 16 +-
.../core/Index/TestDocValuesWithThreads.cs | 26 +-
.../core/Index/TestDocsAndPositions.cs | 26 +-
.../core/Index/TestFilterAtomicReader.cs | 4 +-
src/Lucene.Net.Tests/core/Index/TestFlex.cs | 2 +-
.../core/Index/TestIndexReaderClose.cs | 2 +-
.../core/Index/TestIndexWriter.cs | 78 +-
.../core/Index/TestIndexWriterCommit.cs | 52 +-
.../core/Index/TestIndexWriterDelete.cs | 42 +-
.../core/Index/TestIndexWriterExceptions.cs | 48 +-
.../core/Index/TestIndexWriterForceMerge.cs | 4 +-
.../core/Index/TestIndexWriterMergePolicy.cs | 2 +-
.../core/Index/TestIndexWriterMerging.cs | 34 +-
.../core/Index/TestIndexWriterNRTIsCurrent.cs | 2 +-
.../TestIndexWriterOutOfFileDescriptors.cs | 4 +-
.../core/Index/TestIndexWriterReader.cs | 46 +-
.../core/Index/TestIndexWriterUnicode.cs | 4 +-
.../core/Index/TestIndexWriterWithThreads.cs | 4 +-
.../core/Index/TestLongPostings.cs | 4 +-
.../core/Index/TestMaxTermFrequency.cs | 2 +-
.../core/Index/TestMixedCodecs.cs | 2 +-
.../core/Index/TestMixedDocValuesUpdates.cs | 26 +-
.../core/Index/TestNRTThreads.cs | 6 +-
src/Lucene.Net.Tests/core/Index/TestNorms.cs | 6 +-
.../core/Index/TestNumericDocValuesUpdates.cs | 110 +-
.../core/Index/TestOmitNorms.cs | 2 +-
.../core/Index/TestParallelCompositeReader.cs | 20 +-
.../core/Index/TestParallelReaderEmptyIndex.cs | 4 +-
.../core/Index/TestParallelTermEnum.cs | 2 +-
.../core/Index/TestPostingsOffsets.cs | 10 +-
src/Lucene.Net.Tests/core/Index/TestRollback.cs | 2 +-
.../core/Index/TestRollingUpdates.cs | 6 +-
.../core/Index/TestSegmentMerger.cs | 12 +-
.../core/Index/TestSegmentReader.cs | 8 +-
.../core/Index/TestSegmentTermDocs.cs | 2 +-
.../core/Index/TestSegmentTermEnum.cs | 2 +-
.../core/Index/TestSnapshotDeletionPolicy.cs | 2 +-
.../core/Index/TestStressAdvance.cs | 4 +-
.../core/Index/TestStressIndexing2.cs | 20 +-
.../core/Index/TestTermVectorsReader.cs | 4 +-
.../core/Index/TestTermVectorsWriter.cs | 2 +-
.../core/Index/TestTermsEnum.cs | 14 +-
.../core/Index/TestThreadedForceMerge.cs | 8 +-
.../core/Index/TestTieredMergePolicy.cs | 20 +-
.../core/Index/TestTransactionRollback.cs | 4 +-
.../core/Index/TestTransactions.cs | 4 +-
.../core/Search/JustCompileSearch.cs | 4 +-
src/Lucene.Net.Tests/core/Search/MockFilter.cs | 2 +-
.../core/Search/SingleDocTestFilter.cs | 2 +-
.../core/Search/Spans/MultiSpansWrapper.cs | 14 +-
.../core/Search/Spans/TestNearSpansOrdered.cs | 4 +-
.../core/Search/Spans/TestSpans.cs | 4 +-
.../core/Search/Spans/TestSpansAdvanced2.cs | 2 +-
.../core/Search/TestBooleanOr.cs | 4 +-
.../core/Search/TestCachingWrapperFilter.cs | 30 +-
.../core/Search/TestDisjunctionMaxQuery.cs | 4 +-
.../core/Search/TestDocValuesScoring.cs | 6 +-
.../core/Search/TestElevationComparator.cs | 2 +-
.../core/Search/TestFieldCacheRangeFilter.cs | 16 +-
.../core/Search/TestFieldCacheTermsFilter.cs | 2 +-
.../core/Search/TestFilteredQuery.cs | 6 +-
.../core/Search/TestFilteredSearch.cs | 4 +-
.../core/Search/TestIndexSearcher.cs | 2 +-
.../core/Search/TestMinShouldMatch2.cs | 2 +-
.../core/Search/TestMultiTermConstantScore.cs | 4 +-
.../core/Search/TestMultiThreadTermVectors.cs | 2 +-
.../core/Search/TestNumericRangeQuery32.cs | 6 +-
.../core/Search/TestNumericRangeQuery64.cs | 6 +-
.../core/Search/TestQueryRescorer.cs | 4 +-
.../core/Search/TestSameScoresWithThreads.cs | 2 +-
.../core/Search/TestSearchAfter.cs | 2 +-
.../core/Search/TestSearcherManager.cs | 4 +-
.../core/Search/TestShardSearching.cs | 8 +-
.../core/Search/TestSimilarityProvider.cs | 2 +-
src/Lucene.Net.Tests/core/Search/TestSort.cs | 12 +-
.../core/Search/TestSortDocValues.cs | 4 +-
.../core/Search/TestSortRandom.cs | 6 +-
.../core/Search/TestSubScorerFreqs.cs | 6 +-
.../core/Search/TestTermRangeFilter.cs | 4 +-
.../core/Search/TestTermScorer.cs | 6 +-
.../core/Search/TestTermVectors.cs | 4 +-
.../core/Search/TestTopDocsMerge.cs | 6 +-
.../core/Store/TestFileSwitchDirectory.cs | 2 +-
.../core/Store/TestNRTCachingDirectory.cs | 2 +-
.../core/Store/TestRAMDirectory.cs | 4 +-
.../core/Util/BaseSortTestCase.cs | 154 +-
.../core/Util/TestDoubleBarrelLRUCache.cs | 13 +-
.../core/Util/TestFieldCacheSanityChecker.cs | 19 +-
src/Lucene.Net.Tests/core/Util/TestIOUtils.cs | 42 +-
.../core/Util/TestInPlaceMergeSorter.cs | 5 -
.../core/Util/TestIntroSorter.cs | 5 -
.../core/Util/TestLongBitSet.cs | 21 +-
.../core/Util/TestOpenBitSet.cs | 20 +-
src/Lucene.Net.Tests/core/Util/TestSetOnce.cs | 5 +-
.../core/Util/TestSmallFloat.cs | 5 +-
src/Lucene.Net.Tests/core/Util/TestTimSorter.cs | 5 -
.../core/Util/TestVirtualMethod.cs | 13 +-
395 files changed, 34526 insertions(+), 1869 deletions(-)
----------------------------------------------------------------------
[3/7] Cleanup of codes, mostly SimpleText in this commit
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
index 5c5346d..79d943f 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,181 +15,226 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import java.io.IOException;
-
-import org.apache.lucene.codecs.StoredFieldsWriter;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.IndexableField;
-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 plain-text stored fields.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextStoredFieldsWriter extends StoredFieldsWriter {
- private int numDocsWritten = 0;
- private final Directory directory;
- private final String segment;
- private IndexOutput out;
-
- final static String FIELDS_EXTENSION = "fld";
-
- final static BytesRef TYPE_STRING = new BytesRef("string");
- final static BytesRef TYPE_BINARY = new BytesRef("binary");
- final static BytesRef TYPE_INT = new BytesRef("int");
- final static BytesRef TYPE_LONG = new BytesRef("long");
- final static BytesRef TYPE_FLOAT = new BytesRef("float");
- final static BytesRef TYPE_DOUBLE = new BytesRef("double");
-
- final static BytesRef END = new BytesRef("END");
- final static BytesRef DOC = new BytesRef("doc ");
- final static BytesRef NUM = new BytesRef(" numfields ");
- final static BytesRef FIELD = new BytesRef(" field ");
- final static BytesRef NAME = new BytesRef(" name ");
- final static BytesRef TYPE = new BytesRef(" type ");
- final static BytesRef VALUE = new BytesRef(" value ");
-
- private final BytesRef scratch = new BytesRef();
-
- public SimpleTextStoredFieldsWriter(Directory directory, String segment, IOContext context) {
- this.directory = directory;
- this.segment = segment;
- bool success = false;
- try {
- out = directory.createOutput(IndexFileNames.segmentFileName(segment, "", FIELDS_EXTENSION), context);
- success = true;
- } finally {
- if (!success) {
- abort();
- }
- }
- }
-
- @Override
- public void startDocument(int numStoredFields) {
- write(DOC);
- write(Integer.toString(numDocsWritten));
- newLine();
-
- write(NUM);
- write(Integer.toString(numStoredFields));
- newLine();
-
- numDocsWritten++;
- }
-
- @Override
- public void writeField(FieldInfo info, IndexableField field) {
- write(FIELD);
- write(Integer.toString(info.number));
- newLine();
-
- write(NAME);
- write(field.name());
- newLine();
-
- write(TYPE);
- final Number n = field.numericValue();
-
- if (n != null) {
- if (n instanceof Byte || n instanceof Short || n instanceof Integer) {
- write(TYPE_INT);
- newLine();
-
- write(VALUE);
- write(Integer.toString(n.intValue()));
- newLine();
- } else if (n instanceof Long) {
- write(TYPE_LONG);
- newLine();
-
- write(VALUE);
- write(Long.toString(n.longValue()));
- newLine();
- } else if (n instanceof Float) {
- write(TYPE_FLOAT);
- newLine();
-
- write(VALUE);
- write(Float.toString(n.floatValue()));
- newLine();
- } else if (n instanceof Double) {
- write(TYPE_DOUBLE);
- newLine();
-
- write(VALUE);
- write(Double.toString(n.doubleValue()));
- newLine();
- } else {
- throw new IllegalArgumentException("cannot store numeric type " + n.getClass());
- }
- } else {
- BytesRef bytes = field.binaryValue();
- if (bytes != null) {
- write(TYPE_BINARY);
- newLine();
-
- write(VALUE);
- write(bytes);
- newLine();
- } else if (field.stringValue() == null) {
- throw new IllegalArgumentException("field " + field.name() + " is stored but does not have binaryValue, stringValue nor numericValue");
- } else {
- write(TYPE_STRING);
- newLine();
-
- write(VALUE);
- write(field.stringValue());
- newLine();
- }
- }
- }
-
- @Override
- public void abort() {
- try {
- close();
- } catch (Throwable ignored) {}
- IOUtils.deleteFilesIgnoringExceptions(directory, IndexFileNames.segmentFileName(segment, "", FIELDS_EXTENSION));
- }
-
- @Override
- public void finish(FieldInfos fis, int numDocs) {
- if (numDocsWritten != numDocs) {
- throw new RuntimeException("mergeFields produced an invalid result: docCount is " + numDocs
- + " but only saw " + numDocsWritten + " file=" + out.toString() + "; now aborting this merge to prevent index corruption");
- }
- write(END);
- newLine();
- SimpleTextUtil.writeChecksum(out, scratch);
- }
-
- @Override
- public void close() {
- try {
- IOUtils.close(out);
- } finally {
- out = null;
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+ using System;
+
+ using FieldInfo = Index.FieldInfo;
+ using FieldInfos = Index.FieldInfos;
+ using IndexFileNames = Index.IndexFileNames;
+ using IndexableField = Index.IndexableField;
+ using Directory = Store.Directory;
+ using IOContext = Store.IOContext;
+ using IndexOutput = Store.IndexOutput;
+ using BytesRef = Util.BytesRef;
+ using IOUtils = Util.IOUtils;
+
+ /// <summary>
+ /// Writes plain-text stored fields.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextStoredFieldsWriter : StoredFieldsWriter
+ {
+ private int _numDocsWritten;
+ private readonly Directory _directory;
+ private readonly string _segment;
+ private IndexOutput _output;
+
+ internal const string FIELDS_EXTENSION = "fld";
+
+ internal static readonly BytesRef TYPE_STRING = new BytesRef("string");
+ internal static readonly BytesRef TYPE_BINARY = new BytesRef("binary");
+ internal static readonly BytesRef TYPE_INT = new BytesRef("int");
+ internal static readonly BytesRef TYPE_LONG = new BytesRef("long");
+ internal static readonly BytesRef TYPE_FLOAT = new BytesRef("float");
+ internal static readonly BytesRef TYPE_DOUBLE = new BytesRef("double");
+
+ internal static readonly BytesRef END = new BytesRef("END");
+ internal static readonly BytesRef DOC = new BytesRef("doc ");
+ internal static readonly BytesRef NUM = new BytesRef(" numfields ");
+ internal static readonly BytesRef FIELD = new BytesRef(" field ");
+ internal static readonly BytesRef NAME = new BytesRef(" name ");
+ internal static readonly BytesRef TYPE = new BytesRef(" type ");
+ internal static readonly BytesRef VALUE = new BytesRef(" value ");
+
+ private readonly BytesRef _scratch = new BytesRef();
+
+ public SimpleTextStoredFieldsWriter(Directory directory, string segment, IOContext context)
+ {
+ _directory = directory;
+ _segment = segment;
+ var success = false;
+ try
+ {
+ _output = directory.CreateOutput(IndexFileNames.SegmentFileName(segment, "", FIELDS_EXTENSION), context);
+ success = true;
+ }
+ finally
+ {
+ if (!success)
+ {
+ Abort();
+ }
+ }
+ }
+
+ public override void StartDocument(int numStoredFields)
+ {
+ Write(DOC);
+ Write(Convert.ToString(_numDocsWritten));
+ NewLine();
+
+ Write(NUM);
+ Write(Convert.ToString(numStoredFields));
+ NewLine();
+
+ _numDocsWritten++;
+ }
+
+ public override void WriteField(FieldInfo info, IndexableField field)
+ {
+ Write(FIELD);
+ Write(Convert.ToString(info.Number));
+ NewLine();
+
+ Write(NAME);
+ Write(field.Name());
+ NewLine();
+
+ Write(TYPE);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final Number n = field.numericValue();
+ Number n = field.NumericValue;
+
+ if (n != null)
+ {
+ if (n is sbyte? || n is short? || n is int?)
+ {
+ Write(TYPE_INT);
+ NewLine();
+
+ Write(VALUE);
+ Write(Convert.ToString((int) n));
+ NewLine();
+ }
+ else if (n is long?)
+ {
+ Write(TYPE_LONG);
+ NewLine();
+
+ Write(VALUE);
+ Write(Convert.ToString((long) n));
+ NewLine();
+ }
+ else if (n is float?)
+ {
+ Write(TYPE_FLOAT);
+ NewLine();
+
+ Write(VALUE);
+ Write(Convert.ToString((float) n));
+ NewLine();
+ }
+ else if (n is double?)
+ {
+ Write(TYPE_DOUBLE);
+ NewLine();
+
+ Write(VALUE);
+ Write(Convert.ToString((double) n));
+ NewLine();
+ }
+ else
+ {
+ throw new System.ArgumentException("cannot store numeric type " + n.GetType());
+ }
+ }
+ else
+ {
+ BytesRef bytes = field.binaryValue();
+ if (bytes != null)
+ {
+ Write(TYPE_BINARY);
+ NewLine();
+
+ Write(VALUE);
+ Write(bytes);
+ NewLine();
+ }
+ else if (field.stringValue() == null)
+ {
+ throw new ArgumentException("field " + field.Name() +
+ " is stored but does not have binaryValue, stringValue nor numericValue");
+ }
+ else
+ {
+ Write(TYPE_STRING);
+ NewLine();
+
+ Write(VALUE);
+ Write(field.StringValue());
+ NewLine();
+ }
+ }
+ }
+
+ public override sealed void Abort()
+ {
+ try
+ {
+ Dispose();
+ }
+ finally
+ {
+ IOUtils.DeleteFilesIgnoringExceptions(_directory,
+ IndexFileNames.SegmentFileName(_segment, "", FIELDS_EXTENSION));
+ }
+ }
+
+ public override void Finish(FieldInfos fis, int numDocs)
+ {
+ if (_numDocsWritten != numDocs)
+ {
+ throw new Exception("mergeFields produced an invalid result: docCount is " + numDocs + " but only saw " +
+ _numDocsWritten + " file=" + _output +
+ "; now aborting this merge to prevent index corruption");
+ }
+ Write(END);
+ NewLine();
+ SimpleTextUtil.WriteChecksum(_output, _scratch);
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing) return;
+ try
+ {
+ IOUtils.Close(_output);
+ }
+ finally
+ {
+ _output = null;
+ }
+ }
+
+ private void Write(string s)
+ {
+ SimpleTextUtil.Write(_output, s, _scratch);
+ }
+
+ private void Write(BytesRef bytes)
+ {
+ SimpleTextUtil.Write(_output, bytes);
+ }
+
+ private void NewLine()
+ {
+ SimpleTextUtil.WriteNewline(_output);
+ }
}
- }
-
- private void write(String s) {
- SimpleTextUtil.write(out, s, scratch);
- }
-
- private void write(BytesRef bytes) {
- SimpleTextUtil.write(out, bytes);
- }
-
- private void newLine() {
- SimpleTextUtil.writeNewline(out);
- }
-}
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsFormat.cs
index 4b332e5..d9829ab 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsFormat.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,31 +15,32 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import java.io.IOException;
-
-import org.apache.lucene.codecs.TermVectorsFormat;
-import org.apache.lucene.codecs.TermVectorsReader;
-import org.apache.lucene.codecs.TermVectorsWriter;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
+namespace Lucene.Net.Codecs.SimpleText
+{
+ using FieldInfos = Index.FieldInfos;
+ using SegmentInfo = Index.SegmentInfo;
+ using Directory = Store.Directory;
+ using IOContext = Store.IOContext;
-/**
- * plain text term vectors format.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextTermVectorsFormat extends TermVectorsFormat {
+ /// <summary>
+ /// plain text term vectors format.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextTermVectorsFormat : TermVectorsFormat
+ {
+ public override TermVectorsReader VectorsReader(Directory directory, SegmentInfo segmentInfo,
+ FieldInfos fieldInfos, IOContext context)
+ {
+ return new SimpleTextTermVectorsReader(directory, segmentInfo, context);
+ }
- @Override
- public TermVectorsReader vectorsReader(Directory directory, SegmentInfo segmentInfo, FieldInfos fieldInfos, IOContext context) {
- return new SimpleTextTermVectorsReader(directory, segmentInfo, context);
- }
- @Override
- public TermVectorsWriter vectorsWriter(Directory directory, SegmentInfo segmentInfo, IOContext context) {
- return new SimpleTextTermVectorsWriter(directory, segmentInfo.name, context);
- }
-}
+ public override TermVectorsWriter VectorsWriter(Directory directory, SegmentInfo segmentInfo, IOContext context)
+ {
+ return new SimpleTextTermVectorsWriter(directory, segmentInfo.Name, context);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
index 634e4ae..09e4a30 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsReader.cs
@@ -1,558 +1,617 @@
-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.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.apache.lucene.codecs.TermVectorsReader;
-import org.apache.lucene.index.DocsAndPositionsEnum;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.Fields;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.store.AlreadyClosedException;
-import org.apache.lucene.store.BufferedChecksumIndexInput;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-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.IOUtils;
-import org.apache.lucene.util.StringHelper;
-import org.apache.lucene.util.UnicodeUtil;
-import static org.apache.lucene.codecs.simpletext.SimpleTextTermVectorsWriter.*;
-
-/**
- * Reads plain-text term vectors.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextTermVectorsReader extends TermVectorsReader {
- private long offsets[]; /* docid -> offset in .vec file */
- private IndexInput in;
- private BytesRef scratch = new BytesRef();
- private CharsRef scratchUTF16 = new CharsRef();
-
- public SimpleTextTermVectorsReader(Directory directory, SegmentInfo si, IOContext context) {
- bool success = false;
- try {
- in = directory.openInput(IndexFileNames.segmentFileName(si.name, "", VECTORS_EXTENSION), context);
- success = true;
- } finally {
- if (!success) {
- try {
- close();
- } catch (Throwable t) {} // ensure we throw our original exception
- }
- }
- readIndex(si.getDocCount());
- }
-
- // used by clone
- SimpleTextTermVectorsReader(long offsets[], IndexInput in) {
- this.offsets = offsets;
- this.in = in;
- }
-
- // we don't actually write a .tvx-like index, instead we read the
- // vectors file in entirety up-front and save the offsets
- // so we can seek to the data later.
- private void readIndex(int maxDoc) {
- ChecksumIndexInput input = new BufferedChecksumIndexInput(in);
- offsets = new long[maxDoc];
- int upto = 0;
- while (!scratch.equals(END)) {
- SimpleTextUtil.readLine(input, scratch);
- if (StringHelper.startsWith(scratch, DOC)) {
- offsets[upto] = input.getFilePointer();
- upto++;
- }
- }
- SimpleTextUtil.checkFooter(input);
- Debug.Assert( upto == offsets.length;
- }
-
- @Override
- public Fields get(int doc) {
- SortedMap<String,SimpleTVTerms> fields = new TreeMap<>();
- in.seek(offsets[doc]);
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, NUMFIELDS);
- int numFields = parseIntAt(NUMFIELDS.length);
- if (numFields == 0) {
- return null; // no vectors for this doc
- }
- for (int i = 0; i < numFields; i++) {
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, FIELD);
- // skip fieldNumber:
- parseIntAt(FIELD.length);
-
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, FIELDNAME);
- String fieldName = readString(FIELDNAME.length, scratch);
-
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, FIELDPOSITIONS);
- bool positions = bool.parsebool(readString(FIELDPOSITIONS.length, scratch));
-
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, FIELDOFFSETS);
- bool offsets = bool.parsebool(readString(FIELDOFFSETS.length, scratch));
-
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, FIELDPAYLOADS);
- bool payloads = bool.parsebool(readString(FIELDPAYLOADS.length, scratch));
-
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, FIELDTERMCOUNT);
- int termCount = parseIntAt(FIELDTERMCOUNT.length);
-
- SimpleTVTerms terms = new SimpleTVTerms(offsets, positions, payloads);
- fields.put(fieldName, terms);
-
- for (int j = 0; j < termCount; j++) {
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, TERMTEXT);
- BytesRef term = new BytesRef();
- int termLength = scratch.length - TERMTEXT.length;
- term.grow(termLength);
- term.length = termLength;
- System.arraycopy(scratch.bytes, scratch.offset+TERMTEXT.length, term.bytes, term.offset, termLength);
-
- SimpleTVPostings postings = new SimpleTVPostings();
- terms.terms.put(term, postings);
-
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, TERMFREQ);
- postings.freq = parseIntAt(TERMFREQ.length);
-
- if (positions || offsets) {
- if (positions) {
- postings.positions = new int[postings.freq];
- if (payloads) {
- postings.payloads = new BytesRef[postings.freq];
- }
- }
-
- if (offsets) {
- postings.startOffsets = new int[postings.freq];
- postings.endOffsets = new int[postings.freq];
- }
-
- for (int k = 0; k < postings.freq; k++) {
- if (positions) {
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, POSITION);
- postings.positions[k] = parseIntAt(POSITION.length);
- if (payloads) {
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, PAYLOAD);
- if (scratch.length - PAYLOAD.length == 0) {
- postings.payloads[k] = null;
- } else {
- byte payloadBytes[] = new byte[scratch.length - PAYLOAD.length];
- System.arraycopy(scratch.bytes, scratch.offset+PAYLOAD.length, payloadBytes, 0, payloadBytes.length);
- postings.payloads[k] = new BytesRef(payloadBytes);
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+ using System;
+ using System.Diagnostics;
+ using System.Collections.Generic;
+
+ using DocsAndPositionsEnum = Index.DocsAndPositionsEnum;
+ using DocsEnum = Index.DocsEnum;
+ using Fields = Index.Fields;
+ using IndexFileNames = Index.IndexFileNames;
+ using SegmentInfo = Index.SegmentInfo;
+ using Terms = Index.Terms;
+ using TermsEnum = Index.TermsEnum;
+ using AlreadyClosedException = Store.AlreadyClosedException;
+ using BufferedChecksumIndexInput = Store.BufferedChecksumIndexInput;
+ using ChecksumIndexInput = Store.ChecksumIndexInput;
+ using Directory = Store.Directory;
+ using IOContext = Store.IOContext;
+ using IndexInput = Store.IndexInput;
+ using ArrayUtil = Util.ArrayUtil;
+ using Bits = Util.Bits;
+ using BytesRef = Util.BytesRef;
+ using CharsRef = Util.CharsRef;
+ using IOUtils = Util.IOUtils;
+ using StringHelper = Util.StringHelper;
+ using UnicodeUtil = Util.UnicodeUtil;
+
+ //JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+ //import static Lucene.Net.Codecs.SimpleText.SimpleTextTermVectorsWriter.*;
+
+ /// <summary>
+ /// Reads plain-text term vectors.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextTermVectorsReader : TermVectorsReader
+ {
+ private long[] _offsets; // docid -> offset in .vec file
+ private IndexInput _input;
+ private readonly BytesRef _scratch = new BytesRef();
+ private readonly CharsRef _scratchUtf16 = new CharsRef();
+
+ public SimpleTextTermVectorsReader(Directory directory, SegmentInfo si, IOContext context)
+ {
+ bool success = false;
+ try
+ {
+ _input = directory.OpenInput(IndexFileNames.SegmentFileName(si.Name, "", VECTORS_EXTENSION), context);
+ success = true;
+ }
+ finally
+ {
+ if (!success)
+ {
+ try
+ {
+ Dispose();
+ } // ensure we throw our original exception
+ catch (Exception)
+ {
+ }
}
- }
- }
-
- if (offsets) {
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, STARTOFFSET);
- postings.startOffsets[k] = parseIntAt(STARTOFFSET.length);
-
- readLine();
- Debug.Assert( StringHelper.startsWith(scratch, ENDOFFSET);
- postings.endOffsets[k] = parseIntAt(ENDOFFSET.length);
- }
- }
+ }
+ ReadIndex(si.DocCount);
}
- }
- }
- return new SimpleTVFields(fields);
- }
- @Override
- public TermVectorsReader clone() {
- if (in == null) {
- throw new AlreadyClosedException("this TermVectorsReader is closed");
- }
- return new SimpleTextTermVectorsReader(offsets, in.clone());
- }
-
- @Override
- public void close() {
- try {
- IOUtils.close(in);
- } finally {
- in = null;
- offsets = null;
- }
- }
-
- private void readLine() {
- SimpleTextUtil.readLine(in, scratch);
- }
-
- private int parseIntAt(int offset) {
- UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+offset, scratch.length-offset, scratchUTF16);
- return ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
- }
-
- private String readString(int offset, BytesRef scratch) {
- UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+offset, scratch.length-offset, scratchUTF16);
- return scratchUTF16.toString();
- }
-
- private class SimpleTVFields extends Fields {
- private final SortedMap<String,SimpleTVTerms> fields;
-
- SimpleTVFields(SortedMap<String,SimpleTVTerms> fields) {
- this.fields = fields;
- }
+ // used by clone
+ internal SimpleTextTermVectorsReader(long[] offsets, IndexInput @in)
+ {
+ this._offsets = offsets;
+ _input = @in;
+ }
- @Override
- public Iterator<String> iterator() {
- return Collections.unmodifiableSet(fields.keySet()).iterator();
- }
+ // we don't actually write a .tvx-like index, instead we read the
+ // vectors file in entirety up-front and save the offsets
+ // so we can seek to the data later.
+ private void ReadIndex(int maxDoc)
+ {
+ ChecksumIndexInput input = new BufferedChecksumIndexInput(_input);
+ _offsets = new long[maxDoc];
+ int upto = 0;
+ while (!_scratch.Equals(END))
+ {
+ SimpleTextUtil.ReadLine(input, _scratch);
+ if (StringHelper.StartsWith(_scratch, DOC))
+ {
+ _offsets[upto] = input.FilePointer;
+ upto++;
+ }
+ }
+ SimpleTextUtil.CheckFooter(input);
+ Debug.Assert(upto == _offsets.Length);
+ }
- @Override
- public Terms terms(String field) {
- return fields.get(field);
- }
+ public override Fields Get(int doc)
+ {
+ SortedMap<string, SimpleTVTerms> fields = new SortedDictionary<string, SimpleTVTerms>();
+ _input.Seek(_offsets[doc]);
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, NUMFIELDS));
+ int numFields = ParseIntAt(NUMFIELDS.length);
+ if (numFields == 0)
+ {
+ return null; // no vectors for this doc
+ }
+ for (int i = 0; i < numFields; i++)
+ {
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, FIELD));
+ // skip fieldNumber:
+ ParseIntAt(FIELD.length);
+
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, FIELDNAME));
+ string fieldName = ReadString(FIELDNAME.length, _scratch);
+
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, FIELDPOSITIONS));
+ bool positions = Convert.ToBoolean(ReadString(FIELDPOSITIONS.length, _scratch));
+
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, FIELDOFFSETS));
+ bool offsets = Convert.ToBoolean(ReadString(FIELDOFFSETS.length, _scratch));
+
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, FIELDPAYLOADS));
+ bool payloads = Convert.ToBoolean(ReadString(FIELDPAYLOADS.length, _scratch));
+
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, FIELDTERMCOUNT));
+ int termCount = ParseIntAt(FIELDTERMCOUNT.length);
+
+ SimpleTVTerms terms = new SimpleTVTerms(offsets, positions, payloads);
+ fields.put(fieldName, terms);
+
+ for (int j = 0; j < termCount; j++)
+ {
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, TERMTEXT));
+ BytesRef term = new BytesRef();
+ int termLength = _scratch.length - TERMTEXT.length;
+ term.grow(termLength);
+ term.length = termLength;
+ Array.Copy(_scratch.bytes, _scratch.offset + TERMTEXT.length, term.bytes, term.offset, termLength);
+
+ SimpleTVPostings postings = new SimpleTVPostings();
+ terms.TERMS.put(term, postings);
+
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, TERMFREQ));
+ postings.FREQ = ParseIntAt(TERMFREQ.length);
+
+ if (positions || offsets)
+ {
+ if (positions)
+ {
+ postings.POSITIONS = new int[postings.FREQ];
+ if (payloads)
+ {
+ postings.PAYLOADS = new BytesRef[postings.FREQ];
+ }
+ }
+
+ if (offsets)
+ {
+ postings.START_OFFSETS = new int[postings.FREQ];
+ postings.END_OFFSETS = new int[postings.FREQ];
+ }
+
+ for (int k = 0; k < postings.FREQ; k++)
+ {
+ if (positions)
+ {
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, POSITION));
+ postings.POSITIONS[k] = ParseIntAt(POSITION.length);
+ if (payloads)
+ {
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, PAYLOAD));
+ if (_scratch.length - PAYLOAD.length == 0)
+ {
+ postings.PAYLOADS[k] = null;
+ }
+ else
+ {
+ sbyte[] payloadBytes = new sbyte[_scratch.length - PAYLOAD.length];
+ Array.Copy(_scratch.bytes, _scratch.offset + PAYLOAD.length, payloadBytes, 0,
+ payloadBytes.Length);
+ postings.PAYLOADS[k] = new BytesRef(payloadBytes);
+ }
+ }
+ }
+
+ if (offsets)
+ {
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, STARTOFFSET));
+ postings.START_OFFSETS[k] = ParseIntAt(STARTOFFSET.length);
+
+ ReadLine();
+ Debug.Assert(StringHelper.StartsWith(_scratch, ENDOFFSET));
+ postings.END_OFFSETS[k] = ParseIntAt(ENDOFFSET.length);
+ }
+ }
+ }
+ }
+ }
+ return new SimpleTVFields(this, fields);
+ }
- @Override
- public int size() {
- return fields.size();
- }
- }
-
- private static class SimpleTVTerms extends Terms {
- final SortedMap<BytesRef,SimpleTVPostings> terms;
- final bool hasOffsets;
- final bool hasPositions;
- final bool hasPayloads;
-
- SimpleTVTerms(bool hasOffsets, bool hasPositions, bool hasPayloads) {
- this.hasOffsets = hasOffsets;
- this.hasPositions = hasPositions;
- this.hasPayloads = hasPayloads;
- terms = new TreeMap<>();
- }
-
- @Override
- public TermsEnum iterator(TermsEnum reuse) {
- // TODO: reuse
- return new SimpleTVTermsEnum(terms);
- }
+ public override TermVectorsReader Clone()
+ {
+ if (_input == null)
+ {
+ throw new AlreadyClosedException("this TermVectorsReader is closed");
+ }
+ return new SimpleTextTermVectorsReader(_offsets, _input.Clone());
+ }
- @Override
- public Comparator<BytesRef> getComparator() {
- return BytesRef.getUTF8SortedAsUnicodeComparator();
- }
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing) return;
- @Override
- public long size() {
- return terms.size();
- }
+ try
+ {
+ IOUtils.Close(_input);
+ }
+ finally
+ {
+ _input = null;
+ _offsets = null;
+ }
+ }
- @Override
- public long getSumTotalTermFreq() {
- return -1;
- }
+ private void ReadLine()
+ {
+ SimpleTextUtil.ReadLine(_input, _scratch);
+ }
- @Override
- public long getSumDocFreq() {
- return terms.size();
- }
+ private int ParseIntAt(int offset)
+ {
+ UnicodeUtil.UTF8toUTF16(_scratch.Bytes, _scratch.Offset + offset, _scratch.Length - offset, _scratchUtf16);
+ return ArrayUtil.ParseInt(_scratchUtf16.Chars, 0, _scratchUtf16.length);
+ }
- @Override
- public int getDocCount() {
- return 1;
- }
+ private string ReadString(int offset, BytesRef scratch)
+ {
+ UnicodeUtil.UTF8toUTF16(scratch.Bytes, scratch.Offset + offset, scratch.Length - offset, _scratchUtf16);
+ return _scratchUtf16.ToString();
+ }
- @Override
- public bool hasFreqs() {
- return true;
- }
+ public override long RamBytesUsed()
+ {
+ return 0;
+ }
- @Override
- public bool hasOffsets() {
- return hasOffsets;
- }
+ public override void CheckIntegrity()
+ {
+ }
- @Override
- public bool hasPositions() {
- return hasPositions;
- }
-
- @Override
- public bool hasPayloads() {
- return hasPayloads;
- }
- }
-
- private static class SimpleTVPostings {
- private int freq;
- private int positions[];
- private int startOffsets[];
- private int endOffsets[];
- private BytesRef payloads[];
- }
-
- private static class SimpleTVTermsEnum extends TermsEnum {
- SortedMap<BytesRef,SimpleTVPostings> terms;
- Iterator<Map.Entry<BytesRef,SimpleTextTermVectorsReader.SimpleTVPostings>> iterator;
- Map.Entry<BytesRef,SimpleTextTermVectorsReader.SimpleTVPostings> current;
-
- SimpleTVTermsEnum(SortedMap<BytesRef,SimpleTVPostings> terms) {
- this.terms = terms;
- this.iterator = terms.entrySet().iterator();
- }
-
- @Override
- public SeekStatus seekCeil(BytesRef text) {
- iterator = terms.tailMap(text).entrySet().iterator();
- if (!iterator.hasNext()) {
- return SeekStatus.END;
- } else {
- return next().equals(text) ? SeekStatus.FOUND : SeekStatus.NOT_FOUND;
- }
- }
- @Override
- public void seekExact(long ord) {
- throw new UnsupportedOperationException();
- }
+ private class SimpleTVFields : Fields
+ {
+ private readonly SimpleTextTermVectorsReader _outerInstance;
+ private readonly SortedDictionary<string, SimpleTVTerms> _fields;
- @Override
- public BytesRef next() {
- if (!iterator.hasNext()) {
- return null;
- } else {
- current = iterator.next();
- return current.getKey();
- }
- }
+ internal SimpleTVFields(SimpleTextTermVectorsReader outerInstance, SortedDictionary<string, SimpleTVTerms> fields)
+ {
+ _outerInstance = outerInstance;
+ _fields = fields;
+ }
- @Override
- public BytesRef term() {
- return current.getKey();
- }
+ public override IEnumerator<string> GetEnumerator()
+ {
+ return _fields.Keys.GetEnumerator();
+ }
- @Override
- public long ord() {
- throw new UnsupportedOperationException();
- }
+ public override Terms Terms(string field)
+ {
+ return _fields[field];
+ }
- @Override
- public int docFreq() {
- return 1;
- }
+ public override int Size()
+ {
+ return _fields.Count;
+ }
+ }
- @Override
- public long totalTermFreq() {
- return current.getValue().freq;
- }
+ private class SimpleTVTerms : Terms
+ {
+ internal readonly SortedDictionary<BytesRef, SimpleTVPostings> TERMS;
+ private readonly bool _hasOffsetsRenamed;
+ private readonly bool _hasPositionsRenamed;
+ private readonly bool _hasPayloadsRenamed;
+
+ internal SimpleTVTerms(bool hasOffsets, bool hasPositions, bool hasPayloads)
+ {
+ _hasOffsetsRenamed = hasOffsets;
+ _hasPositionsRenamed = hasPositions;
+ _hasPayloadsRenamed = hasPayloads;
+ TERMS = new SortedDictionary<BytesRef, SimpleTVPostings>();
+ }
- @Override
- public DocsEnum docs(Bits liveDocs, DocsEnum reuse, int flags) {
- // TODO: reuse
- SimpleTVDocsEnum e = new SimpleTVDocsEnum();
- e.reset(liveDocs, (flags & DocsEnum.FLAG_FREQS) == 0 ? 1 : current.getValue().freq);
- return e;
- }
+ public override TermsEnum Iterator(TermsEnum reuse)
+ {
+ // TODO: reuse
+ return new SimpleTVTermsEnum(TERMS);
+ }
- @Override
- public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) {
- SimpleTVPostings postings = current.getValue();
- if (postings.positions == null && postings.startOffsets == null) {
- return null;
- }
- // TODO: reuse
- SimpleTVDocsAndPositionsEnum e = new SimpleTVDocsAndPositionsEnum();
- e.reset(liveDocs, postings.positions, postings.startOffsets, postings.endOffsets, postings.payloads);
- return e;
- }
+ public override IComparer<BytesRef> Comparator
+ {
+ get { return BytesRef.UTF8SortedAsUnicodeComparer; }
+ }
- @Override
- public Comparator<BytesRef> getComparator() {
- return BytesRef.getUTF8SortedAsUnicodeComparator();
- }
- }
-
- // note: these two enum classes are exactly like the Default impl...
- private static class SimpleTVDocsEnum extends DocsEnum {
- private bool didNext;
- private int doc = -1;
- private int freq;
- private Bits liveDocs;
-
- @Override
- public int freq() {
- Debug.Assert( freq != -1;
- return freq;
- }
+ public override long Size()
+ {
+ return TERMS.Count;
+ }
- @Override
- public int docID() {
- return doc;
- }
+ public override long SumTotalTermFreq
+ {
+ get { return -1; }
+ }
- @Override
- public int nextDoc() {
- if (!didNext && (liveDocs == null || liveDocs.get(0))) {
- didNext = true;
- return (doc = 0);
- } else {
- return (doc = NO_MORE_DOCS);
- }
- }
+ public override long SumDocFreq
+ {
+ get { return TERMS.Count; }
+ }
- @Override
- public int advance(int target) {
- return slowAdvance(target);
- }
+ public override int DocCount
+ {
+ get { return 1; }
+ }
- public void reset(Bits liveDocs, int freq) {
- this.liveDocs = liveDocs;
- this.freq = freq;
- this.doc = -1;
- didNext = false;
- }
-
- @Override
- public long cost() {
- return 1;
- }
- }
-
- private static class SimpleTVDocsAndPositionsEnum extends DocsAndPositionsEnum {
- private bool didNext;
- private int doc = -1;
- private int nextPos;
- private Bits liveDocs;
- private int[] positions;
- private BytesRef[] payloads;
- private int[] startOffsets;
- private int[] endOffsets;
-
- @Override
- public int freq() {
- if (positions != null) {
- return positions.length;
- } else {
- Debug.Assert( startOffsets != null;
- return startOffsets.length;
- }
- }
+ public override bool HasFreqs()
+ {
+ return true;
+ }
- @Override
- public int docID() {
- return doc;
- }
+ public override bool HasOffsets()
+ {
+ return _hasOffsetsRenamed;
+ }
- @Override
- public int nextDoc() {
- if (!didNext && (liveDocs == null || liveDocs.get(0))) {
- didNext = true;
- return (doc = 0);
- } else {
- return (doc = NO_MORE_DOCS);
- }
- }
+ public override bool HasPositions()
+ {
+ return _hasPositionsRenamed;
+ }
- @Override
- public int advance(int target) {
- return slowAdvance(target);
- }
+ public override bool HasPayloads()
+ {
+ return _hasPayloadsRenamed;
+ }
+ }
- public void reset(Bits liveDocs, int[] positions, int[] startOffsets, int[] endOffsets, BytesRef payloads[]) {
- this.liveDocs = liveDocs;
- this.positions = positions;
- this.startOffsets = startOffsets;
- this.endOffsets = endOffsets;
- this.payloads = payloads;
- this.doc = -1;
- didNext = false;
- nextPos = 0;
- }
+ private class SimpleTVPostings
+ {
+ internal int FREQ;
+ internal int[] POSITIONS;
+ internal int[] START_OFFSETS;
+ internal int[] END_OFFSETS;
+ internal BytesRef[] PAYLOADS;
+ }
- @Override
- public BytesRef getPayload() {
- return payloads == null ? null : payloads[nextPos-1];
- }
+ private class SimpleTVTermsEnum : TermsEnum
+ {
+ internal SortedMap<BytesRef, SimpleTVPostings> terms;
+ private IEnumerator<KeyValuePair<BytesRef, SimpleTVPostings>> _iterator;
+ private KeyValuePair<BytesRef, SimpleTVPostings> _current;
- @Override
- public int nextPosition() {
- Debug.Assert( (positions != null && nextPos < positions.length) ||
- startOffsets != null && nextPos < startOffsets.length;
- if (positions != null) {
- return positions[nextPos++];
- } else {
- nextPos++;
- return -1;
- }
- }
+ internal SimpleTVTermsEnum(SortedMap<BytesRef, SimpleTVPostings> terms)
+ {
+ this.terms = terms;
+ this._iterator = terms.EntrySet().GetEnumerator();
+ }
- @Override
- public int startOffset() {
- if (startOffsets == null) {
- return -1;
- } else {
- return startOffsets[nextPos-1];
- }
- }
+ public override SeekStatus SeekCeil(BytesRef text)
+ {
+ _iterator = terms.TailMap(text).entrySet().GetEnumerator();
+ //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
+ if (!_iterator.HasNext())
+ {
+ return SeekStatus.END;
+ }
+ else
+ {
+ return Next().Equals(text) ? SeekStatus.FOUND : SeekStatus.NOT_FOUND;
+ }
+ }
- @Override
- public int endOffset() {
- if (endOffsets == null) {
- return -1;
- } else {
- return endOffsets[nextPos-1];
- }
- }
-
- @Override
- public long cost() {
- return 1;
- }
- }
+ public override void SeekExact(long ord)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override BytesRef Next()
+ {
+ //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
+ if (!_iterator.HasNext())
+ {
+ return null;
+ }
+ else
+ {
+ //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
+ _current = _iterator.Next();
+ return _current.Key;
+ }
+ }
+
+ public override BytesRef Term()
+ {
+ return _current.Key;
+ }
+
+ public override long Ord()
+ {
+ throw new NotSupportedException();
+ }
+
+ public override int DocFreq()
+ {
+ return 1;
+ }
+
+ public override long TotalTermFreq()
+ {
+ return _current.Value.FREQ;
+ }
+
+ public override DocsEnum Docs(Bits liveDocs, DocsEnum reuse, int flags)
+ {
+ // TODO: reuse
+ var e = new SimpleTVDocsEnum();
+ e.Reset(liveDocs, (flags & DocsEnum.FLAG_FREQS) == 0 ? 1 : _current.Value.FREQ);
+ return e;
+ }
+
+ public override DocsAndPositionsEnum DocsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags)
+ {
+ SimpleTVPostings postings = _current.Value;
+ if (postings.POSITIONS == null && postings.START_OFFSETS == null)
+ return null;
+
+ // TODO: reuse
+ var e = new SimpleTVDocsAndPositionsEnum();
+ e.Reset(liveDocs, postings.POSITIONS, postings.START_OFFSETS, postings.END_OFFSETS, postings.PAYLOADS);
+ return e;
+ }
+
+ public override IComparer<BytesRef> Comparator
+ {
+ get { return BytesRef.UTF8SortedAsUnicodeComparer; }
+ }
+ }
- @Override
- public long ramBytesUsed() {
- return 0;
- }
+ // note: these two enum classes are exactly like the Default impl...
+ private sealed class SimpleTVDocsEnum : DocsEnum
+ {
+ private bool _didNext;
+ private int _doc = -1;
+ private int _freqRenamed;
+ private Bits _liveDocs;
+
+ public override int Freq()
+ {
+ Debug.Assert(_freqRenamed != -1);
+ return _freqRenamed;
+ }
+
+ public override int DocID()
+ {
+ return _doc;
+ }
+
+ public override int NextDoc()
+ {
+ if (_didNext || (_liveDocs != null && !_liveDocs.Get(0))) return (_doc = NO_MORE_DOCS);
+ _didNext = true;
+ return (_doc = 0);
+ }
+
+ public override int Advance(int target)
+ {
+ return SlowAdvance(target);
+ }
+
+ public void Reset(Bits liveDocs, int freq)
+ {
+ _liveDocs = liveDocs;
+ _freqRenamed = freq;
+ _doc = -1;
+ _didNext = false;
+ }
+
+ public override long Cost()
+ {
+ return 1;
+ }
+ }
+
+ private sealed class SimpleTVDocsAndPositionsEnum : DocsAndPositionsEnum
+ {
+ private bool _didNext;
+ private int _doc = -1;
+ private int _nextPos;
+ private Bits _liveDocs;
+ private int[] _positions;
+ private BytesRef[] _payloads;
+ private int[] _startOffsets;
+ private int[] _endOffsets;
+
+ public override int Freq()
+ {
+ if (_positions != null)
+ return _positions.Length;
+
+ Debug.Assert(_startOffsets != null);
+ return _startOffsets.Length;
+ }
+
+ public override int DocID()
+ {
+ return _doc;
+ }
+
+ public override int NextDoc()
+ {
+ if (_didNext || (_liveDocs != null && !_liveDocs.Get(0))) return (_doc = NO_MORE_DOCS);
+ _didNext = true;
+ return (_doc = 0);
+ }
+
+ public override int Advance(int target)
+ {
+ return SlowAdvance(target);
+ }
+
+ public void Reset(Bits liveDocs, int[] positions, int[] startOffsets, int[] endOffsets,
+ BytesRef[] payloads)
+ {
+ _liveDocs = liveDocs;
+ _positions = positions;
+ _startOffsets = startOffsets;
+ _endOffsets = endOffsets;
+ _payloads = payloads;
+ _doc = -1;
+ _didNext = false;
+ _nextPos = 0;
+ }
+
+ public override BytesRef Payload
+ {
+ get { return _payloads == null ? null : _payloads[_nextPos - 1]; }
+ }
+
+ public override int NextPosition()
+ {
+ Debug.Assert((_positions != null && _nextPos < _positions.Length) ||
+ _startOffsets != null && _nextPos < _startOffsets.Length);
+ if (_positions != null)
+ {
+ return _positions[_nextPos++];
+ }
+
+ _nextPos++;
+ return -1;
+ }
+
+ public override int StartOffset()
+ {
+ if (_startOffsets == null)
+ return -1;
+
+ return _startOffsets[_nextPos - 1];
+ }
+
+ public override int EndOffset()
+ {
+ if (_endOffsets == null)
+ {
+ return -1;
+ }
+
+ return _endOffsets[_nextPos - 1];
+ }
+
+ public override long Cost()
+ {
+ return 1;
+ }
+ }
+
+ }
- @Override
- public void checkIntegrity() {}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
index 5e497cc..67cc4e2 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
@@ -1,6 +1,4 @@
-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.
@@ -17,193 +15,224 @@ package org.apache.lucene.codecs.simpletext;
* limitations under the License.
*/
-import java.io.IOException;
-import java.util.Comparator;
-
-import org.apache.lucene.codecs.TermVectorsWriter;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-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 plain-text term vectors.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextTermVectorsWriter extends TermVectorsWriter {
-
- static final BytesRef END = new BytesRef("END");
- static final BytesRef DOC = new BytesRef("doc ");
- static final BytesRef NUMFIELDS = new BytesRef(" numfields ");
- static final BytesRef FIELD = new BytesRef(" field ");
- static final BytesRef FIELDNAME = new BytesRef(" name ");
- static final BytesRef FIELDPOSITIONS = new BytesRef(" positions ");
- static final BytesRef FIELDOFFSETS = new BytesRef(" offsets ");
- static final BytesRef FIELDPAYLOADS = new BytesRef(" payloads ");
- static final BytesRef FIELDTERMCOUNT = new BytesRef(" numterms ");
- static final BytesRef TERMTEXT = new BytesRef(" term ");
- static final BytesRef TERMFREQ = new BytesRef(" freq ");
- static final BytesRef POSITION = new BytesRef(" position ");
- static final BytesRef PAYLOAD = new BytesRef(" payload ");
- static final BytesRef STARTOFFSET = new BytesRef(" startoffset ");
- static final BytesRef ENDOFFSET = new BytesRef(" endoffset ");
-
- static final String VECTORS_EXTENSION = "vec";
-
- private final Directory directory;
- private final String segment;
- private IndexOutput out;
- private int numDocsWritten = 0;
- private final BytesRef scratch = new BytesRef();
- private bool offsets;
- private bool positions;
- private bool payloads;
-
- public SimpleTextTermVectorsWriter(Directory directory, String segment, IOContext context) {
- this.directory = directory;
- this.segment = segment;
- bool success = false;
- try {
- out = directory.createOutput(IndexFileNames.segmentFileName(segment, "", VECTORS_EXTENSION), context);
- success = true;
- } finally {
- if (!success) {
- abort();
- }
- }
- }
-
- @Override
- public void startDocument(int numVectorFields) {
- write(DOC);
- write(Integer.toString(numDocsWritten));
- newLine();
-
- write(NUMFIELDS);
- write(Integer.toString(numVectorFields));
- newLine();
- numDocsWritten++;
- }
-
- @Override
- public void startField(FieldInfo info, int numTerms, bool positions, bool offsets, bool payloads) {
- write(FIELD);
- write(Integer.toString(info.number));
- newLine();
-
- write(FIELDNAME);
- write(info.name);
- newLine();
-
- write(FIELDPOSITIONS);
- write(bool.toString(positions));
- newLine();
-
- write(FIELDOFFSETS);
- write(bool.toString(offsets));
- newLine();
-
- write(FIELDPAYLOADS);
- write(bool.toString(payloads));
- newLine();
-
- write(FIELDTERMCOUNT);
- write(Integer.toString(numTerms));
- newLine();
-
- this.positions = positions;
- this.offsets = offsets;
- this.payloads = payloads;
- }
-
- @Override
- public void startTerm(BytesRef term, int freq) {
- write(TERMTEXT);
- write(term);
- newLine();
-
- write(TERMFREQ);
- write(Integer.toString(freq));
- newLine();
- }
-
- @Override
- public void addPosition(int position, int startOffset, int endOffset, BytesRef payload) {
- Debug.Assert( positions || offsets;
-
- if (positions) {
- write(POSITION);
- write(Integer.toString(position));
- newLine();
-
- if (payloads) {
- write(PAYLOAD);
- if (payload != null) {
- Debug.Assert( payload.length > 0;
- write(payload);
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+ using System;
+ using System.Diagnostics;
+ using System.Collections.Generic;
+ using FieldInfo = Index.FieldInfo;
+ using FieldInfos = Index.FieldInfos;
+ using IndexFileNames = Index.IndexFileNames;
+ using Directory = Store.Directory;
+ using IOContext = Store.IOContext;
+ using IndexOutput = Store.IndexOutput;
+ using BytesRef = Util.BytesRef;
+ using IOUtils = Util.IOUtils;
+
+ /// <summary>
+ /// Writes plain-text term vectors.
+ /// <para>
+ /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+ /// @lucene.experimental
+ /// </para>
+ /// </summary>
+ public class SimpleTextTermVectorsWriter : TermVectorsWriter
+ {
+
+ internal static readonly BytesRef END = new BytesRef("END");
+ internal static readonly BytesRef DOC = new BytesRef("doc ");
+ internal static readonly BytesRef NUMFIELDS = new BytesRef(" numfields ");
+ internal static readonly BytesRef FIELD = new BytesRef(" field ");
+ internal static readonly BytesRef FIELDNAME = new BytesRef(" name ");
+ internal static readonly BytesRef FIELDPOSITIONS = new BytesRef(" positions ");
+ internal static readonly BytesRef FIELDOFFSETS = new BytesRef(" offsets ");
+ internal static readonly BytesRef FIELDPAYLOADS = new BytesRef(" payloads ");
+ internal static readonly BytesRef FIELDTERMCOUNT = new BytesRef(" numterms ");
+ internal static readonly BytesRef TERMTEXT = new BytesRef(" term ");
+ internal static readonly BytesRef TERMFREQ = new BytesRef(" freq ");
+ internal static readonly BytesRef POSITION = new BytesRef(" position ");
+ internal static readonly BytesRef PAYLOAD = new BytesRef(" payload ");
+ internal static readonly BytesRef STARTOFFSET = new BytesRef(" startoffset ");
+ internal static readonly BytesRef ENDOFFSET = new BytesRef(" endoffset ");
+
+ internal const string VECTORS_EXTENSION = "vec";
+
+ private readonly Directory directory;
+ private readonly string segment;
+ private IndexOutput _output;
+ private int numDocsWritten = 0;
+ private readonly BytesRef scratch = new BytesRef();
+ private bool offsets;
+ private bool positions;
+ private bool payloads;
+
+ public SimpleTextTermVectorsWriter(Directory directory, string segment, IOContext context)
+ {
+ this.directory = directory;
+ this.segment = segment;
+ bool success = false;
+ try
+ {
+ _output = directory.CreateOutput(IndexFileNames.SegmentFileName(segment, "", VECTORS_EXTENSION), context);
+ success = true;
+ }
+ finally
+ {
+ if (!success)
+ {
+ Abort();
+ }
+ }
+ }
+
+ public override void StartDocument(int numVectorFields)
+ {
+ Write(DOC);
+ Write(Convert.ToString(numDocsWritten));
+ NewLine();
+
+ Write(NUMFIELDS);
+ Write(Convert.ToString(numVectorFields));
+ NewLine();
+ numDocsWritten++;
+ }
+
+ public override void StartField(FieldInfo info, int numTerms, bool positions, bool offsets, bool payloads)
+ {
+ Write(FIELD);
+ Write(Convert.ToString(info.Number));
+ NewLine();
+
+ Write(FIELDNAME);
+ Write(info.Name);
+ NewLine();
+
+ Write(FIELDPOSITIONS);
+ Write(Convert.ToString(positions));
+ NewLine();
+
+ Write(FIELDOFFSETS);
+ Write(Convert.ToString(offsets));
+ NewLine();
+
+ Write(FIELDPAYLOADS);
+ Write(Convert.ToString(payloads));
+ NewLine();
+
+ Write(FIELDTERMCOUNT);
+ Write(Convert.ToString(numTerms));
+ NewLine();
+
+ this.positions = positions;
+ this.offsets = offsets;
+ this.payloads = payloads;
+ }
+
+ public override void StartTerm(BytesRef term, int freq)
+ {
+ Write(TERMTEXT);
+ Write(term);
+ NewLine();
+
+ Write(TERMFREQ);
+ Write(Convert.ToString(freq));
+ NewLine();
+ }
+
+ public override void AddPosition(int position, int startOffset, int endOffset, BytesRef payload)
+ {
+ Debug.Assert(positions || offsets);
+
+ if (positions)
+ {
+ Write(POSITION);
+ Write(Convert.ToString(position));
+ NewLine();
+
+ if (payloads)
+ {
+ Write(PAYLOAD);
+ if (payload != null)
+ {
+ Debug.Assert(payload.Length > 0);
+ Write(payload);
+ }
+ NewLine();
+ }
+ }
+
+ if (offsets)
+ {
+ Write(STARTOFFSET);
+ Write(Convert.ToString(startOffset));
+ NewLine();
+
+ Write(ENDOFFSET);
+ Write(Convert.ToString(endOffset));
+ NewLine();
+ }
+ }
+
+ public override void Abort()
+ {
+ try
+ {
+ Dispose();
+ }
+ finally
+ {
+
+ IOUtils.DeleteFilesIgnoringExceptions(directory,
+ IndexFileNames.SegmentFileName(segment, "", VECTORS_EXTENSION));
+ }
+ }
+
+ public override void Finish(FieldInfos fis, int numDocs)
+ {
+ if (numDocsWritten != numDocs)
+ {
+ throw new Exception("mergeVectors produced an invalid result: mergedDocs is " + numDocs +
+ " but vec numDocs is " + numDocsWritten + " file=" + _output.ToString() +
+ "; now aborting this merge to prevent index corruption");
+ }
+ Write(END);
+ NewLine();
+ SimpleTextUtil.WriteChecksum(_output, scratch);
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing) return;
+
+ try
+ {
+ IOUtils.Close(_output);
+ }
+ finally
+ {
+ _output = null;
+ }
+ }
+
+ public override IComparer<BytesRef> Comparator
+ {
+ get { return BytesRef.UTF8SortedAsUnicodeComparer; }
+ }
+
+ private void Write(string s)
+ {
+ SimpleTextUtil.Write(_output, s, scratch);
+ }
+
+ private void Write(BytesRef bytes)
+ {
+ SimpleTextUtil.Write(_output, bytes);
+ }
+
+ private void NewLine()
+ {
+ SimpleTextUtil.WriteNewline(_output);
}
- newLine();
- }
- }
-
- if (offsets) {
- write(STARTOFFSET);
- write(Integer.toString(startOffset));
- newLine();
-
- write(ENDOFFSET);
- write(Integer.toString(endOffset));
- newLine();
- }
- }
-
- @Override
- public void abort() {
- try {
- close();
- } catch (Throwable ignored) {}
- IOUtils.deleteFilesIgnoringExceptions(directory, IndexFileNames.segmentFileName(segment, "", VECTORS_EXTENSION));
- }
-
- @Override
- public void finish(FieldInfos fis, int numDocs) {
- if (numDocsWritten != numDocs) {
- throw new RuntimeException("mergeVectors produced an invalid result: mergedDocs is " + numDocs + " but vec numDocs is " + numDocsWritten + " file=" + out.toString() + "; now aborting this merge to prevent index corruption");
- }
- write(END);
- newLine();
- SimpleTextUtil.writeChecksum(out, scratch);
- }
-
- @Override
- public void close() {
- try {
- IOUtils.close(out);
- } finally {
- out = null;
}
- }
-
- @Override
- public Comparator<BytesRef> getComparator() {
- return BytesRef.getUTF8SortedAsUnicodeComparator();
- }
-
- private void write(String s) {
- SimpleTextUtil.write(out, s, scratch);
- }
-
- private void write(BytesRef bytes) {
- SimpleTextUtil.write(out, bytes);
- }
-
- private void newLine() {
- SimpleTextUtil.writeNewline(out);
- }
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextUtil.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextUtil.cs
index edb4da7..447b1bb 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextUtil.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextUtil.cs
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -18,28 +18,32 @@
namespace Lucene.Net.Codecs.SimpleText
{
- using System;
- using Lucene.Net.Index;
- using Lucene.Net.Store;
- using Lucene.Net.Util;
+ using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
+ using ChecksumIndexInput = Store.ChecksumIndexInput;
+ using DataInput = Store.DataInput;
+ using DataOutput = Store.DataOutput;
+ using IndexOutput = Store.IndexOutput;
+ using BytesRef = Util.BytesRef;
+ using StringHelper = Util.StringHelper;
+ using UnicodeUtil = Util.UnicodeUtil;
- public static class SimpleTextUtil
+ internal class SimpleTextUtil
{
- public const byte NEWLINE = 10;
- public const byte ESCAPE = 92;
- public static BytesRef CHECKSUM = new BytesRef("checksum ");
+ public const sbyte NEWLINE = 10;
+ public const sbyte ESCAPE = 92;
+ internal static readonly BytesRef CHECKSUM = new BytesRef("checksum ");
- public static void Write(DataOutput output, String s, BytesRef scratch)
+ public static void Write(DataOutput output, string s, BytesRef scratch)
{
- UnicodeUtil.UTF16toUTF8(s, 0, s.Length, scratch);
+ UnicodeUtil.UTF16toUTF8(s.ToCharArray(), 0, s.Length, scratch);
Write(output, scratch);
}
public static void Write(DataOutput output, BytesRef b)
{
- for (int i = 0; i < b.Length; i++)
+ for (var i = 0; i < b.Length; i++)
{
- sbyte bx = b.Bytes[b.Offset + i];
+ var bx = b.Bytes[b.Offset + i];
if (bx == NEWLINE || bx == ESCAPE)
{
output.WriteByte(ESCAPE);
@@ -55,17 +59,17 @@ namespace Lucene.Net.Codecs.SimpleText
public static void ReadLine(DataInput input, BytesRef scratch)
{
- int upto = 0;
+ var upto = 0;
while (true)
{
- byte b = input.ReadByte();
+ var b = input.ReadSByte();
if (scratch.Bytes.Length == upto)
{
scratch.Grow(1 + upto);
}
if (b == ESCAPE)
{
- scratch.Bytes[upto++] = input.ReadByte();
+ scratch.Bytes[upto++] = input.ReadSByte();
}
else
{
@@ -88,29 +92,29 @@ namespace Lucene.Net.Codecs.SimpleText
// Pad with zeros so different checksum values use the
// same number of bytes
// (BaseIndexFileFormatTestCase.testMergeStability cares):
- String checksum = String.Format(Locale.ROOT, "%020d", output.Checksum);
- SimpleTextUtil.Write(output, CHECKSUM);
- SimpleTextUtil.Write(output, checksum, scratch);
- SimpleTextUtil.WriteNewline(output);
+ var checksum = string.Format("{0:D}", output.Checksum);
+ Write(output, CHECKSUM);
+ Write(output, checksum, scratch);
+ WriteNewline(output);
}
public static void CheckFooter(ChecksumIndexInput input)
{
- BytesRef scratch = new BytesRef();
- String expectedChecksum = String.Format(Locale.ROOT, "%020d", input.Checksum);
- SimpleTextUtil.ReadLine(input, scratch);
+ var scratch = new BytesRef();
+ var expectedChecksum = string.Format("{0:D}", input.Checksum);
+ ReadLine(input, scratch);
+
if (StringHelper.StartsWith(scratch, CHECKSUM) == false)
{
throw new CorruptIndexException("SimpleText failure: expected checksum line but got " +
scratch.Utf8ToString() + " (resource=" + input + ")");
}
- String actualChecksum =
- new BytesRef(scratch.Bytes, CHECKSUM.Length, scratch.Length - CHECKSUM.Length).Utf8ToString();
+ var actualChecksum =
+ (new BytesRef(scratch.Bytes, CHECKSUM.Length, scratch.Length - CHECKSUM.Length)).Utf8ToString();
if (!expectedChecksum.Equals(actualChecksum))
{
throw new CorruptIndexException("SimpleText checksum failure: " + actualChecksum + " != " +
- expectedChecksum +
- " (resource=" + input + ")");
+ expectedChecksum + " (resource=" + input + ")");
}
if (input.Length() != input.FilePointer)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/StringHelperClass.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/StringHelperClass.cs b/src/Lucene.Net.Codecs/StringHelperClass.cs
new file mode 100644
index 0000000..a9ba97a
--- /dev/null
+++ b/src/Lucene.Net.Codecs/StringHelperClass.cs
@@ -0,0 +1,119 @@
+/*
+* 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.
+*/
+
+//-------------------------------------------------------------------------------------------
+// Copyright © 2007 - 2014 Tangible Software Solutions Inc.
+// This class can be used by anyone provided that the copyright notice remains intact.
+//
+// This class is used to convert some aspects of the Java String class.
+//-------------------------------------------------------------------------------------------
+
+namespace Lucene.Net.Codes
+{
+
+ internal static class StringHelperClass
+ {
+ //----------------------------------------------------------------------------------
+ // This method replaces the Java String.substring method when 'start' is a
+ // method call or calculated value to ensure that 'start' is obtained just once.
+ //----------------------------------------------------------------------------------
+ internal static string SubstringSpecial(this string self, int start, int end)
+ {
+ return self.Substring(start, end - start);
+ }
+
+ //------------------------------------------------------------------------------------
+ // This method is used to replace calls to the 2-arg Java String.startsWith method.
+ //------------------------------------------------------------------------------------
+ internal static bool StartsWith(this string self, string prefix, int toffset)
+ {
+ return self.IndexOf(prefix, toffset, System.StringComparison.Ordinal) == toffset;
+ }
+
+ //------------------------------------------------------------------------------
+ // This method is used to replace most calls to the Java String.split method.
+ //------------------------------------------------------------------------------
+ internal static string[] Split(this string self, string regexDelimiter, bool trimTrailingEmptyStrings)
+ {
+ string[] splitArray = System.Text.RegularExpressions.Regex.Split(self, regexDelimiter);
+
+ if (trimTrailingEmptyStrings)
+ {
+ if (splitArray.Length > 1)
+ {
+ for (int i = splitArray.Length; i > 0; i--)
+ {
+ if (splitArray[i - 1].Length > 0)
+ {
+ if (i < splitArray.Length)
+ System.Array.Resize(ref splitArray, i);
+
+ break;
+ }
+ }
+ }
+ }
+
+ return splitArray;
+ }
+
+ #region These methods are used to replace calls to some Java String constructors.
+
+ internal static string NewString(sbyte[] bytes)
+ {
+ return NewString(bytes, 0, bytes.Length);
+ }
+
+ internal static string NewString(sbyte[] bytes, int index, int count)
+ {
+ return System.Text.Encoding.UTF8.GetString((byte[]) (object) bytes, index, count);
+ }
+
+ internal static string NewString(sbyte[] bytes, string encoding)
+ {
+ return NewString(bytes, 0, bytes.Length, encoding);
+ }
+
+ internal static string NewString(sbyte[] bytes, int index, int count, string encoding)
+ {
+ return System.Text.Encoding.GetEncoding(encoding).GetString((byte[]) (object) bytes, index, count);
+ }
+
+ #endregion
+
+ #region These methods are used to replace calls to the Java String.getBytes methods.
+
+ internal static sbyte[] GetBytes(this string self)
+ {
+ return GetSBytesForEncoding(System.Text.Encoding.UTF8, self);
+ }
+
+ internal static sbyte[] GetBytes(this string self, string encoding)
+ {
+ return GetSBytesForEncoding(System.Text.Encoding.GetEncoding(encoding), self);
+ }
+
+ private static sbyte[] GetSBytesForEncoding(System.Text.Encoding encoding, string s)
+ {
+ sbyte[] sbytes = new sbyte[encoding.GetByteCount(s)];
+ encoding.GetBytes(s, 0, s.Length, (byte[]) (object) sbytes, 0);
+ return sbytes;
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Core/Search/MultiTermQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Search/MultiTermQuery.cs b/src/Lucene.Net.Core/Search/MultiTermQuery.cs
index c2bd033..8952e69 100644
--- a/src/Lucene.Net.Core/Search/MultiTermQuery.cs
+++ b/src/Lucene.Net.Core/Search/MultiTermQuery.cs
@@ -57,7 +57,7 @@ namespace Lucene.Net.Search
/// a priority queue to only collect competitive terms
/// and not hit this limitation.
///
- /// Note that org.apache.lucene.queryparser.classic.QueryParser produces
+ /// Note that queryparser.classic.QueryParser produces
/// MultiTermQueries using {@link
/// #CONSTANT_SCORE_AUTO_REWRITE_DEFAULT} by default.
/// </summary>
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Core/Store/Directory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/Directory.cs b/src/Lucene.Net.Core/Store/Directory.cs
index a485343..8286867 100644
--- a/src/Lucene.Net.Core/Store/Directory.cs
+++ b/src/Lucene.Net.Core/Store/Directory.cs
@@ -27,16 +27,16 @@ namespace Lucene.Net.Store
/// are created. Once a file is created it may only be opened for read, or
/// deleted. Random access is permitted both when reading and writing.
///
- /// <p> Java's i/o APIs not used directly, but rather all i/o is
+ /// Java's i/o APIs not used directly, but rather all i/o is
/// through this API. this permits things such as: <ul>
- /// <li> implementation of RAM-based indices;
- /// <li> implementation indices stored in a database, via JDBC;
- /// <li> implementation of an index as a single file;
+ /// <li> implementation of RAM-based indices;</li>
+ /// <li> implementation indices stored in a database, via JDBC;</li>
+ /// <li> implementation of an index as a single file;</li>
/// </ul>
///
/// Directory locking is implemented by an instance of {@link
/// LockFactory}, and can be changed for each Directory
- /// instance using <seealso cref="#setLockFactory"/>.
+ /// instance using <seealso cref="setLockFactory"/>.
///
/// </summary>
public abstract class Directory : IDisposable