25 namespace Lucene.Net.Index
46 this.fieldInfos = fieldInfos;
59 tvx.WriteLong(tvd.FilePointer);
60 tvx.WriteLong(tvf.FilePointer);
64 int numFields = vectors.Length;
65 tvd.WriteVInt(numFields);
67 var fieldPointers =
new long[numFields];
69 for (
int i = 0; i < numFields; i++)
71 fieldPointers[i] = tvf.FilePointer;
73 int fieldNumber = fieldInfos.FieldNumber(vectors[i].
Field);
76 tvd.WriteVInt(fieldNumber);
78 int numTerms = vectors[i].
Size;
79 tvf.WriteVInt(numTerms);
90 tpVector = (TermPositionVector) vectors[i];
92 storeOffsets = tpVector.
Size > 0 && tpVector.
GetOffsets(0) != null;
93 bits = (byte) ((storePositions?
TermVectorsReader.STORE_POSITIONS_WITH_TERMVECTOR: (byte) 0) + (storeOffsets?
TermVectorsReader.STORE_OFFSET_WITH_TERMVECTOR: (byte) 0));
99 storePositions =
false;
100 storeOffsets =
false;
105 System.String[] terms = vectors[i].
GetTerms();
109 utf8Results[1].length = 0;
111 for (
int j = 0; j < numTerms; j++)
114 UnicodeUtil.UTF16toUTF8(terms[j], 0, terms[j].Length, utf8Results[utf8Upto]);
116 int start =
StringHelper.BytesDifference(utf8Results[1 - utf8Upto].result, utf8Results[1 - utf8Upto].length, utf8Results[utf8Upto].result, utf8Results[utf8Upto].length);
117 int length = utf8Results[utf8Upto].length - start;
118 tvf.WriteVInt(start);
119 tvf.WriteVInt(length);
120 tvf.WriteBytes(utf8Results[utf8Upto].result, start, length);
121 utf8Upto = 1 - utf8Upto;
123 int termFreq = freqs[j];
125 tvf.WriteVInt(termFreq);
130 if (positions == null)
131 throw new System.SystemException(
"Trying to write positions that are null!");
132 System.Diagnostics.Debug.Assert(positions.Length == termFreq);
135 int lastPosition = 0;
136 foreach (
int position
in positions)
138 tvf.WriteVInt(position - lastPosition);
139 lastPosition = position;
147 throw new System.SystemException(
"Trying to write offsets that are null!");
148 System.Diagnostics.Debug.Assert(offsets.Length == termFreq);
151 int lastEndOffset = 0;
156 tvf.WriteVInt(startOffset - lastEndOffset);
157 tvf.WriteVInt(endOffset - startOffset);
158 lastEndOffset = endOffset;
167 long lastFieldPointer = fieldPointers[0];
168 for (
int i = 1; i < numFields; i++)
170 long fieldPointer = fieldPointers[i];
171 tvd.WriteVLong(fieldPointer - lastFieldPointer);
172 lastFieldPointer = fieldPointer;
184 internal void AddRawDocuments(
TermVectorsReader reader,
int[] tvdLengths,
int[] tvfLengths,
int numDocs)
186 long tvdPosition = tvd.FilePointer;
187 long tvfPosition = tvf.FilePointer;
188 long tvdStart = tvdPosition;
189 long tvfStart = tvfPosition;
190 for (
int i = 0; i < numDocs; i++)
192 tvx.WriteLong(tvdPosition);
193 tvdPosition += tvdLengths[i];
194 tvx.WriteLong(tvfPosition);
195 tvfPosition += tvfLengths[i];
197 tvd.CopyBytes(reader.GetTvdStream(), tvdPosition - tvdStart);
198 tvf.CopyBytes(reader.GetTvfStream(), tvfPosition - tvfStart);
199 System.Diagnostics.Debug.Assert(tvd.FilePointer == tvdPosition);
200 System.Diagnostics.Debug.Assert(tvf.FilePointer == tvfPosition);
204 public void Dispose()
210 System.IO.IOException keep = null;
216 catch (System.IO.IOException e)
225 catch (System.IO.IOException e)
235 catch (System.IO.IOException e)
242 throw new System.IO.IOException(keep.StackTrace);