1 package org.apache.lucene.index;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.io.IOException;
24 * A {@link MergePolicy} which never returns merges to execute (hence it's
25 * name). It is also a singleton and can be accessed through
26 * {@link NoMergePolicy#NO_COMPOUND_FILES} if you want to indicate the index
27 * does not use compound files, or through {@link NoMergePolicy#COMPOUND_FILES}
28 * otherwise. Use it if you want to prevent an {@link IndexWriter} from ever
29 * executing merges, without going through the hassle of tweaking a merge
30 * policy's settings to achieve that, such as changing its merge factor.
32 public final class NoMergePolicy extends MergePolicy {
35 * A singleton {@link NoMergePolicy} which indicates the index does not use
38 public static final MergePolicy NO_COMPOUND_FILES = new NoMergePolicy(false);
41 * A singleton {@link NoMergePolicy} which indicates the index uses compound
44 public static final MergePolicy COMPOUND_FILES = new NoMergePolicy(true);
46 private final boolean useCompoundFile;
48 private NoMergePolicy(boolean useCompoundFile) {
49 // prevent instantiation
50 this.useCompoundFile = useCompoundFile;
54 public void close() {}
57 public MergeSpecification findMerges(SegmentInfos segmentInfos)
58 throws CorruptIndexException, IOException { return null; }
61 public MergeSpecification findForcedMerges(SegmentInfos segmentInfos,
62 int maxSegmentCount, Map<SegmentInfo,Boolean> segmentsToMerge)
63 throws CorruptIndexException, IOException { return null; }
66 public MergeSpecification findForcedDeletesMerges(SegmentInfos segmentInfos)
67 throws CorruptIndexException, IOException { return null; }
70 public boolean useCompoundFile(SegmentInfos segments, SegmentInfo newSegment) { return useCompoundFile; }
73 public void setIndexWriter(IndexWriter writer) {}
76 public String toString() {
77 return "NoMergePolicy";