首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

lucene3.5检索范例

2012-06-28 
lucene3.5检索实例public class MySearcher {public static final String STORE_PATH E:/lucene_index

lucene3.5检索实例

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");}}

热点排行