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

时间:2023-02-06 03:04:08

I am using the Lucene.NET API directly in my ASP.NET/C# web application. 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. Does Lucene have the ability to highlight using the same logic it used to match with?

我在ASP.NET / C#Web应用程序中直接使用Lucene.NET API。当我使用通配符搜索时,例如“fuc *”,荧光笔不会突出显示任何内容,但是当我搜索整个单词时,如“fuchsia”,它会突出显示。 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。

1 个解决方案

#1


4  

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,

希望这可以帮助,

#1


4  

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,

希望这可以帮助,