Search in sources :

Example 1 with Scorer

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;
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) Post(net.jforum.entities.Post) QueryScorer(org.apache.lucene.search.highlight.QueryScorer) Iterator(java.util.Iterator) StringReader(java.io.StringReader) QueryScorer(org.apache.lucene.search.highlight.QueryScorer) Scorer(org.apache.lucene.search.highlight.Scorer) List(java.util.List) Highlighter(org.apache.lucene.search.highlight.Highlighter)

Aggregations

StringReader (java.io.StringReader)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Post (net.jforum.entities.Post)1 TokenStream (org.apache.lucene.analysis.TokenStream)1 Highlighter (org.apache.lucene.search.highlight.Highlighter)1 QueryScorer (org.apache.lucene.search.highlight.QueryScorer)1 Scorer (org.apache.lucene.search.highlight.Scorer)1