1 package org.apache.lucene.index;
3 import java.io.IOException;
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 /** This is a {@link LogMergePolicy} that measures size of a
23 * segment as the number of documents (not taking deletions
26 public class LogDocMergePolicy extends LogMergePolicy {
28 /** Default minimum segment size. @see setMinMergeDocs */
29 public static final int DEFAULT_MIN_MERGE_DOCS = 1000;
31 public LogDocMergePolicy() {
32 minMergeSize = DEFAULT_MIN_MERGE_DOCS;
34 // maxMergeSize(ForOptimize) are never used by LogDocMergePolicy; set
35 // it to Long.MAX_VALUE to disable it
36 maxMergeSize = Long.MAX_VALUE;
37 maxMergeSizeForOptimize = Long.MAX_VALUE;
41 protected long size(SegmentInfo info) throws IOException {
42 return sizeDocs(info);
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;
58 /** Get the minimum size for a segment to remain
60 * @see #setMinMergeDocs **/
61 public int getMinMergeDocs() {
62 return (int) minMergeSize;