public DirectField(SegmentReadState state, string field, Terms termsIn, int minSkipCount, int lowFreqCutoff) { FieldInfo fieldInfo = state.FieldInfos.FieldInfo(field); sumTotalTermFreq = termsIn.SumTotalTermFreq; sumDocFreq = termsIn.SumDocFreq; docCount = termsIn.DocCount; int numTerms = (int) termsIn.Size(); if (numTerms == -1) { throw new System.ArgumentException("codec does not provide Terms.size()"); } terms = new TermAndSkip[numTerms]; termOffsets = new int[1 + numTerms]; byte[] termBytes = new byte[1024]; this.minSkipCount = minSkipCount; hasFreq = fieldInfo.FieldIndexOptions.Value.CompareTo(IndexOptions.DOCS_ONLY) > 0; hasPos = fieldInfo.FieldIndexOptions.Value.CompareTo(IndexOptions.DOCS_AND_FREQS) > 0; hasOffsets_Renamed = fieldInfo.FieldIndexOptions.Value.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) > 0; hasPayloads_Renamed = fieldInfo.HasPayloads(); BytesRef term; DocsEnum docsEnum = null; DocsAndPositionsEnum docsAndPositionsEnum = null; TermsEnum termsEnum = termsIn.Iterator(null); int termOffset = 0; IntArrayWriter scratch = new IntArrayWriter(); // Used for payloads, if any: RAMOutputStream ros = new RAMOutputStream(); // if (DEBUG) { // System.out.println("\nLOAD terms seg=" + state.segmentInfo.name + " field=" + field + " hasOffsets=" + hasOffsets + " hasFreq=" + hasFreq + " hasPos=" + hasPos + " hasPayloads=" + hasPayloads); // } while ((term = termsEnum.Next()) != null) { int docFreq = termsEnum.DocFreq(); long totalTermFreq = termsEnum.TotalTermFreq(); // if (DEBUG) { // System.out.println(" term=" + term.utf8ToString()); // } termOffsets[count] = termOffset; if (termBytes.Length < (termOffset + term.Length)) { termBytes = ArrayUtil.Grow(termBytes, termOffset + term.Length); } Array.Copy(term.Bytes, term.Offset, termBytes, termOffset, term.Length); termOffset += term.Length; termOffsets[count + 1] = termOffset; if (hasPos) { docsAndPositionsEnum = termsEnum.DocsAndPositions(null, docsAndPositionsEnum); } else { docsEnum = termsEnum.Docs(null, docsEnum); } TermAndSkip ent; DocsEnum docsEnum2; docsEnum2 = hasPos ? docsAndPositionsEnum : docsEnum; int docID; if (docFreq <= lowFreqCutoff) { ros.Reset(); // Pack postings for low-freq terms into a single int[]: while ((docID = docsEnum2.NextDoc()) != DocsEnum.NO_MORE_DOCS) { scratch.Add(docID); if (hasFreq) { int freq = docsEnum2.Freq(); scratch.Add(freq); if (hasPos) { for (int pos = 0; pos < freq; pos++) { scratch.Add(docsAndPositionsEnum.NextPosition()); if (hasOffsets_Renamed) { scratch.Add(docsAndPositionsEnum.StartOffset()); scratch.Add(docsAndPositionsEnum.EndOffset()); } if (hasPayloads_Renamed) { BytesRef payload = docsAndPositionsEnum.Payload; if (payload != null) { scratch.Add(payload.Length); ros.WriteBytes(payload.Bytes, payload.Offset, payload.Length); } else { scratch.Add(0); } } } } } } byte[] payloads; if (hasPayloads_Renamed) { ros.Flush(); payloads = new byte[(int) ros.Length]; ros.WriteTo(payloads, 0); } else { payloads = null; } int[] postings = scratch.Get(); ent = new LowFreqTerm(postings, payloads, docFreq, (int) totalTermFreq); } else { var docs = new int[docFreq]; int[] freqs; int[][] positions; byte[][][] payloads; if (hasFreq) { freqs = new int[docFreq]; if (hasPos) { positions = new int[docFreq][]; if (hasPayloads_Renamed) { payloads = new byte[docFreq][][]; } else { payloads = null; } } else { positions = null; payloads = null; } } else { freqs = null; positions = null; payloads = null; } // Use separate int[] for the postings for high-freq // terms: int upto = 0; while ((docID = docsEnum2.NextDoc()) != DocsEnum.NO_MORE_DOCS) { docs[upto] = docID; if (hasFreq) { int freq = docsEnum2.Freq(); freqs[upto] = freq; if (hasPos) { int mult; if (hasOffsets_Renamed) { mult = 3; } else { mult = 1; } if (hasPayloads_Renamed) { payloads[upto] = new byte[freq][]; } positions[upto] = new int[mult*freq]; int posUpto = 0; for (int pos = 0; pos < freq; pos++) { positions[upto][posUpto] = docsAndPositionsEnum.NextPosition(); if (hasPayloads_Renamed) { BytesRef payload = docsAndPositionsEnum.Payload; if (payload != null) { var payloadBytes = new byte[payload.Length]; Array.Copy(payload.Bytes, payload.Offset, payloadBytes, 0, payload.Length); payloads[upto][pos] = payloadBytes; } } posUpto++; if (hasOffsets_Renamed) { positions[upto][posUpto++] = docsAndPositionsEnum.StartOffset(); positions[upto][posUpto++] = docsAndPositionsEnum.EndOffset(); } } } } upto++; } Debug.Assert(upto == docFreq); ent = new HighFreqTerm(docs, freqs, positions, payloads, totalTermFreq); } terms[count] = ent; SetSkips(count, termBytes); count++; } // End sentinel: termOffsets[count] = termOffset; FinishSkips(); //System.out.println(skipCount + " skips: " + field); this.termBytes = new byte[termOffset]; Array.Copy(termBytes, 0, this.termBytes, 0, termOffset); // Pack skips: this.skips = new int[skipCount]; this.skipOffsets = new int[1 + numTerms]; int skipOffset = 0; for (int i = 0; i < numTerms; i++) { int[] termSkips = terms[i].skips; skipOffsets[i] = skipOffset; if (termSkips != null) { Array.Copy(termSkips, 0, skips, skipOffset, termSkips.Length); skipOffset += termSkips.Length; terms[i].skips = null; } } this.skipOffsets[numTerms] = skipOffset; Debug.Assert(skipOffset == skipCount); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public DirectField(index.SegmentReadState state, String field, index.Terms termsIn, int minSkipCount, int lowFreqCutoff) throws java.io.IOException public DirectField(SegmentReadState state, string field, Terms termsIn, int minSkipCount, int lowFreqCutoff) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final index.FieldInfo fieldInfo = state.fieldInfos.fieldInfo(field); FieldInfo fieldInfo = state.fieldInfos.fieldInfo(field); sumTotalTermFreq = termsIn.SumTotalTermFreq; sumDocFreq = termsIn.SumDocFreq; docCount = termsIn.DocCount; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int numTerms = (int) termsIn.size(); int numTerms = (int) termsIn.size(); if (numTerms == -1) { throw new System.ArgumentException("codec does not provide Terms.size()"); } terms = new TermAndSkip[numTerms]; termOffsets = new int[1 + numTerms]; sbyte[] termBytes = new sbyte[1024]; this.minSkipCount = minSkipCount; hasFreq = fieldInfo.IndexOptions.compareTo(IndexOptions.DOCS_ONLY) > 0; hasPos = fieldInfo.IndexOptions.compareTo(IndexOptions.DOCS_AND_FREQS) > 0; hasOffsets_Renamed = fieldInfo.IndexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) > 0; hasPayloads_Renamed = fieldInfo.hasPayloads(); BytesRef term; DocsEnum docsEnum = null; DocsAndPositionsEnum docsAndPositionsEnum = null; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final index.TermsEnum termsEnum = termsIn.iterator(null); TermsEnum termsEnum = termsIn.iterator(null); int termOffset = 0; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final IntArrayWriter scratch = new IntArrayWriter(); IntArrayWriter scratch = new IntArrayWriter(); // Used for payloads, if any: //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final store.RAMOutputStream ros = new store.RAMOutputStream(); RAMOutputStream ros = new RAMOutputStream(); // if (DEBUG) { // System.out.println("\nLOAD terms seg=" + state.segmentInfo.name + " field=" + field + " hasOffsets=" + hasOffsets + " hasFreq=" + hasFreq + " hasPos=" + hasPos + " hasPayloads=" + hasPayloads); // } while ((term = termsEnum.next()) != null) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int docFreq = termsEnum.docFreq(); int docFreq = termsEnum.docFreq(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long totalTermFreq = termsEnum.totalTermFreq(); long totalTermFreq = termsEnum.totalTermFreq(); // if (DEBUG) { // System.out.println(" term=" + term.utf8ToString()); // } termOffsets[count] = termOffset; if (termBytes.Length < (termOffset + term.length)) { termBytes = ArrayUtil.grow(termBytes, termOffset + term.length); } Array.Copy(term.bytes, term.offset, termBytes, termOffset, term.length); termOffset += term.length; termOffsets[count + 1] = termOffset; if (hasPos) { docsAndPositionsEnum = termsEnum.docsAndPositions(null, docsAndPositionsEnum); } else { docsEnum = termsEnum.docs(null, docsEnum); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TermAndSkip ent; TermAndSkip ent; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final index.DocsEnum docsEnum2; DocsEnum docsEnum2; if (hasPos) { docsEnum2 = docsAndPositionsEnum; } else { docsEnum2 = docsEnum; } int docID; if (docFreq <= lowFreqCutoff) { ros.reset(); // Pack postings for low-freq terms into a single int[]: while ((docID = docsEnum2.nextDoc()) != DocsEnum.NO_MORE_DOCS) { scratch.add(docID); if (hasFreq) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int freq = docsEnum2.freq(); int freq = docsEnum2.freq(); scratch.add(freq); if (hasPos) { for (int pos = 0; pos < freq; pos++) { scratch.add(docsAndPositionsEnum.nextPosition()); if (hasOffsets_Renamed) { scratch.add(docsAndPositionsEnum.startOffset()); scratch.add(docsAndPositionsEnum.endOffset()); } if (hasPayloads_Renamed) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final util.BytesRef payload = docsAndPositionsEnum.getPayload(); BytesRef payload = docsAndPositionsEnum.Payload; if (payload != null) { scratch.add(payload.length); ros.writeBytes(payload.bytes, payload.offset, payload.length); } else { scratch.add(0); } } } } } } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final byte[] payloads; sbyte[] payloads; if (hasPayloads_Renamed) { ros.flush(); payloads = new sbyte[(int) ros.length()]; ros.writeTo(payloads, 0); } else { payloads = null; } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] postings = scratch.get(); int[] postings = scratch.get(); ent = new LowFreqTerm(postings, payloads, docFreq, (int) totalTermFreq); } else { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] docs = new int[docFreq]; int[] docs = new int[docFreq]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] freqs; int[] freqs; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[][] positions; int[][] positions; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final byte[][][] payloads; sbyte[][][] payloads; if (hasFreq) { freqs = new int[docFreq]; if (hasPos) { positions = new int[docFreq][]; if (hasPayloads_Renamed) { payloads = new sbyte[docFreq][][]; } else { payloads = null; } } else { positions = null; payloads = null; } } else { freqs = null; positions = null; payloads = null; } // Use separate int[] for the postings for high-freq // terms: int upto = 0; while ((docID = docsEnum2.nextDoc()) != DocsEnum.NO_MORE_DOCS) { docs[upto] = docID; if (hasFreq) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int freq = docsEnum2.freq(); int freq = docsEnum2.freq(); freqs[upto] = freq; if (hasPos) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int mult; int mult; if (hasOffsets_Renamed) { mult = 3; } else { mult = 1; } if (hasPayloads_Renamed) { payloads[upto] = new sbyte[freq][]; } positions[upto] = new int[mult*freq]; int posUpto = 0; for (int pos = 0; pos < freq; pos++) { positions[upto][posUpto] = docsAndPositionsEnum.nextPosition(); if (hasPayloads_Renamed) { BytesRef payload = docsAndPositionsEnum.Payload; if (payload != null) { sbyte[] payloadBytes = new sbyte[payload.length]; Array.Copy(payload.bytes, payload.offset, payloadBytes, 0, payload.length); payloads[upto][pos] = payloadBytes; } } posUpto++; if (hasOffsets_Renamed) { positions[upto][posUpto++] = docsAndPositionsEnum.startOffset(); positions[upto][posUpto++] = docsAndPositionsEnum.endOffset(); } } } } upto++; } Debug.Assert(upto == docFreq); ent = new HighFreqTerm(docs, freqs, positions, payloads, totalTermFreq); } terms[count] = ent; setSkips(count, termBytes); count++; } // End sentinel: termOffsets[count] = termOffset; finishSkips(); //System.out.println(skipCount + " skips: " + field); this.termBytes = new sbyte[termOffset]; Array.Copy(termBytes, 0, this.termBytes, 0, termOffset); // Pack skips: this.skips = new int[skipCount]; this.skipOffsets = new int[1 + numTerms]; int skipOffset = 0; for (int i = 0; i < numTerms; i++) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] termSkips = terms[i].skips; int[] termSkips = terms[i].skips; skipOffsets[i] = skipOffset; if (termSkips != null) { Array.Copy(termSkips, 0, skips, skipOffset, termSkips.Length); skipOffset += termSkips.Length; terms[i].skips = null; } } this.skipOffsets[numTerms] = skipOffset; Debug.Assert(skipOffset == skipCount); }