I'm trying to implement highlighting in my lucene application and I can't get any fragment. getBestFragment always returns null.
My code:
QueryParser parser = new QueryParser(Version.LUCENE_30, "text", myAnalyzer);
Query realQuery = parser.parse(query);
Highlighter highlighter = new Highlighter(new QueryScorer(realQuery, "text"));
for (ScoreDoc scoredoc : luceneTopDocs.scoreDocs ) {
Document doc = null;
doc = searcher.doc(scoredoc.doc);
String bestFragment = highlighter.getBestFragment(myAnalyzer, "text", doc.get("text"));
if (bestFragment != null) doSomething();
}