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");
}
}
lucene3.5检索实例
最新推荐文章于 2025-08-06 18:22:29 发布