23 using System.Collections.Generic;
26 using Lucene.Net.Analysis;
27 using Lucene.Net.Analysis.Tokenattributes;
28 using Lucene.Net.Documents;
29 using Lucene.Net.Index;
31 namespace Lucene.Net.Search.Highlight
42 protected internal Token[] tokens;
43 protected internal int currentToken = 0;
50 termAtt = AddAttribute<ITermAttribute>();
51 offsetAtt = AddAttribute<IOffsetAttribute>();
54 public override bool IncrementToken()
56 if (currentToken >= tokens.Length)
61 Token token = tokens[currentToken++];
67 protected override void Dispose(
bool disposing)
94 if (termPositionVector != null)
96 ts = GetTokenStream(termPositionVector);
100 return ts ?? GetTokenStream(doc, field, analyzer);
117 if (termPositionVector != null)
119 ts = GetTokenStream(termPositionVector);
123 return ts ?? GetTokenStream(reader, docId, field, analyzer);
129 return GetTokenStream(tpv,
false);
163 int totalTokens = freq.Sum();
165 var tokensInOriginalOrder =
new Token[totalTokens];
166 List<Token> unsortedTokens = null;
167 for (
int t = 0; t < freq.Length; t++)
176 if (tokenPositionsGuaranteedContiguous)
184 if (unsortedTokens == null)
186 unsortedTokens =
new List<Token>();
192 token.SetTermBuffer(terms[t]);
193 unsortedTokens.Add(token);
204 for (
int tp = 0; tp < pos.Length; tp++)
206 var token =
new Token(terms[t], offsets[tp].StartOffset, offsets[tp].EndOffset);
207 tokensInOriginalOrder[pos[tp]] = token;
212 if (unsortedTokens != null)
214 tokensInOriginalOrder = unsortedTokens.ToArray();
215 Array.Sort(tokensInOriginalOrder, (t1, t2) =>
217 if (t1.StartOffset > t2.EndOffset)
219 if (t1.StartOffset < t2.StartOffset)
232 throw new ArgumentException(field +
" in doc #" + docId
233 +
"does not have any term position data stored");
238 return GetTokenStream(tpv);
240 throw new ArgumentException(field +
" in doc #" + docId
241 +
"does not have any term position data stored");
248 return GetTokenStream(doc, field, analyzer);
253 String contents = doc.
Get(field);
254 if (contents == null)
256 throw new ArgumentException(
"Field " + field +
" in document is not stored and cannot be analyzed");
258 return GetTokenStream(field, contents, analyzer);
264 return analyzer.
TokenStream(field,
new StringReader(contents));