3

I've made a search component in my application with lucene. everything works fine, Indexing, highlighting ,etc. I need now to return a paragraph as my search response and not just limit the result to "fragmentSize" in SimpleSpanFragmenter method.there 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've set to 256. but its not my ideal. I want to get a paragraph which contains my search word in query.

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
  • I don't think know of anything out of the box, but if you are rolling your own fragmenter then Solr has a RegexFragmenter that would be worth looking at http://stackoverflow.com/q/364301/281469 http://lucene.apache.org/solr/4_1_0/solr-core/org/apache/solr/highlight/RegexFragmenter.html – bcoughlan Dec 16 '14 at 16:13

0 Answers0