/** * Records the fact that roughly units amount of work have been done since this method was last * called. When adding time-consuming code into SegmentMerger, you should test different values * for units to ensure that the time in between calls to merge.checkAborted is up to ~ 1 second. */ public void work(double units) throws MergePolicy.MergeAbortedException { workCount += units; if (workCount >= 10000.0) { merge.checkAborted(dir); workCount = 0; } }
@Override public synchronized void merge(IndexWriter writer, MergeTrigger trigger, boolean newMergesFound) throws IOException { while (true) { MergePolicy.OneMerge merge = writer.getNextMerge(); if (merge == null) { break; } int numDocs = 0; for (int i = 0; i < merge.segments.size(); i++) { int maxDoc = merge.segments.get(i).info.maxDoc(); numDocs += maxDoc; assertTrue(maxDoc < 20); } writer.merge(merge); assertEquals(numDocs, merge.getMergeInfo().info.maxDoc()); } }
@Override public void doMerge(MergePolicy.OneMerge merge) throws IOException { totMergedBytes += merge.totalBytesSize(); super.doMerge(merge); }