add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / java / org / apache / lucene / index / LogByteSizeMergePolicy.java
1 package org.apache.lucene.index;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * 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 = 2048;
32
33   /** Default maximum segment size.  A segment of this size
34    *  or larger will never be merged during optimize.  @see setMaxMergeMBForOptimize */
35   public static final double DEFAULT_MAX_MERGE_MB_FOR_OPTIMIZE = Long.MAX_VALUE;
36
37   public LogByteSizeMergePolicy() {
38     minMergeSize = (long) (DEFAULT_MIN_MERGE_MB*1024*1024);
39     maxMergeSize = (long) (DEFAULT_MAX_MERGE_MB*1024*1024);
40     maxMergeSizeForOptimize = (long) (DEFAULT_MAX_MERGE_MB_FOR_OPTIMIZE*1024*1024);
41   }
42   
43   @Override
44   protected long size(SegmentInfo info) throws IOException {
45     return sizeBytes(info);
46   }
47
48   /** <p>Determines the largest segment (measured by total
49    *  byte size of the segment's files, in MB) that may be
50    *  merged with other segments.  Small values (e.g., less
51    *  than 50 MB) are best for interactive indexing, as this
52    *  limits the length of pauses while indexing to a few
53    *  seconds.  Larger values are best for batched indexing
54    *  and speedier searches.</p>
55    *
56    *  <p>Note that {@link #setMaxMergeDocs} is also
57    *  used to check whether a segment is too large for
58    *  merging (it's either or).</p>*/
59   public void setMaxMergeMB(double mb) {
60     maxMergeSize = (long) (mb*1024*1024);
61   }
62
63   /** Returns the largest segment (measured by total byte
64    *  size of the segment's files, in MB) that may be merged
65    *  with other segments.
66    *  @see #setMaxMergeMB */
67   public double getMaxMergeMB() {
68     return ((double) maxMergeSize)/1024/1024;
69   }
70
71   /** <p>Determines the largest segment (measured by total
72    *  byte size of the segment's files, in MB) that may be
73    *  merged with other segments during optimize. Setting
74    *  it low will leave the index with more than 1 segment,
75    *  even if {@link IndexWriter#optimize()} is called.*/
76   public void setMaxMergeMBForOptimize(double mb) {
77     maxMergeSizeForOptimize = (long) (mb*1024*1024);
78   }
79
80   /** Returns the largest segment (measured by total byte
81    *  size of the segment's files, in MB) that may be merged
82    *  with other segments during optimize.
83    *  @see #setMaxMergeMBForOptimize */
84   public double getMaxMergeMBForOptimize() {
85     return ((double) maxMergeSizeForOptimize)/1024/1024;
86   }
87
88   /** Sets the minimum size for the lowest level segments.
89    * Any segments below this size are considered to be on
90    * the same level (even if they vary drastically in size)
91    * and will be merged whenever there are mergeFactor of
92    * them.  This effectively truncates the "long tail" of
93    * small segments that would otherwise be created into a
94    * single level.  If you set this too large, it could
95    * greatly increase the merging cost during indexing (if
96    * you flush many small segments). */
97   public void setMinMergeMB(double mb) {
98     minMergeSize = (long) (mb*1024*1024);
99   }
100
101   /** Get the minimum size for a segment to remain
102    *  un-merged.
103    *  @see #setMinMergeMB **/
104   public double getMinMergeMB() {
105     return ((double) minMergeSize)/1024/1024;
106   }
107 }