摘要: (轉(zhuǎn))http://www.wujianrong.com/archives/2007/03/lucene_7.html
1.寫(xiě)一段傳統(tǒng)的JDBC程序,講每條的用戶信息從數(shù)據(jù)庫(kù)讀取出來(lái)
2.針對(duì)每條用戶記錄,建立一個(gè)lucene document
Document doc = new Document();
并根據(jù)你的需要,將用戶信息的各個(gè)字段對(duì)應(yīng)luncene document中的field 進(jìn)行添加,如:
doc.add(new Field("NAME","USERNAME",Field.Store.YES,Field.Index.UN_TOKENIZED));
然后將該條doc加入到索引中, 如: luceneWriter.addDocument(doc);
這樣就建立了lucene的索引庫(kù)
3.編寫(xiě)對(duì)索引庫(kù)的搜索程序(看lucene文檔),通過(guò)對(duì)lucene的索引庫(kù)的查找,你可以快速找到對(duì)應(yīng)記錄的ID
4.通過(guò)ID到數(shù)據(jù)庫(kù)中查找相關(guān)記錄
閱讀全文