日期:2014-05-17 浏览次数:20810 次
public void testSearch() throws IOException, ParseException { // 读取indexer文件 IndexReader reader = IndexReader.open(FSDirectory.open(new File(TestIndexer.indexPath))); IndexSearcher sercher = new IndexSearcher(reader); Long sDate = System.currentTimeMillis(); QueryParser parser = new QueryParser(Version.LUCENE_35,"正文",new IKAnalyzer()); Query query = parser.parse("活动"); TopDocs topDoc = sercher.search(query,5); System.out.println(topDoc.totalHits); ScoreDoc[] hits = topDoc.scoreDocs; for(ScoreDoc sd:hits){ Document doc = sercher.doc(sd.doc); System.out.println("作者 = "+doc.get("作者")); System.out.println("标题 = "+doc.get("标题")); System.out.println("日期 = "+doc.get("日期")); System.out.println("路径 = "+doc.get("路径")); System.out.println("................"); } Long sDate2 = System.currentTimeMillis(); System.out.println("消耗时间:"+(sDate2-sDate)+"毫秒"); sercher.close(); reader.close(); }