Index: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java =================================================================== --- lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java (revision 1496623) +++ lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java (working copy) @@ -2209,4 +2209,27 @@ dir.close(); } } + + public void testHasUncommittedChanges() throws IOException { + Directory dir = newDirectory(); + IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random()))); + assertTrue(writer.hasUncommittedChanges()); // this will be true because a commit will create a new segment + Document doc = new Document(); + doc.add(newTextField("myfield", "a b c", Field.Store.NO)); + writer.addDocument(doc); + assertTrue(writer.hasUncommittedChanges()); + writer.commit(); + assertFalse(writer.hasUncommittedChanges()); + writer.addDocument(doc); + assertTrue(writer.hasUncommittedChanges()); + writer.close(); + + writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random()))); + assertFalse(writer.hasUncommittedChanges()); + writer.addDocument(doc); + assertTrue(writer.hasUncommittedChanges()); + + writer.close(); + dir.close(); + } } Index: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- lucene/core/src/java/org/apache/lucene/index/IndexWriter.java (revision 1496623) +++ lucene/core/src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -2827,6 +2827,11 @@ commitInternal(); } + /** Returns true if there are changes that have not been committed */ + public final boolean hasUncommittedChanges() { + return changeCount != lastCommitChangeCount; + } + private final void commitInternal() throws IOException { if (infoStream.isEnabled("IW")) {