Lucene in Action阅读笔记(1)--Yin

为了保证项目按时完成,我每天都会抽出一定的时间阅读《Lucene in Action 2nd edtion》,以下为读书笔记,形式可能略显杂乱,但都是我的个人心得,或者原文摘录的经典之处。

1. how to delete a Document or update a existing Document

Delete a Document

ƒ deleteDocuments(Term)  deletes all documents containing the provided term.
ƒ deleteDocuments(Term[])  deletes all documents containing any of the terms in the provided array.
ƒ deleteDocuments(Query)  deletes all documents matching the provided query.
ƒ deleteDocuments(Query[])  deletes all documents matching any of the queries in the provided array.
ƒ deleteAll()  deletes all documents in the index. This is exactly the same as closing the writer and opening a new writer with create=true, without having to close your writer

Usage:

writer.deleteDocuments(new Term("ID", documentID));

Update a Document

writer.updateDocument(new Term("ID", documenteId), newDocument);

Warning:由于updateDocument()内部通过调用deleteDocuments首先删除包含指定Term的文档,因此,需要保证Term的唯一性

posted @ 2012-11-30 00:40  MagicCode1023  阅读(160)  评论(0编辑  收藏  举报