1

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?

devang
  • 5,376
  • 7
  • 34
  • 49

1 Answers1

2

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.

potame
  • 7,597
  • 4
  • 26
  • 33
Christopher Currens
  • 29,917
  • 5
  • 57
  • 77
  • Can you or @gotuskar add a sample code snippet on how to use the Highlighter please.. – Anand Rockzz Nov 06 '12 at 03:41
  • 1
    @Anand I don't have that piece of code now. Take a look at these examples http://stackoverflow.com/questions/2409870/using-hit-highlighter-in-lucene, http://hrycan.com/2009/10/25/lucene-highlighter-howto/ – devang Nov 06 '12 at 03:46
  • Thanks for pointing to that example, [HERE](http://db.tt/RdW3EhXT) is a simple working copy/demo/helloworld app. – Anand Rockzz Nov 06 '12 at 06:10