用Lucene突出显示结果

时间:2017-10-06 14:30:50

标签: lucene hibernate-search

        QueryScorer queryScorer = new QueryScorer(query, "title");
        Fragmenter fragmenter = new SimpleSpanFragmenter(queryScorer);

        Highlighter highlighter = new Highlighter(queryScorer); // Set the best scorer fragments
        highlighter.setTextFragmenter(fragmenter); // Set fragment to highlight            

        SearchFactory searchFactory = fullTextEntityManager.getSearchFactory();
        IndexReader indexReader = searchFactory.getIndexReaderAccessor().open(SearchResult.class);        
        indexSearcher = new IndexSearcher(indexReader);
        // STEP C
        System.out.println("");
        ScoreDoc scoreDocs[] = indexSearcher.search(query, 20).scoreDocs;
        for (ScoreDoc scoreDoc : scoreDocs) {
            Document document = indexSearcher.doc(scoreDoc.doc);
            String title = document.get("title");
            TokenStream tokenStream = analyzer.tokenStream("title", new StringReader(title));
             LOG.info(String.format("TEXTE BRUT: %s", title));
             String fragment = highlighter.getBestFragments(tokenStream, title, 3, "...");
            LOG.log(Level.INFO, "--------- FRAGMENT search : ", fragment);

我有这个错误,我试图获得高亮显示的结果:

无法在Service Module Loader模块“deployment.dev-1.0.war:main”中定义类org.apache.lucene.search.highlight.TermVectorLeafReader:java.lang.VerifyError:

无法链接org / apache / lucene / search / highlight / TermVectorLeafReader(来自Service Module Loader的模块“deployment.scob-1.0.war:main”):class org.apache.lucene.search.highlight.TermVectorLeafReader覆盖final方法术语。(Ljava / lang / String;)Lorg / apache / lucene / index / Terms;

1 个答案:

答案 0 :(得分:0)

当使用与预期版本的Apache Lucene不兼容的VerifyError版本时,您将获得Highlighter

验证您的应用服务器正在使用哪个版本的Lucene,并获得荧光笔的匹配版本。