1 From: Joe Shaw <joeshaw@novell.com>
3 Optimize IndexWriter.MaybeMergeSegments() by caching the number of buffered
4 documents rather than counting the number after each document addition. This
5 is a a backport from the Lucene devel 2.1 branch.
7 See https://issues.apache.org/jira/browse/LUCENE-388
9 Index: Index/IndexWriter.cs
10 ===================================================================
11 RCS file: /cvs/gnome/beagle/beagled/Lucene.Net/Index/IndexWriter.cs,v
12 retrieving revision 1.4
13 diff -u -p -u -r1.4 IndexWriter.cs
14 --- Index/IndexWriter.cs 2 Oct 2006 17:08:56 -0000 1.4
15 +++ Index/IndexWriter.cs 16 Oct 2006 20:41:55 -0000
16 @@ -241,6 +241,8 @@ namespace Lucene.Net.Index
18 private SegmentInfos segmentInfos = new SegmentInfos(); // the segments
19 private Directory ramDirectory = new RAMDirectory(); // for temp segs
21 + private int singleDocSegmentsCount = 0; // for speeding decision on merge candidates
23 private Lock writeLock;
25 @@ -618,6 +620,7 @@ namespace Lucene.Net.Index
28 segmentInfos.Add(new SegmentInfo(segmentName, 1, ramDirectory));
29 + singleDocSegmentsCount++;
33 @@ -815,8 +818,8 @@ namespace Lucene.Net.Index
34 while (targetMergeDocs <= maxMergeDocs)
36 // find segments smaller than current target size
37 - int minSegment = segmentInfos.Count;
39 + int minSegment = segmentInfos.Count - singleDocSegmentsCount; // top 1-doc segments are taken for sure
40 + int mergeDocs = singleDocSegmentsCount;
41 while (--minSegment >= 0)
43 SegmentInfo si = segmentInfos.Info(minSegment);
44 @@ -825,10 +828,11 @@ namespace Lucene.Net.Index
45 mergeDocs += si.docCount;
48 - if (mergeDocs >= targetMergeDocs)
49 + if (mergeDocs >= targetMergeDocs) {
50 // found a merge to do
51 MergeSegments(minSegment + 1);
53 + singleDocSegmentsCount = 0;
57 targetMergeDocs *= mergeFactor; // increase target size