Closed GoogleCodeExporter closed 8 years ago
IKAnalyzer analyzer = new IKAnalyzer(true); QueryParser parser = new QueryParser(Version.LUCENE_29, "title", new IKAnalyzer()); Directory fsDir = FSDirectory.open(new File("D:/java/server/apache-tomcat-6.0.18/bin/solr/data/index")); IndexReader reader = null; try { reader = IndexReader.open(fsDir, true); Query query = parser.parse("title:【搜索引擎】Google购物搜索"); IndexSearcher searcher = new IndexSearcher(reader); TopDocs hits = searcher.search(query, null, 10000); Document doc = null; ScoreDoc[] scoreDocs = hits.scoreDocs; int length = scoreDocs.length; for (int i = 0; i < length; i++) { doc = searcher.doc(scoreDocs[i].doc); //有值 String value = doc.get("title"); //System.out.println(doc.get("id")); //System.out.println(doc.getBoost()); SimpleHTMLFormatter sHtmlF = new SimpleHTMLFormatter( "<b>", "</b>"); Highlighter highlighter = new Highlighter(sHtmlF, new QueryScorer( query)); highlighter.setTextFragmenter(new SimpleFragmenter(100000)); if (value != null) { TokenStream tokenStream = analyzer.tokenStream("title", new StringReader(value)); String str = highlighter.getBestFragment(tokenStream, value); //值为null System.out.println(str); } } searcher.close();
Original issue reported on code.google.com by panxiuya...@gmail.com on 28 Jun 2010 at 3:17
panxiuya...@gmail.com
这个应该是高亮api算法的问题了。
Original comment by linliang...@gmail.com on 8 Jul 2010 at 7:19
linliang...@gmail.com
Original issue reported on code.google.com by
panxiuya...@gmail.com
on 28 Jun 2010 at 3:17