diff --git a/CHANGES.txt b/CHANGES.txt index e40186a1e23..fec3f5993b1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -121,6 +121,9 @@ Optimizations during segment merges (e.g. during indexing or optimizing), thus improving performance . (Michael Busch via Otis Gospodnetic) + 4. LUCENE-388: Changes to maybeMergeSegments() to improve indexing speed. + (Paul Smith via Otis Gospodnetic) + Release 2.0.0 2006-05-26 API Changes diff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.java index 901a1fa4194..47cafe1a42e 100644 --- a/src/java/org/apache/lucene/index/IndexWriter.java +++ b/src/java/org/apache/lucene/index/IndexWriter.java @@ -110,6 +110,7 @@ public class IndexWriter { private SegmentInfos segmentInfos = new SegmentInfos(); // the segments private final Directory ramDirectory = new RAMDirectory(); // for temp segs + private long bufferedDocCount = 0; private Lock writeLock; private int termIndexInterval = DEFAULT_TERM_INDEX_INTERVAL; @@ -509,6 +510,7 @@ public class IndexWriter { dw.addDocument(segmentName, doc); synchronized (this) { segmentInfos.addElement(new SegmentInfo(segmentName, 1, ramDirectory)); + bufferedDocCount++; maybeMergeSegments(); } } @@ -691,6 +693,15 @@ public class IndexWriter { /** Incremental segment merger. */ private final void maybeMergeSegments() throws IOException { + /** + * do not bother checking the segment details to determine + * if we should merge, but instead honour the maxBufferedDocs(minMergeDocs) + * property to ensure we do not spend time checking for merge conditions + * + */ + if(bufferedDocCount