From f9f0cdd56fdc550d193db5c841571d7bbb0ff6cb Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 17 Oct 2013 17:10:38 +0000 Subject: [PATCH] LUCENE-5289: IndexWriter.hasUncommittedChanges was returning false when only deletes were buffered git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1533164 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 4 ++++ .../src/java/org/apache/lucene/index/IndexWriter.java | 2 +- .../test/org/apache/lucene/index/TestIndexWriter.java | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 67d4c89fed0..fa598235bc3 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -144,6 +144,10 @@ Bug Fixes * LUCENE-5272: OpenBitSet.ensureCapacity did not modify numBits, causing false assertion errors in fastSet. (Shai Erera) +* LUCENE-5289: IndexWriter.hasUncommittedChanges was returning false + when there were buffered delete-by-Term. (Shalin Shekhar Mangar, + Mike McCandless) + API Changes: * LUCENE-5222: Add SortField.needsScores(). Previously it was not possible 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 e07f50e4f01..b794e0bc08a 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -2882,7 +2882,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{ /** Returns true if there are changes that have not been committed */ public final boolean hasUncommittedChanges() { - return changeCount != lastCommitChangeCount; + return changeCount != lastCommitChangeCount || docWriter.anyChanges() || bufferedDeletesStream.any(); } private final void commitInternal() throws IOException { diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java index 1602ef917cc..9bba40dd63c 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -2253,6 +2253,17 @@ public class TestIndexWriter extends LuceneTestCase { assertFalse(writer.hasUncommittedChanges()); writer.addDocument(doc); assertTrue(writer.hasUncommittedChanges()); + writer.commit(); + doc = new Document(); + doc.add(newStringField("id", "xyz", Field.Store.YES)); + writer.addDocument(doc); + assertTrue(writer.hasUncommittedChanges()); + writer.commit(); + assertFalse(writer.hasUncommittedChanges()); + writer.deleteDocuments(new Term("id", "xyz")); + assertTrue(writer.hasUncommittedChanges()); + writer.commit(); + assertFalse(writer.hasUncommittedChanges()); writer.close(); writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random())));