01: package org.apache.lucene;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * 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 org.apache.lucene.analysis.SimpleAnalyzer;
21: import org.apache.lucene.index.IndexWriter;
22: import org.apache.lucene.demo.FileDocument;
23:
24: import java.io.File;
25: import java.util.Date;
26:
27: class IndexTest {
28: public static void main(String[] args) {
29: try {
30: Date start = new Date();
31: IndexWriter writer = new IndexWriter(File.createTempFile(
32: "luceneTest", "idx"), new SimpleAnalyzer(), true);
33:
34: writer.setMergeFactor(20);
35:
36: indexDocs(writer, new File("/tmp"));
37:
38: writer.optimize();
39: writer.close();
40:
41: Date end = new Date();
42:
43: System.out.print(end.getTime() - start.getTime());
44: System.out.println(" total milliseconds");
45:
46: Runtime runtime = Runtime.getRuntime();
47:
48: System.out.print(runtime.freeMemory());
49: System.out.println(" free memory before gc");
50: System.out.print(runtime.totalMemory());
51: System.out.println(" total memory before gc");
52:
53: runtime.gc();
54:
55: System.out.print(runtime.freeMemory());
56: System.out.println(" free memory after gc");
57: System.out.print(runtime.totalMemory());
58: System.out.println(" total memory after gc");
59:
60: } catch (Exception e) {
61: System.out.println(" caught a " + e.getClass()
62: + "\n with message: " + e.getMessage());
63: }
64: }
65:
66: public static void indexDocs(IndexWriter writer, File file)
67: throws Exception {
68: if (file.isDirectory()) {
69: String[] files = file.list();
70: for (int i = 0; i < files.length; i++)
71: indexDocs(writer, new File(file, files[i]));
72: } else {
73: System.out.println("adding " + file);
74: writer.addDocument(FileDocument.Document(file));
75: }
76: }
77: }
|