在TokenStream Lucene.Net中获取TermAttribute

时间:2013-04-29 08:59:46

标签: .net lucene.net

我使用Lucene.NET3.0.3 如何获得TermAttribute.I尽我所能,但我无法得到它

这里来源:

    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

    }

2 个答案:

答案 0 :(得分:9)

var termAttr = tokenStream.GetAttribute<Lucene.Net.Analysis.Tokenattributes.ITermAttribute>();

while(tokenStream.IncrementToken())
{
    string term = termAttr.Term;
}

答案 1 :(得分:0)

Apache Lucene.Net 4.8中,您可以使用以下C#代码:(。NET Core 2 +),其中<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/js/bootstrap.min.js"></script> <div class="container"> <div class="row py-2"> <div class="col-sm-12"> <input type="search" id="myInput" placeholder="Start typing.." name="search" class="form-control searchbox-input" required=""> </div> </div> <div class="row"> <div class="col-sm-12"> <div class="row no-gutters bg-info"> <div class="col-sm-12 col-lg-4 p-3"> <h2>Day 1</h2> </div> <div class="col-sm-12 col-lg-8 p-3"> <h2>April 7, 2019</h2> </div> </div> <div class="card"> <div class="card-body"> <h4 class="card-title">Batman</h4> <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> </div> </div> <div class="card card-body"> <h4 class="card-title">Superman</h4> <blockquote class="card-blockquote"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p> <footer> <small class="text-muted"> Someone famous in <cite title="Source Title">Source Title</cite> </small> </footer> </blockquote> </div> </div> </div> <div class="row"> <div class="col-lg-12"> <div class="row no-gutters bg-warning"> <div class="col-sm-12 col-lg-4 p-3"> <h2>Day 2</h2> </div> <div class="col-sm-12 col-lg-8 p-3"> <h2>April 8, 2019</h2> </div> </div> <div class="card"> <div class="card-body"> <h4 class="card-title">Daredevil</h4> <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small> </p> </div> </div> <div class="card card-body card-inverse card-primary text-xs-center"> <blockquote class="card-blockquote"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat.</p> <footer> <small> Someone famous in <cite title="Source Title">Source Title</cite> </small> </footer> </blockquote> </div> <div class="card card-body text-xs-center"> <h4 class="card-title">Hulk</h4> <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small> </p> </div> <div class="card card-body text-xs-right"> <blockquote class="card-blockquote"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p> <footer> <small class="text-muted"> Someone famous in <cite title="Source Title">Source Title</cite> </small> </footer> </blockquote> </div> <div class="card card-body"> <h4 class="card-title">Thor</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small> </p> </div> </div> </div> </div>包含 Token 作为{{1} }。完整的方法:term = termAttr.ToString(),您可以在 GitHub msigut/LuceneNet48Demo上获得。

string