use of org.apache.lucene.search.highlight.Scorer in project jforum2 by rafaelsteil.
the class LuceneContentCollector method retrieveRealPosts.
private List retrieveRealPosts(int[] postIds, Query query) throws IOException {
List posts = DataAccessDriver.getInstance().newLuceneDAO().getPostsData(postIds);
for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
Post post = (Post) iter.next();
Scorer scorer = new QueryScorer(query);
Highlighter highlighter = new Highlighter(scorer);
TokenStream tokenStream = this.settings.analyzer().tokenStream(SearchFields.Indexed.CONTENTS, new StringReader(post.getText()));
String fragment = highlighter.getBestFragment(tokenStream, post.getText());
post.setText(fragment != null ? fragment : post.getText());
}
return posts;
}
Aggregations