Lucene学习笔记(一)
这里主要介绍一下如何快速的学习开发自己的第一个Lucene程序。
Lucene的开发主要分为两个步骤:
????? 1、对需要检索的数据创建索引
????? 2、根据关键字在索引查询到你需要的内容
?
首先我们来看一下如何利用Lucene创建索引:
?
?
下面是利用Lucene创建的索引库查询
public void search() throws Exception {// 待查询的关键字String queryString = "adddocument";// 构建一个查询解析器QueryParser queryParser = new MultiFieldQueryParser(new String[]{"name","content"}, new StandardAnalyzer());// 利用查询解析器构建查询对象Query query = queryParser.parse(queryString);// 构建索引查询对象IndexSearcher indexSearcher = new IndexSearcher(indexPath);Filter filter = null;// 查询出匹配的文档TopDocs topDocs = indexSearcher.search(query, filter, 10000);System.out.println("共搜索到【"+topDocs.totalHits+"】条匹配记录");// 展示查询结果for (ScoreDoc scoreDoc : topDocs.scoreDocs) {int docSn = scoreDoc.doc;Document doc = indexSearcher.doc(docSn);File2DocumentUtils.printDocumentInfo(doc);}}?