本文整理汇总了C#中ITokenSource.SetReader方法的典型用法代码示例。如果您正苦于以下问题:C# ITokenSource.SetReader方法的具体用法?C# ITokenSource.SetReader怎么用?C# ITokenSource.SetReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITokenSource
的用法示例。
在下文中一共展示了ITokenSource.SetReader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddField
public void AddField(string field, TextReader indexedValue = null, string storedValue = null, FieldOptions options = FieldOptions.None)
{
if (storedValue != null)
{
var num = _parent.GetFieldNumber(field);
_binaryWriter.Write(num);
_binaryWriter.Write(storedValue);
_currentStoredCount++;
}
if (indexedValue == null)
{
if (storedValue == null)
throw new ArgumentException("It isn't meaningful to pass null for both indexedValue and storedValue");
return;
}
_source = _analyzer.CreateTokenSource(field, _source);
_source.SetReader(indexedValue);
while (_source.Next())
{
if (options.HasFlag(FieldOptions.NoAnalyzer) == false)
{
if (_analyzer.Process(field, _source) == false)
continue;
}
var byteCount = Encoding.UTF8.GetByteCount(_source.Buffer, 0, _source.Size);
var bytes = _bufferPool.Take(byteCount);
Encoding.UTF8.GetBytes(_source.Buffer, 0, _source.Size, bytes, 0);
Debug.Assert(byteCount < ushort.MaxValue);
_currentTermCount++;
var key = Tuple.Create(field, new ArraySegmentKey<byte>(bytes, byteCount));
TermInfo info;
if (_currentTerms.TryGetValue(key, out info))
{
_bufferPool.Return(bytes);
}
else
{
_currentTerms[key] = info = new TermInfo {Boost = 1.0f};
_usedBuffers.Add(bytes);
}
info.Freq++;
if (options.HasFlag(FieldOptions.TermPositions))
{
if (info.Positions == null)
info.Positions = new List<int>();
info.Positions.Add(_source.Position);
}
}
}