I use Lucene.NET3.0.3 how to get TermAttribute.I try my best but i can't get it
here source:
Analyzer analyzer = new Lucene.Net.Analysis.Snowball.SnowballAnalyzer(Lucene.Net.Util.Version.LUCENE_30, "English",stopword);
TokenStream tokenStream = analyzer.TokenStream("English", new StringReader("How to get TermAttribute"));
while (tokenStream.IncrementToken())
{
???How to get TermAttribute
}
var termAttr = tokenStream.GetAttribute<Lucene.Net.Analysis.Tokenattributes.ITermAttribute>();
while(tokenStream.IncrementToken())
{
string term = termAttr.Term;
}
In Apache Lucene.Net 4.8 you can use this C# code: (.NET Core 2+) where term = termAttr.ToString()
contains Token as string
. Complete method: PrintTokens(Analyzer analyzer, string fieldName, string text)
you can get at GitHub msigut/LuceneNet48Demo.
var tokenStream = analyzer.GetTokenStream(fieldName, textToAnalyze);
var termAttr = tokenStream.GetAttribute<ICharTermAttribute>();
tokenStream.Reset();
while (tokenStream.IncrementToken())
{
string term = termAttr.ToString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With