From cefa4d0bf0c7c848c2d0df4bef0cfe3b552e8ba9 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Tue, 30 Jun 2009 10:19:11 +0000 Subject: [PATCH] LUCENE-1705: clear flushed doc count in deleteAll git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@789651 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/IndexWriter.java | 1 + .../lucene/index/TestIndexWriterDelete.java | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.java index dad6d8b5d49..75e30da438e 100644 --- a/src/java/org/apache/lucene/index/IndexWriter.java +++ b/src/java/org/apache/lucene/index/IndexWriter.java @@ -3260,6 +3260,7 @@ public class IndexWriter { // Remove any buffered docs docWriter.abort(); + docWriter.setFlushedDocCount(0); // Remove all segments segmentInfos.clear(); diff --git a/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/src/test/org/apache/lucene/index/TestIndexWriterDelete.java index fb88fce886b..5733d85c621 100644 --- a/src/test/org/apache/lucene/index/TestIndexWriterDelete.java +++ b/src/test/org/apache/lucene/index/TestIndexWriterDelete.java @@ -297,9 +297,9 @@ public class TestIndexWriterDelete extends LuceneTestCase { assertEquals(7, reader.numDocs()); reader.close(); - // Add 2 new docs (after the deleteAll, before the commit) + // Add a doc and update a doc (after the deleteAll, before the commit) addDoc(modifier, 101, value); - addDoc(modifier, 102, value); + updateDoc(modifier, 102, value); // commit the delete all modifier.commit(); @@ -396,6 +396,18 @@ public class TestIndexWriterDelete extends LuceneTestCase { } + private void updateDoc(IndexWriter modifier, int id, int value) + throws IOException { + Document doc = new Document(); + doc.add(new Field("content", "aaa", Field.Store.NO, Field.Index.ANALYZED)); + doc.add(new Field("id", String.valueOf(id), Field.Store.YES, + Field.Index.NOT_ANALYZED)); + doc.add(new Field("value", String.valueOf(value), Field.Store.NO, + Field.Index.NOT_ANALYZED)); + modifier.updateDocument(new Term("id", String.valueOf(id)), doc); + } + + private void addDoc(IndexWriter modifier, int id, int value) throws IOException { Document doc = new Document();