首页 > 其他 > 详细

lucene检索实例

时间:2014-04-10 03:30:07      阅读:447      评论:0      收藏:0      [点我收藏+]
public class MySearcher {
	public static final String STORE_PATH = "E:/lucene_index";
	
	public static void searcher(String keyword) throws ParseException,IOException {
		long startTime = System.currentTimeMillis();
		Directory dir = FSDirectory.open(new File(STORE_PATH));
		IndexReader reader = IndexReader.open(dir);
		IndexSearcher search = new IndexSearcher(reader);

		Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_35);
		QueryParser parse = new QueryParser(Version.LUCENE_35, "content", analyzer);
		Query query = parse.parse(keyword);
		System.out.println("解析后的语法:"+query.toString());
		TopDocs it = search.search(query, 100);
		System.out.println("search : " + query.toString());
		ScoreDoc[] docs = it.scoreDocs;
		for (int i = 0; i < docs.length; i++) {
			System.out.println(i + "\t" + search.doc(docs[i].doc).get("title")+"\t"+docs.toString());
		}
		long endTime = System.currentTimeMillis();
		System.out.println("total time: " + (endTime - startTime) + " ms");
	}
	public static void main(String[] args) throws IOException, ParseException {
		searcher("lucene");
	}

}

lucene检索实例,布布扣,bubuko.com

lucene检索实例

原文:http://blog.csdn.net/estelle_belle/article/details/23280373

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!