pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / java / org / apache / lucene / index / NoMergePolicy.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 import java.util.Map;
22
23 /**
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.
31  */
32 public final class NoMergePolicy extends MergePolicy {
33
34   /**
35    * A singleton {@link NoMergePolicy} which indicates the index does not use
36    * compound files.
37    */
38   public static final MergePolicy NO_COMPOUND_FILES = new NoMergePolicy(false);
39
40   /**
41    * A singleton {@link NoMergePolicy} which indicates the index uses compound
42    * files.
43    */
44   public static final MergePolicy COMPOUND_FILES = new NoMergePolicy(true);
45
46   private final boolean useCompoundFile;
47   
48   private NoMergePolicy(boolean useCompoundFile) {
49     // prevent instantiation
50     this.useCompoundFile = useCompoundFile;
51   }
52
53   @Override
54   public void close() {}
55
56   @Override
57   public MergeSpecification findMerges(SegmentInfos segmentInfos)
58       throws CorruptIndexException, IOException { return null; }
59
60   @Override
61   public MergeSpecification findForcedMerges(SegmentInfos segmentInfos,
62              int maxSegmentCount, Map<SegmentInfo,Boolean> segmentsToMerge)
63       throws CorruptIndexException, IOException { return null; }
64
65   @Override
66   public MergeSpecification findForcedDeletesMerges(SegmentInfos segmentInfos)
67       throws CorruptIndexException, IOException { return null; }
68
69   @Override
70   public boolean useCompoundFile(SegmentInfos segments, SegmentInfo newSegment) { return useCompoundFile; }
71
72   @Override
73   public void setIndexWriter(IndexWriter writer) {}
74
75   @Override
76   public String toString() {
77     return "NoMergePolicy";
78   }
79 }