一、文档中的代码修改下Filter:
Directory dir=FSDirectory.open(new File("E:\\lucene\\test_lucene\\index")); IndexReader r=DirectoryReader.open(dir); //IndexSearcher search=new IndexSearcher(r); IndexSearcher searcher = new IndexSearcher(r); Analyzer analyzer=new SmartChineseAnalyzer(Version.LUCENE_42); QueryParser parser = new QueryParser(Version.LUCENE_42, "countent", analyzer); Query query = parser.parse("红纸包绿纸包"); TopDocs hits = searcher.search(query, 10); SimpleHTMLFormatter htmlFormatter = new SimpleHTMLFormatter("<font color=\"red\">", "</font>"); Highlighter highlighter = new Highlighter(htmlFormatter, new QueryScorer(query)); for (int i = 0; i < hits.scoreDocs.length; i++) { int id = hits.scoreDocs[i].doc; Document doc = searcher.doc(id); String text = doc.get("countent"); TokenStream tokenStream = TokenSources.getAnyTokenStream(searcher.getIndexReader(), id, "countent", analyzer); TextFragment[] frag = highlighter.getBestTextFragments(tokenStream, text, false, 10);//highlighter.getBestFragments(tokenStream, text, 3, "..."); for (int j = 0; j < frag.length; j++) { if ((frag[j] != null) && (frag[j].getScore() > 0)) { System.out.println((frag[j].toString())); } } //Term vector text = doc.get("Path"); tokenStream = TokenSources.getAnyTokenStream(searcher.getIndexReader(), hits.scoreDocs[i].doc, "Path", analyzer); frag = highlighter.getBestTextFragments(tokenStream, text, false, 10); for (int j = 0; j < frag.length; j++) { if ((frag[j] != null) && (frag[j].getScore() > 0)) { System.out.println((frag[j].toString())); } } System.out.println("-------------"); } }
二、效果如下
相关推荐
lucene3.5高亮
lucene高亮显示
lucene 高亮显示. java 已测试
基于SpringBoot编写的一个Lucene测试Demo把匹配到的结果高亮摘要显示在前端jsp上
Lucene.Net.dll Highlighter.Net.dll
这个是自己写的lucene分页高亮程序虽然有些不足但是毕竟是自己研究半天总结出来的麻烦各位帮忙给点分哈哈祝大家新年快乐!
lucene-highlighter-3.5.0.jar lucene高亮包
lucene.NET 中文分词 高亮 lucene.NET 中文分词 高亮 lucene.NET 中文分词 高亮 lucene.NET 中文分词 高亮
NULL 博文链接:https://sunlongan666.iteye.com/blog/580380
lucene全文检索4.6.0基础jar包、lucene全文检索4.6.0基础jar包lucene全文检索4.6.0基础jar包
java实现lucene高亮显示Html,直接测试就可以用;java实现的对html进行高亮显示,
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part3 SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part2 SSH + Lucene + 分页 + 排序 + 高亮 ...
NULL 博文链接:https://navylee.iteye.com/blog/740128
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part3 SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part2 SSH + Lucene + 分页 + 排序 + 高亮 ...
lucene jar 2.4.0使用jar包加高亮包.外加commons-logging-1.0.4包
使用lucene技术,实现android的本地文档资源的全文检索功能,并实现关键字高亮
该项目中包括创建索引,增删改查索引,以及关键字高亮显示实例~~对于初学者很有帮助,该项目是基于Lucene3.0
此资源配合《android+lucene实现全文检索并高亮关键字》使用http://download.csdn.net/detail/reality_jie/6335113
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part3 SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part2 SSH + Lucene + 分页 + 排序 + 高亮 ...
利用IKAnalyzer结合LUCENE.4.9进行中文分词的高亮显示。