IndexWriter writer = getWriter();
Document doc = new Document();
doc.add(new Field("id", "1",
Field.Store.YES,
Field.Index.NOT_ANALYZED));
doc.add(new Field("country", "Netherlands",
Field.Store.YES,
Field.Index.NO));
doc.add(new Field("contents",
"Den Haag has a lot of museums",
Field.Store.NO,
Field.Index.ANALYZED));
doc.add(new Field("city", "Den Haag",
Field.Store.YES,
Field.Index.ANALYZED));
writer.close();
上篇文章說了一下創建索引的過程。現在介紹一下 lucene 創建索引的api吧
Document A document is Lucene’s atomic unit of indexing and searching. It’s a container that
holds one or more fields (lucene in action)有這麼一句話。可見document的重要性
Field document 中包含的信息
IndexWriter io操作,負責把信息 寫入指定的地點
這幾個對象 很像jdk io 中的
OutStream ===> IndexWriter// 操作者
File ====>document //容器
byte[] =====>filed //內容