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
This commit is contained in:
Michael McCandless 2013-10-17 17:10:38 +00:00
parent ea81f1add6
commit f9f0cdd56f
3 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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())));