1 package org.apache.lucene.misc;
4 * Copyright 2005 The Apache Software Foundation
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
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;
28 import java.io.IOException;
31 * Merges indices specified on the command line into the index
32 * specified as the first command line argument.
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] ...");
40 FSDirectory mergedIndex = FSDirectory.open(new File(args[0]));
42 IndexWriter writer = new IndexWriter(mergedIndex, new IndexWriterConfig(
43 Version.LUCENE_CURRENT, new WhitespaceAnalyzer(Version.LUCENE_CURRENT))
44 .setOpenMode(OpenMode.CREATE));
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]));
51 System.out.println("Merging...");
52 writer.addIndexes(indexes);
54 System.out.println("Full merge...");
57 System.out.println("Done.");