diff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.java index c2572b8098b..cb4b10e540a 100644 --- a/src/java/org/apache/lucene/index/IndexWriter.java +++ b/src/java/org/apache/lucene/index/IndexWriter.java @@ -46,28 +46,24 @@ import java.util.Map; /** An IndexWriter creates and maintains an index. -

The create argument to the - constructor - determines whether a new index is created, or whether an existing index is - opened. 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. There are - also constructors - with no create argument which - will create a new index if there is not already an index at the - provided path and otherwise open the existing index.

+

The create argument to the {@link + #IndexWriter(Directory, Analyzer, boolean) constructor} determines + whether a new index is created, or whether an existing index is + opened. 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. There are + also {@link #IndexWriter(Directory, Analyzer) constructors} + with no create argument which will create a new index + if there is not already an index at the provided path and otherwise + open the existing index.

-

In either case, documents are added with addDocument - and removed with deleteDocuments(Term) - or deleteDocuments(Query). - A document can be updated with updateDocument - (which just deletes and then adds the entire document). - When finished adding, deleting and updating documents, close should be called.

+

In either case, documents are added with {@link #addDocument(Document) + addDocument} and removed with {@link #deleteDocuments(Term)} or {@link + #deleteDocuments(Query)}. A document can be updated with {@link + #updateDocument(Term, Document) updateDocument} (which just deletes + and then adds the entire document). When finished adding, deleting + and updating documents, {@link #close() close} should be called.

These changes are buffered in memory and periodically @@ -90,23 +86,20 @@ import java.util.Map; for changing the {@link MergeScheduler}).

-

The optional autoCommit argument to the constructors +

The optional autoCommit argument to the {@link + #IndexWriter(Directory, boolean, Analyzer) constructors} controls visibility of the changes to {@link IndexReader} instances reading the same index. When this is false, changes are not visible until {@link #close()} or {@link #commit()} is called. Note that changes will still be - flushed to the {@link org.apache.lucene.store.Directory} - as new files, but are not committed (no new - segments_N file is written referencing the - new files, nor are the files sync'd to stable storage) + flushed to the {@link Directory} as new files, but are + not committed (no new segments_N file is written + referencing the new files, nor are the files sync'd to stable storage) until {@link #close()} or {@link #commit()} is called. If something goes terribly wrong (for example the JVM crashes), then the index will reflect none of the changes made since the last commit, or the starting state if commit was not called. - You can also call {@link #rollback}, which closes the writer + You can also call {@link #rollback()}, which closes the writer without committing any changes, and removes any index files that had been flushed but are now unreferenced. This mode is useful for preventing readers from refreshing @@ -142,7 +135,7 @@ import java.util.Map; are not visible until the reader is re-opened.

If an index will not have more documents added for a while and optimal search - performance is desired, then either the full optimize + performance is desired, then either the full {@link #optimize() optimize} method or partial {@link #optimize(int)} method should be called before the index is closed.

diff --git a/src/java/org/apache/lucene/index/LogMergePolicy.java b/src/java/org/apache/lucene/index/LogMergePolicy.java index d9de85ebcee..5bbb3665cf8 100644 --- a/src/java/org/apache/lucene/index/LogMergePolicy.java +++ b/src/java/org/apache/lucene/index/LogMergePolicy.java @@ -22,9 +22,12 @@ import java.util.Set; /**

This class implements a {@link MergePolicy} that tries * to merge segments into levels of exponentially - * increasing size, where each level has < mergeFactor - * segments in it. Whenever a given levle has mergeFactor - * segments or more in it, they will be merged.

+ * increasing size, where each level has fewer segments than + * the value of the merge factor. Whenever extra segments + * (beyond the merge factor upper bound) are encountered, + * all segments within the level are merged. You can get or + * set the merge factor using {@link #getMergeFactor()} and + * {@link #setMergeFactor(int)} respectively.

* *

This class is abstract and requires a subclass to * define the {@link #size} method which specifies how a diff --git a/src/java/org/apache/lucene/index/MergePolicy.java b/src/java/org/apache/lucene/index/MergePolicy.java index 7e75c5f960f..871c4efb23f 100644 --- a/src/java/org/apache/lucene/index/MergePolicy.java +++ b/src/java/org/apache/lucene/index/MergePolicy.java @@ -55,7 +55,7 @@ import java.util.Set; * (subject to change suddenly in the next release)

* *

NOTE: This class typically requires access to - * package-private APIs (eg, SegmentInfos) to do its job; + * package-private APIs (e.g. {@link SegmentInfo}s) to do its job; * if you implement your own MergePolicy, you'll need to put * it in package org.apache.lucene.index in order to use * these APIs. diff --git a/src/java/org/apache/lucene/store/IndexOutput.java b/src/java/org/apache/lucene/store/IndexOutput.java index 977881f0cef..b47c16a9165 100644 --- a/src/java/org/apache/lucene/store/IndexOutput.java +++ b/src/java/org/apache/lucene/store/IndexOutput.java @@ -162,6 +162,7 @@ public abstract class IndexOutput { /** Copy numBytes bytes from input to ourself. */ public void copyBytes(IndexInput input, long numBytes) throws IOException { + assert numBytes >= 0: "numBytes=" + numBytes; long left = numBytes; if (copyBuffer == null) copyBuffer = new byte[COPY_BUFFER_SIZE];