我使用以下代码行从Lucene.NET 4.8中的TokenStream中提取分析的术语,但是会出现运行时错误。
var analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48);
TokenStream tokenStream = analyzer.TokenStream(null, new StringReader("myterm"));
tokenStream.Reset();
while (tokenStream.IncrementToken())
{
var termAttr = tokenStream.GetAttribute<ITermAttribute>();
var analyzedTerm = termAttr.Term;
}
tokenStream.End();
tokenStream.Dispose();
抛出异常: Lucene.Net.dll中出现未处理的“System.ArgumentException”类型异常和附加信息:此AttributeSource没有属性“ITermAttribute”
我在其他版本的Lucene.NET中使用了相同的方法,效果很好。
Lucene.NET 3.0.3
var analyser = new StandardAnalyzer(Version.LUCENE_30);
var tokenStream = analyzer.TokenStream(null, new StringReader("myterm"));
tokenStream.Reset();
while (tokenStream.IncrementToken())
{
var termAttr = tokenStream.GetAttribute<ITermAttribute>();
var analyzedTerm = termAttr.Term;
}
tokenStream.End();
tokenStream.Dispose();
Lucene.NET 2.9.4.1
var analyser = new StandardAnalyzer(Version.LUCENE_29);
var tokenStream = analyser.TokenStream(null, new StringReader("myterm"));
tokenStream.Reset();
while (tokenStream.IncrementToken())
{
var termAttr = tokenStream.GetAttribute(typeof(TermAttribute));
var analyzedTerm = termAttr.ToString();
}
tokenStream.End();
tokenStream.Close();
在Lucene.NET 4.8中做过这个的人吗?