I am trying to highlight search terms in a block of HTML, the problem is if a user does a search for "color", this:
<span style='color: white'>White</span>
becomes: <span style='<b>color</b>: white'><b>White</b></span>
and obviously, messing up my style is not a good idea.
Here is the code I am using:
Query parsedQuery = parser.Parse(luceneQuery);
StandardAnalyzer Analyzer = new StandardAnalyzer();
SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<b class='search'>", "</b>");
QueryScorer scorer = new QueryScorer(parsedQuery);
Highlighter highlighter = new Highlighter(formatter, scorer);
highlighter.SetTextFragmenter(new SimpleFragmenter());
Highlighter.GetBestFragment(Analyzer, propertyName, invocation.ReturnValue.ToString())
I'm guessing the problem is that i need a different Fragmenter, but I'm not sure. Any help would be appreciated.