简体   繁体   English

如何使用通配符正确地突出显示Lucene(.NET)?

[英]How do I get Lucene (.NET) to highlight correctly with wildcards?

I am using the Lucene.NET API directly in my ASP.NET/C# web application. 我在ASP.NET / C#Web应用程序中直接使用Lucene.NET API。 When I search using a wildcard, like "fuc*", the highlighter doesn't highlight anything, but when I search for the whole word, like "fuchsia", it highlights fine. 当我使用通配符搜索时,例如“fuc *”,荧光笔不会突出显示任何内容,但是当我搜索整个单词时,如“fuchsia”,它会突出显示。 Does Lucene have the ability to highlight using the same logic it used to match with? Lucene是否能够使用与之匹配的相同逻辑来突出显示?

Various maybe-relevant code-snippets below: 以下各种可能相关的代码片段:

var formatter = new Lucene.Net.Highlight.SimpleHTMLFormatter(
    "<span class='srhilite'>",
    "</span>");

var fragmenter = new Lucene.Net.Highlight.SimpleFragmenter(100);
var scorer = new Lucene.Net.Highlight.QueryScorer(query);
var highlighter = new Lucene.Net.Highlight.Highlighter(formatter, scorer);
highlighter.SetTextFragmenter(fragmenter);

and then on each hit... 然后在每次击中......

string description = Server.HtmlEncode(doc.Get("Description"));
var stream = analyzer.TokenStream("Description", 
    new System.IO.StringReader(description));
string highlighted_text = highlighter.GetBestFragments(
    stream, description, 1, "...");

And I'm using the QueryParser and the StandardAnalyzer. 我正在使用QueryParser和StandardAnalyzer。

you'll need to ensure you set the parser rewrite method to SCORING_BOOLEAN_QUERY_REWRITE . 您需要确保将解析器重写方法设置为SCORING_BOOLEAN_QUERY_REWRITE

This change seems to have become necessary since Lucene v2.9 came along. 自从Lucene v2.9出现以来,这种变化似乎已经变得必要了。

Hope this helps, 希望这可以帮助,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM