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

Posted by Scott Stafford on Stack Overflow See other posts from Stack Overflow or by Scott Stafford
Published on 2010-05-14T21:07:31Z Indexed on 2010/05/14 21:54 UTC
Read the original article Hit count: 1378

Filed under:
|
|
|

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?

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.

© Stack Overflow or respective owner

Related posts about lucene

Related posts about lucene.net