The third argument (create
) to the constructor determines whether a new index is created, or whether an existing index is opened for the addition of new documents. Note that you can open an index with create=true even while readers are using the index. The old readers will continue to search the "point in time" snapshot they had opened, and won't see the newly created index until they re-open.
In either case, documents are added with the addDocument method. When finished adding documents, close should be called.
If an index will not have more documents added for a while and optimal search performance is desired, then the optimize method should be called before the index is closed.
Opening an IndexWriter creates a lock file for the directory in use. Trying to open another IndexWriter on the same directory will lead to an IOException. The IOException is also thrown if an IndexReader on the same directory is used to delete documents from the index.
As of 2.1, IndexWriter can now delete documents by {@link Term} (see {@link #deleteDocuments} ) and update(delete then add) documents (see {@link #updateDocument}). Deletes are buffered until {@link #setMaxBufferedDeleteTerms} Terms
at whichpoint they are flushed to the index. Note that a flush occurs when there are enough buffered deletes or enough added documents, whichever is sooner. When a flush occurs, both pending deletes and added documents are flushed to the index.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|