专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »编程综合 » lucene:全文检索lucene学习笔记( 3) »正文

lucene:全文检索lucene学习笔记( 3)

来源: 发布时间:星期四, 2009年1月15日 浏览:14次 评论:0
  使用Explanation类取得评分信息

  view plaincopy to clipboardpr?

packagecom.lucene;  
importjava.io.IOException;  
importorg.apache.lucene.analysis.standard.StandardAnalyzer;  
importorg.apache.lucene.document.Document;  
importorg.apache.lucene.queryParser.ParseException;  
importorg.apache.lucene.queryParser.QueryParser;  
importorg.apache.lucene.search.Explanation;  
importorg.apache.lucene.search.Hits;  
importorg.apache.lucene.search.IndexSearcher;  
importorg.apache.lucene.search.Query;  
importorg.apache.lucene.store.FSDirectory;  
publicExplainer{  
  publicvoid(Stringargs)throwsIOException,ParseException{  
      
    StringindexDir="C:  estindex";  
    StringqueryExp="ERROR";  
      
    FSDirectorydirectory=FSDirectory.getDirectory(indexDir);  
    QueryParserparser=QueryParser("contents",StandardAnalyzer);  
    Queryquery=parser.parse(queryExp);  
      
    .out.prln("Query:"+queryExp);  
      
    IndexSearchersearcher=IndexSearcher(directory);  
    Hitshits=searcher.search(query);  
      
    for(i=0;i<hits.length;i){  
      Explanationexplanation=searcher.explain(query,hits.id(i));  
      .out.prln("--------------------");  
      Documentdoc=hits.doc(i);  
      .out.prln(doc.get("filename"));  
      .out.prln(explanation.toString);  
    }  
  }  
}


0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: