public static String getHighLight(Document doc, Analyzer analyzer, Query query, String field) throws Exception
{
SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<b>", "</b>");
/* 语法高亮显示设置 */
Highlighter highlighter = new Highlighter(simpleHTMLFormatter, new QueryScorer(query));
highlighter.setTextFragmenter(new SimpleFragmenter(100));
// 取 field 字段值,准备进行高亮
String fieldValue = doc.get(field);
TokenStream tokenStream = analyzer.tokenStream(field, new StringReader(fieldValue));
// 转成高亮的值
String highLightFieldValue = highlighter.getBestFragment(tokenStream, fieldValue);
if (highLightFieldValue == null)
highLightFieldValue = fieldValue;
return highLightFieldValue;
}