19 using Lucene.Net.Analysis.Tokenattributes;
20 using Lucene.Net.Documents;
24 namespace Lucene.Net.Index
37 internal bool doVectors;
38 internal bool doVectorPositions;
39 internal bool doVectorOffsets;
41 internal int maxNumPostings;
46 this.termsHashPerField = termsHashPerField;
47 this.perThread = perThread;
48 this.termsWriter = perThread.termsWriter;
49 this.fieldInfo = fieldInfo;
50 docState = termsHashPerField.docState;
51 fieldState = termsHashPerField.fieldState;
54 internal override int GetStreamCount()
59 internal override bool Start(
IFieldable[] fields,
int count)
62 doVectorPositions =
false;
63 doVectorOffsets =
false;
65 for (
int i = 0; i < count; i++)
78 if (perThread.doc == null)
80 perThread.doc = termsWriter.GetPerDoc();
81 perThread.doc.docID = docState.docID;
82 System.Diagnostics.Debug.Assert(perThread.doc.numVectorFields == 0);
83 System.Diagnostics.Debug.Assert(0 == perThread.doc.perDocTvf.Length);
84 System.Diagnostics.Debug.Assert(0 == perThread.doc.perDocTvf.FilePointer);
87 System.Diagnostics.Debug.Assert(perThread.doc.docID == docState.docID);
88 if (termsHashPerField.numPostings != 0)
93 termsHashPerField.Reset();
94 perThread.termsHashPerThread.Reset(
false);
113 internal override void Finish()
116 System.Diagnostics.Debug.Assert(docState.TestPoint(
"TermVectorsTermsWriterPerField.finish start"));
118 int numPostings = termsHashPerField.numPostings;
120 System.Diagnostics.Debug.Assert(numPostings >= 0);
122 if (!doVectors || numPostings == 0)
125 if (numPostings > maxNumPostings)
126 maxNumPostings = numPostings;
134 System.Diagnostics.Debug.Assert(fieldInfo.storeTermVector);
135 System.Diagnostics.Debug.Assert(perThread.VectorFieldsInOrder(fieldInfo));
137 perThread.doc.AddField(termsHashPerField.fieldInfo.number);
141 tvf.WriteVInt(numPostings);
142 byte bits = (byte) (0x0);
143 if (doVectorPositions)
150 int lastTermBytesCount = 0;
153 char[][] charBuffers = perThread.termsHashPerThread.charPool.buffers;
154 for (
int j = 0; j < numPostings; j++)
157 int freq = posting.freq;
159 char[] text2 = charBuffers[posting.textStart >>
DocumentsWriter.CHAR_BLOCK_SHIFT];
164 UnicodeUtil.UTF8Result utf8Result = perThread.utf8Results[encoderUpto];
167 UnicodeUtil.UTF16toUTF8(text2, start2, utf8Result);
168 int termBytesCount = utf8Result.length;
176 byte[] lastTermBytes = perThread.utf8Results[1 - encoderUpto].result;
177 byte[] termBytes = perThread.utf8Results[encoderUpto].result;
178 while (prefix < lastTermBytesCount && prefix < termBytesCount)
180 if (lastTermBytes[prefix] != termBytes[prefix])
185 encoderUpto = 1 - encoderUpto;
186 lastTermBytesCount = termBytesCount;
188 int suffix = termBytesCount - prefix;
189 tvf.WriteVInt(prefix);
190 tvf.WriteVInt(suffix);
191 tvf.WriteBytes(utf8Result.result, prefix, suffix);
194 if (doVectorPositions)
196 termsHashPerField.InitReader(reader, posting, 0);
202 termsHashPerField.InitReader(reader, posting, 1);
207 termsHashPerField.Reset();
214 perThread.termsHashPerThread.Reset(
false);
217 internal void ShrinkHash()
219 termsHashPerField.ShrinkHash(maxNumPostings);
227 offsetAttribute = fieldState.attributeSource.AddAttribute<
IOffsetAttribute>();
231 offsetAttribute = null;
235 internal override void NewTerm(RawPostingList p0)
238 System.Diagnostics.Debug.Assert(docState.TestPoint(
"TermVectorsTermsWriterPerField.newTerm start"));
240 TermVectorsTermsWriter.PostingList p = (TermVectorsTermsWriter.PostingList) p0;
246 int startOffset = fieldState.offset + offsetAttribute.
StartOffset; ;
247 int endOffset = fieldState.offset + offsetAttribute.EndOffset;
249 termsHashPerField.WriteVInt(1, startOffset);
250 termsHashPerField.WriteVInt(1, endOffset - startOffset);
251 p.lastOffset = endOffset;
254 if (doVectorPositions)
256 termsHashPerField.WriteVInt(0, fieldState.position);
257 p.lastPosition = fieldState.position;
261 internal override void AddTerm(RawPostingList p0)
264 System.Diagnostics.Debug.Assert(docState.TestPoint(
"TermVectorsTermsWriterPerField.addTerm start"));
266 TermVectorsTermsWriter.PostingList p = (TermVectorsTermsWriter.PostingList) p0;
271 int startOffset = fieldState.offset + offsetAttribute.StartOffset; ;
272 int endOffset = fieldState.offset + offsetAttribute.EndOffset;
274 termsHashPerField.WriteVInt(1, startOffset - p.lastOffset);
275 termsHashPerField.WriteVInt(1, endOffset - startOffset);
276 p.lastOffset = endOffset;
279 if (doVectorPositions)
281 termsHashPerField.WriteVInt(0, fieldState.position - p.lastPosition);
282 p.lastPosition = fieldState.position;
286 internal override void SkippingLongTerm()