LUCENE-2996: addIndexes(IndexReader) does not flush before adding the new indexes, and as a consequence, deletes are applied on the incoming indexes too

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1086288 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2011-03-28 15:54:39 +00:00
parent 76b494593d
commit c7c03f6c61
3 changed files with 42 additions and 0 deletions

View File

@ -366,6 +366,10 @@ Bug fixes
* LUCENE-2936: PhraseQuery score explanations were not correctly
identifying 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 policy

View File

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

View File

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