From 920b5fe236fcf4d302cad47a079e0b2b4683aac1 Mon Sep 17 00:00:00 2001 From: Shai Erera Date: Tue, 20 May 2014 15:50:35 +0000 Subject: [PATCH] LUCENE-5679: remove the single-parameter deleteDocuments() versions, in favor of the vararg ones git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1596296 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 4 + .../org/apache/lucene/index/IndexWriter.java | 94 ++++++------------- 2 files changed, 31 insertions(+), 67 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index c685607a02e..5e24b98edec 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -154,6 +154,10 @@ API Changes * LUCENE-5640: The Token class was deprecated. Since Lucene 2.9, TokenStreams are using Attributes, Token is no longer used. (Uwe Schindler, Robert Muir) +* LUCENE-5679: Consolidated IndexWriter.deleteDocuments(Term) and + IndexWriter.deleteDocuments(Query) with their varargs counterparts. + (Shai Erera) + Optimizations * LUCENE-5603: hunspell stemmer more efficiently strips prefixes diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java index 6cde6692013..22f6f7f453c 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -76,8 +76,8 @@ import org.apache.lucene.util.Version; and otherwise open the existing index.

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

@@ -1216,28 +1216,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{ } } - /** - * Deletes the document(s) containing term. - * - *

NOTE: if this method hits an OutOfMemoryError - * you should immediately close the writer. See above for details.

- * - * @param term the term to identify the documents to be deleted - * @throws CorruptIndexException if the index is corrupt - * @throws IOException if there is a low-level IO error - */ - public void deleteDocuments(Term term) throws IOException { - ensureOpen(); - try { - if (docWriter.deleteTerms(term)) { - processEvents(true, false); - } - } catch (OutOfMemoryError oom) { - handleOOM(oom, "deleteDocuments(Term)"); - } - } - /** Expert: attempts to delete by document ID, as long as * the provided reader is a near-real-time reader (from {@link * DirectoryReader#open(IndexWriter,boolean)}). If the @@ -1250,8 +1228,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{ * NOTE: this method can only delete documents * visible to the currently open NRT reader. If you need * to delete documents indexed after opening the NRT - * reader you must use the other deleteDocument methods - * (e.g., {@link #deleteDocuments(Term)}). */ + * reader you must use {@link #deleteDocuments(Term...)}). */ public synchronized boolean tryDeleteDocument(IndexReader readerIn, int docID) throws IOException { final AtomicReader reader; @@ -1339,28 +1316,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{ } } - /** - * Deletes the document(s) matching the provided query. - * - *

NOTE: if this method hits an OutOfMemoryError - * you should immediately close the writer. See above for details.

- * - * @param query the query to identify the documents to be deleted - * @throws CorruptIndexException if the index is corrupt - * @throws IOException if there is a low-level IO error - */ - public void deleteDocuments(Query query) throws IOException { - ensureOpen(); - try { - if (docWriter.deleteQueries(query)) { - processEvents(true, false); - } - } catch (OutOfMemoryError oom) { - handleOOM(oom, "deleteDocuments(Query)"); - } - } - /** * Deletes the document(s) matching any of the provided queries. * All given deletes are applied and flushed atomically at the same time. @@ -2079,25 +2034,30 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{ /** * Delete all documents in the index. - * - *

This method will drop all buffered documents and will - * remove all segments from the index. This change will not be - * visible until a {@link #commit()} has been called. This method - * can be rolled back using {@link #rollback()}.

- * - *

NOTE: this method is much faster than using deleteDocuments( new MatchAllDocsQuery() ). - * Yet, this method also has different semantics compared to {@link #deleteDocuments(Query)} - * / {@link #deleteDocuments(Query...)} since internal data-structures are cleared as well - * as all segment information is forcefully dropped anti-viral semantics like omitting norms - * are reset or doc value types are cleared. Essentially a call to {@link #deleteAll()} is equivalent - * to creating a new {@link IndexWriter} with {@link OpenMode#CREATE} which a delete query only marks - * documents as deleted.

- * - *

NOTE: this method will forcefully abort all merges - * in progress. If other threads are running {@link - * #forceMerge}, {@link #addIndexes(IndexReader[])} or - * {@link #forceMergeDeletes} methods, they may receive - * {@link MergePolicy.MergeAbortedException}s. + * + *

+ * This method will drop all buffered documents and will remove all segments + * from the index. This change will not be visible until a {@link #commit()} + * has been called. This method can be rolled back using {@link #rollback()}. + *

+ * + *

+ * NOTE: this method is much faster than using deleteDocuments( new + * MatchAllDocsQuery() ). Yet, this method also has different semantics + * compared to {@link #deleteDocuments(Query...)} since internal + * data-structures are cleared as well as all segment information is + * forcefully dropped anti-viral semantics like omitting norms are reset or + * doc value types are cleared. Essentially a call to {@link #deleteAll()} is + * equivalent to creating a new {@link IndexWriter} with + * {@link OpenMode#CREATE} which a delete query only marks documents as + * deleted. + *

+ * + *

+ * NOTE: this method will forcefully abort all merges in progress. If other + * threads are running {@link #forceMerge}, {@link #addIndexes(IndexReader[])} + * or {@link #forceMergeDeletes} methods, they may receive + * {@link MergePolicy.MergeAbortedException}s. */ public void deleteAll() throws IOException { ensureOpen();