lucene search multiply method

public void searchContent(String type,String keyword){    // 根据指定的检索内容类型type,以及检索关键字keyword进行检索操作
   try {
    IndexSearcher searcher = new IndexSearcher(this.indexPath);    // 根据指定路径,构造一个IndexSearcher检索器
    Term term = new Term(type,keyword);    // 创建词条
    Query query = new TermQuery(term);    //   创建查询
    Date startTime = new Date();
    TermDocs termDocs = searcher.getIndexReader().termDocs(term);    // 执行检索操作
    while(termDocs.next()){    //   遍历输出根据指定词条检索的结果信息
     System.out.println("搜索的该关键字【"+keyword+"】在文件\n"+searcher.getIndexReader().document(termDocs.doc()));
     System.out.println("中,出现过 "+termDocs.freq()+" 次");
    }
    Date finishTime = new Date();
    long timeOfSearch = finishTime.getTime() - startTime.getTime();    //   计算检索花费时间
    System.out.println("本次搜索所用的时间为 "+timeOfSearch+" ms");
   } catch (CorruptIndexException e) {
    e.printStackTrace();
   } catch (IOException e) {
    e.printStackTrace();
   }
}

你可能感兴趣的:(Lucene)