result.setTotalHits(docs.totalHits);
ScoreDoc[] scoreDocs = docs.scoreDocs;
ArrayList<SearchHit> hitList = new ArrayList<SearchHit>(scoreDocs.length);
for (ScoreDoc scoreDoc : scoreDocs) {
SearchHit hit = new SearchHit();
hit.setScore(scoreDoc.score);
int docid = scoreDoc.doc;
Document doc = multiReader.document(docid);
String content = doc.get("content");
Scorer qs = new QueryScorer(q);
SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"hl\">", "</span>");
Highlighter hl = new Highlighter(formatter, qs);
String[] fragments = hl.getBestFragments(analyzer, "content", content, 1);
Map<String, String[]> fields = convert(doc);
fields.put("fragment", fragments);
hit.setFields(fields);
hitList.add(hit);
}
result.setHits(hitList.toArray(new SearchHit[hitList.size()]));
return result;