01: package org.apache.lucene.misc;
02:
03: /**
04: * Copyright 2005 The Apache Software Foundation
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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.index.IndexWriter;
20: import org.apache.lucene.analysis.SimpleAnalyzer;
21: import org.apache.lucene.store.Directory;
22: import org.apache.lucene.store.FSDirectory;
23:
24: import java.io.File;
25: import java.io.IOException;
26:
27: /**
28: * Merges indices specified on the command line into the index
29: * specified as the first command line argument.
30: * @author Erik Hatcher
31: * @version $Id$
32: */
33: public class IndexMergeTool {
34: public static void main(String[] args) throws IOException {
35: if (args.length < 3) {
36: System.err
37: .println("Usage: IndexMergeTool <mergedIndex> <index1> <index2> [index3] ...");
38: System.exit(1);
39: }
40: File mergedIndex = new File(args[0]);
41:
42: IndexWriter writer = new IndexWriter(mergedIndex,
43: new SimpleAnalyzer(), true);
44:
45: Directory[] indexes = new Directory[args.length - 1];
46: for (int i = 1; i < args.length; i++) {
47: indexes[i - 1] = FSDirectory.getDirectory(args[i], false);
48: }
49:
50: System.out.println("Merging...");
51: writer.addIndexes(indexes);
52:
53: System.out.println("Optimizing...");
54: writer.optimize();
55: writer.close();
56: System.out.println("Done.");
57: }
58: }
|