views:

75

answers:

1

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();
}
A: 

Resolved! The problem was in other chunk of code. Actually in "doSomething().

Thank you!

Manrash