How do I get a paragraph from search in lucene?

I made a search component in my application with lucene. everything works fine, indexing, highlighting, etc. Now I need to return a paragraph as a search response, not just constrain the result to "fragmentation" in the SimpleSpanFragmenter method. This is part of my code:

SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class='highlight'>", "</span>");
QueryScorer scorer = new QueryScorer(query, NodeDocument.TEXT_FIELD);
Highlighter highlighter = new Highlighter(formatter, scorer);
highlighter.setTextFragmenter(new SimpleSpanFragmenter(scorer, MAX_FRAGMENT_LEN));
String excerpt = highlighter.getBestFragment(analyzer, Document.MESSAGE_FIELD, nForumPost.getMessage());

      

This code returns "MAX_FRAGMENT_LEN", which I set to 256. But that's not my ideal. I want to get a paragraph containing my search term in a query.

+3


source to share





All Articles