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: /** This is a {@link LogMergePolicy} that measures size of a
21: * segment as the number of documents (not taking deletions
22: * into account). */
23:
24: public class LogDocMergePolicy extends LogMergePolicy {
25:
26: /** Default minimum segment size. @see setMinMergeDocs */
27: public static final int DEFAULT_MIN_MERGE_DOCS = 1000;
28:
29: public LogDocMergePolicy() {
30: super ();
31: minMergeSize = DEFAULT_MIN_MERGE_DOCS;
32:
33: // maxMergeSize is never used by LogDocMergePolicy; set
34: // it to Long.MAX_VALUE to disable it
35: maxMergeSize = Long.MAX_VALUE;
36: }
37:
38: protected long size(SegmentInfo info) {
39: return info.docCount;
40: }
41:
42: /** Sets the minimum size for the lowest level segments.
43: * Any segments below this size are considered to be on
44: * the same level (even if they vary drastically in size)
45: * and will be merged whenever there are mergeFactor of
46: * them. This effectively truncates the "long tail" of
47: * small segments that would otherwise be created into a
48: * single level. If you set this too large, it could
49: * greatly increase the merging cost during indexing (if
50: * you flush many small segments). */
51: public void setMinMergeDocs(int minMergeDocs) {
52: minMergeSize = minMergeDocs;
53: }
54:
55: /** Get the minimum size for a segment to remain
56: * un-merged.
57: * @see #setMinMergeDocs **/
58: public int getMinMergeDocs() {
59: return (int) minMergeSize;
60: }
61: }
|