| 1 |
|
package org.apache.lucene; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
import org.apache.lucene.analysis.SimpleAnalyzer; |
| 20 |
|
import org.apache.lucene.index.IndexWriter; |
| 21 |
|
import org.apache.lucene.demo.FileDocument; |
| 22 |
|
|
| 23 |
|
import java.io.File; |
| 24 |
|
import java.util.Date; |
| 25 |
|
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 5 |
Complexity Density: 0.19 |
|
| 26 |
|
class IndexTest { |
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 2 |
Complexity Density: 0.1 |
|
| 27 |
0
|
public static void main(String[] args) {... |
| 28 |
0
|
try { |
| 29 |
0
|
Date start = new Date(); |
| 30 |
0
|
IndexWriter writer = new IndexWriter(File.createTempFile("luceneTest", "idx"), |
| 31 |
|
new SimpleAnalyzer(), true); |
| 32 |
|
|
| 33 |
0
|
writer.setMergeFactor(20); |
| 34 |
|
|
| 35 |
0
|
indexDocs(writer, new File("/tmp")); |
| 36 |
|
|
| 37 |
0
|
writer.optimize(); |
| 38 |
0
|
writer.close(); |
| 39 |
|
|
| 40 |
0
|
Date end = new Date(); |
| 41 |
|
|
| 42 |
0
|
System.out.print(end.getTime() - start.getTime()); |
| 43 |
0
|
System.out.println(" total milliseconds"); |
| 44 |
|
|
| 45 |
0
|
Runtime runtime = Runtime.getRuntime(); |
| 46 |
|
|
| 47 |
0
|
System.out.print(runtime.freeMemory()); |
| 48 |
0
|
System.out.println(" free memory before gc"); |
| 49 |
0
|
System.out.print(runtime.totalMemory()); |
| 50 |
0
|
System.out.println(" total memory before gc"); |
| 51 |
|
|
| 52 |
0
|
runtime.gc(); |
| 53 |
|
|
| 54 |
0
|
System.out.print(runtime.freeMemory()); |
| 55 |
0
|
System.out.println(" free memory after gc"); |
| 56 |
0
|
System.out.print(runtime.totalMemory()); |
| 57 |
0
|
System.out.println(" total memory after gc"); |
| 58 |
|
|
| 59 |
|
} catch (Exception e) { |
| 60 |
0
|
System.out.println(" caught a " + e.getClass() + |
| 61 |
|
"\n with message: " + e.getMessage()); |
| 62 |
|
} |
| 63 |
|
} |
| 64 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 65 |
0
|
public static void indexDocs(IndexWriter writer, File file)... |
| 66 |
|
throws Exception { |
| 67 |
0
|
if (file.isDirectory()) { |
| 68 |
0
|
String[] files = file.list(); |
| 69 |
0
|
for (int i = 0; i < files.length; i++) |
| 70 |
0
|
indexDocs(writer, new File(file, files[i])); |
| 71 |
|
} else { |
| 72 |
0
|
System.out.println("adding " + file); |
| 73 |
0
|
writer.addDocument(FileDocument.Document(file)); |
| 74 |
|
} |
| 75 |
|
} |
| 76 |
|
} |