Apache Lucene open-source search software
LUCENE-2996: addIndexes(IndexReader) does not flush before adding the new indexes, and as a consequence, deletes are applied on the incoming indexes too
Shai Ererac7c03f6c6199
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 4784ca1a609..e93f3cf0945 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -366,6 +366,10 @@ Bug fixes* LUCENE-2936: PhraseQuery score explanations were not correctlyidentifying matches vs non-matches. (hossman)+* LUCENE-2996: addIndexes(IndexReader) did not flush before adding the new+ indexes, causing existing deletions to be applied on the incoming indexes as+ well. (Shai Erera, Mike McCandless)+======================= Lucene 3.x (not yet released) =======================Changes in backwards compatibility policydiff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.javaindex cedd1990905..374934bef79 100644--- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java@@ -2211,6 +2211,10 @@ public class IndexWriter implements Closeable {ensureOpen();try {+ if (infoStream != null)+ message("flush at addIndexes(IndexReader...)");+ flush(false, true);+String mergedName = newSegmentName();SegmentMerger merger = new SegmentMerger(directory, config.getTermIndexInterval(),mergedName, null, codecs, payloadProcessorProvider,diff --git a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.javaindex a0055751e43..6085d342c17 100755--- a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java+++ b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java@@ -938,6 +938,40 @@ public class TestAddIndexes extends LuceneTestCase {assertTrue(c.failures.size() == 0);}++ // LUCENE-2996: tests that addIndexes(IndexReader) applies existing deletes correctly.+ public void testExistingDeletes() throws Exception {+ Directory[] dirs = new Directory[2];+ for (int i = 0; i < dirs.length; i++) {+ dirs[i] = newDirectory();+ IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer());+ IndexWriter writer = new IndexWriter(dirs[i], conf);+ Document doc = new Document();+ doc.add(new Field("id", "myid", Store.NO, Index.NOT_ANALYZED_NO_NORMS));+ writer.addDocument(doc);+ writer.close();+ }++ IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer());+ IndexWriter writer = new IndexWriter(dirs[0], conf);++ // Now delete the document+ writer.deleteDocuments(new Term("id", "myid"));+ IndexReader r = IndexReader.open(dirs[1]);+ try {+ writer.addIndexes(r);+ } finally {+ r.close();+ }+ writer.commit();+ assertEquals("Documents from the incoming index should not have been deleted", 1, writer.numDocs());+ writer.close();++ for (Directory dir : dirs) {+ dir.close();+ }++ }private void addDocs3(IndexWriter writer, int numDocs) throws IOException {for (int i = 0; i < numDocs; i++) {