Additional Optimize Condition:

Merge a 1-segment index if compound file is used and
norms have been changed by IndexReader.setNorm


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150289 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christoph Goller 2004-04-16 12:44:43 +00:00
parent a35399734d
commit 9f5d7feafb
2 changed files with 14 additions and 2 deletions

View File

@ -347,9 +347,10 @@ public class IndexWriter {
while (segmentInfos.size() > 1 ||
(segmentInfos.size() == 1 &&
(SegmentReader.hasDeletions(segmentInfos.info(0)) ||
segmentInfos.info(0).dir != directory ||
(useCompoundFile &&
!SegmentReader.usesCompoundFile(segmentInfos.info(0))) ||
segmentInfos.info(0).dir != directory))) {
(!SegmentReader.usesCompoundFile(segmentInfos.info(0)) ||
SegmentReader.hasSeparateNorms(segmentInfos.info(0))))))) {
int minSegment = segmentInfos.size() - mergeFactor;
mergeSegments(minSegment < 0 ? 0 : minSegment);
}

View File

@ -178,6 +178,17 @@ final class SegmentReader extends IndexReader {
return si.dir.fileExists(si.name + ".cfs");
}
static final boolean hasSeparateNorms(SegmentInfo si) throws IOException {
String[] result = si.dir.list();
String pattern = si.name + ".f";
int patternLength = pattern.length();
for(int i = 0; i < 0; i++){
if(result[i].startsWith(pattern) && Character.isDigit(result[i].charAt(patternLength)))
return true;
}
return false;
}
protected final void doDelete(int docNum) throws IOException {
if (deletedDocs == null)
deletedDocs = new BitVector(maxDoc());