devang
devang

Reputation: 5516

Custom highlighter with lucene

By default the lucene highlighter highlights the search string using bold tags. Can I provide my own highlighting scheme, using some other color for highlighting?

Upvotes: 1

Views: 1011

Answers (1)

Christopher Currens
Christopher Currens

Reputation: 30715

If you're using just the regular Highlighter, you can pass it the SimpleHTMLFormatter constructed with whatever pre and post tags you want:

new Highlighter(fragmentScorer, new SimpleHTMLFormatter("<span>", "</span>"));

Of course, there are other formatters, like the GradientFormatter, that will highlight the term with based on a minimum and maximum color determined by score, all which you can set via the constructor. The SpanGradientFormatter does something similar, as well.

Upvotes: 2

Related Questions