pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / java / org / apache / lucene / index / LogDocMergePolicy.java
1 package org.apache.lucene.index;
2
3 import java.io.IOException;
4
5 /**
6  * Licensed to the Apache Software Foundation (ASF) under one or more
7  * contributor license agreements.  See the NOTICE file distributed with
8  * this work for additional information regarding copyright ownership.
9  * The ASF licenses this file to You under the Apache License, Version 2.0
10  * (the "License"); you may not use this file except in compliance with
11  * the License.  You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 /** This is a {@link LogMergePolicy} that measures size of a
23  *  segment as the number of documents (not taking deletions
24  *  into account). */
25
26 public class LogDocMergePolicy extends LogMergePolicy {
27
28   /** Default minimum segment size.  @see setMinMergeDocs */
29   public static final int DEFAULT_MIN_MERGE_DOCS = 1000;
30
31   public LogDocMergePolicy() {
32     minMergeSize = DEFAULT_MIN_MERGE_DOCS;
33     
34     // maxMergeSize(ForForcedMerge) are never used by LogDocMergePolicy; set
35     // it to Long.MAX_VALUE to disable it
36     maxMergeSize = Long.MAX_VALUE;
37     maxMergeSizeForForcedMerge = Long.MAX_VALUE;
38   }
39
40   @Override
41   protected long size(SegmentInfo info) throws IOException {
42     return sizeDocs(info);
43   }
44
45   /** Sets the minimum size for the lowest level segments.
46    * Any segments below this size are considered to be on
47    * the same level (even if they vary drastically in size)
48    * and will be merged whenever there are mergeFactor of
49    * them.  This effectively truncates the "long tail" of
50    * small segments that would otherwise be created into a
51    * single level.  If you set this too large, it could
52    * greatly increase the merging cost during indexing (if
53    * you flush many small segments). */
54   public void setMinMergeDocs(int minMergeDocs) {
55     minMergeSize = minMergeDocs;
56   }
57
58   /** Get the minimum size for a segment to remain
59    *  un-merged.
60    *  @see #setMinMergeDocs **/
61   public int getMinMergeDocs() {
62     return (int) minMergeSize;
63   }
64 }