01: package org.apache.lucene.index;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import java.io.IOException;
21:
22: /** This is a {@link LogMergePolicy} that measures size of a
23: * segment as the total byte size of the segment's files. */
24: public class LogByteSizeMergePolicy extends LogMergePolicy {
25:
26: /** Default minimum segment size. @see setMinMergeMB */
27: public static final double DEFAULT_MIN_MERGE_MB = 1.6;
28:
29: /** Default maximum segment size. A segment of this size
30: * or larger will never be merged. @see setMaxMergeMB */
31: public static final double DEFAULT_MAX_MERGE_MB = (double) Long.MAX_VALUE;
32:
33: public LogByteSizeMergePolicy() {
34: super ();
35: minMergeSize = (long) (DEFAULT_MIN_MERGE_MB * 1024 * 1024);
36: maxMergeSize = (long) (DEFAULT_MAX_MERGE_MB * 1024 * 1024);
37: }
38:
39: protected long size(SegmentInfo info) throws IOException {
40: return info.sizeInBytes();
41: }
42:
43: /** <p>Determines the largest segment (measured by total
44: * byte size of the segment's files, in MB) that may be
45: * merged with other segments. Small values (e.g., less
46: * than 50 MB) are best for interactive indexing, as this
47: * limits the length of pauses while indexing to a few
48: * seconds. Larger values are best for batched indexing
49: * and speedier searches.</p>
50: *
51: * <p>Note that {@link #setMaxMergeDocs} is also
52: * used to check whether a segment is too large for
53: * merging (it's either or).</p>*/
54: public void setMaxMergeMB(double mb) {
55: maxMergeSize = (long) (mb * 1024 * 1024);
56: }
57:
58: /** Returns the largest segment (meaured by total byte
59: * size of the segment's files, in MB) that may be merged
60: * with other segments.
61: * @see #setMaxMergeMB */
62: public double getMaxMergeMB() {
63: return ((double) maxMergeSize) / 1024 / 1024;
64: }
65:
66: /** Sets the minimum size for the lowest level segments.
67: * Any segments below this size are considered to be on
68: * the same level (even if they vary drastically in size)
69: * and will be merged whenever there are mergeFactor of
70: * them. This effectively truncates the "long tail" of
71: * small segments that would otherwise be created into a
72: * single level. If you set this too large, it could
73: * greatly increase the merging cost during indexing (if
74: * you flush many small segments). */
75: public void setMinMergeMB(double mb) {
76: minMergeSize = (long) (mb * 1024 * 1024);
77: }
78:
79: /** Get the minimum size for a segment to remain
80: * un-merged.
81: * @see #setMinMergeMB **/
82: public double getMinMergeMB() {
83: return ((double) minMergeSize) / 1024 / 1024;
84: }
85: }
|