Fixed to never delete added indexes.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@149665 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Doug Cutting 2002-01-29 16:30:16 +00:00
parent 2f2133f715
commit 60817cb719
1 changed files with 4 additions and 17 deletions

View File

@ -225,19 +225,11 @@ public final class IndexWriter {
public final synchronized void addIndexes(Directory[] dirs) public final synchronized void addIndexes(Directory[] dirs)
throws IOException { throws IOException {
optimize(); // start with zero or 1 seg optimize(); // start with zero or 1 seg
int minSegment = segmentInfos.size();
int segmentsAddedSinceMerge = 0;
for (int i = 0; i < dirs.length; i++) { for (int i = 0; i < dirs.length; i++) {
SegmentInfos sis = new SegmentInfos(); // read infos from dir SegmentInfos sis = new SegmentInfos(); // read infos from dir
sis.read(dirs[i]); sis.read(dirs[i]);
for (int j = 0; j < sis.size(); j++) { for (int j = 0; j < sis.size(); j++) {
segmentInfos.addElement(sis.info(j)); // add each info segmentInfos.addElement(sis.info(j)); // add each info
// merge whenever mergeFactor segments have been added
if (++segmentsAddedSinceMerge == mergeFactor) {
mergeSegments(minSegment++, false);
segmentsAddedSinceMerge = 0;
}
} }
} }
optimize(); // final cleanup optimize(); // final cleanup
@ -286,13 +278,7 @@ public final class IndexWriter {
/** Pops segments off of segmentInfos stack down to minSegment, merges them, /** Pops segments off of segmentInfos stack down to minSegment, merges them,
and pushes the merged index onto the top of the segmentInfos stack. */ and pushes the merged index onto the top of the segmentInfos stack. */
private final void mergeSegments(int minSegment) throws IOException { private final void mergeSegments(int minSegment)
mergeSegments(minSegment, true);
}
/** Pops segments off of segmentInfos stack down to minSegment, merges them,
and pushes the merged index onto the top of the segmentInfos stack. */
private final void mergeSegments(int minSegment, boolean delete)
throws IOException { throws IOException {
String mergedName = newSegmentName(); String mergedName = newSegmentName();
int mergedDocCount = 0; int mergedDocCount = 0;
@ -305,8 +291,9 @@ public final class IndexWriter {
infoStream.print(" " + si.name + " (" + si.docCount + " docs)"); infoStream.print(" " + si.name + " (" + si.docCount + " docs)");
SegmentReader reader = new SegmentReader(si); SegmentReader reader = new SegmentReader(si);
merger.add(reader); merger.add(reader);
if (delete) if ((reader.directory == this.directory) || // if we own the directory
segmentsToDelete.addElement(reader); // queue for deletion (reader.directory == this.ramDirectory))
segmentsToDelete.addElement(reader); // queue segment for deletion
mergedDocCount += si.docCount; mergedDocCount += si.docCount;
} }
if (infoStream != null) { if (infoStream != null) {