add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / misc / src / java / org / apache / lucene / misc / IndexMergeTool.java
1 package org.apache.lucene.misc;
2
3 /**
4   * Copyright 2005 The Apache Software Foundation
5   *
6   * Licensed under the Apache License, Version 2.0 (the "License");
7   * you may not use this file except in compliance with the License.
8   * You may obtain a copy of the License at
9   *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18
19 import org.apache.lucene.analysis.WhitespaceAnalyzer;
20 import org.apache.lucene.index.IndexWriter;
21 import org.apache.lucene.index.IndexWriterConfig;
22 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
23 import org.apache.lucene.store.Directory;
24 import org.apache.lucene.store.FSDirectory;
25 import org.apache.lucene.util.Version;
26
27 import java.io.File;
28 import java.io.IOException;
29
30 /**
31  * Merges indices specified on the command line into the index
32  * specified as the first command line argument.
33  */
34 public class IndexMergeTool {
35   public static void main(String[] args) throws IOException {
36     if (args.length < 3) {
37       System.err.println("Usage: IndexMergeTool <mergedIndex> <index1> <index2> [index3] ...");
38       System.exit(1);
39     }
40     FSDirectory mergedIndex = FSDirectory.open(new File(args[0]));
41
42     IndexWriter writer = new IndexWriter(mergedIndex, new IndexWriterConfig(
43         Version.LUCENE_CURRENT, new WhitespaceAnalyzer(Version.LUCENE_CURRENT))
44         .setOpenMode(OpenMode.CREATE));
45
46     Directory[] indexes = new Directory[args.length - 1];
47     for (int i = 1; i < args.length; i++) {
48       indexes[i  - 1] = FSDirectory.open(new File(args[i]));
49     }
50
51     System.out.println("Merging...");
52     writer.addIndexes(indexes);
53
54     System.out.println("Optimizing...");
55     writer.optimize();
56     writer.close();
57     System.out.println("Done.");
58   }
59 }