1 package org.apache.lucene; 2 3 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 26 class IndexTest { 27 public static void main(String [] args) { 28 try { 29 Date start = new Date (); 30 IndexWriter writer = new IndexWriter("F:\\test", new SimpleAnalyzer(), 32 true); 33 34 writer.mergeFactor = 20; 35 36 indexDocs(writer, new File ("F:\\recipes")); 38 39 writer.optimize(); 40 writer.close(); 41 42 Date end = new Date (); 43 44 System.out.print(end.getTime() - start.getTime()); 45 System.out.println(" total milliseconds"); 46 47 Runtime runtime = Runtime.getRuntime(); 48 49 System.out.print(runtime.freeMemory()); 50 System.out.println(" free memory before gc"); 51 System.out.print(runtime.totalMemory()); 52 System.out.println(" total memory before gc"); 53 54 runtime.gc(); 55 56 System.out.print(runtime.freeMemory()); 57 System.out.println(" free memory after gc"); 58 System.out.print(runtime.totalMemory()); 59 System.out.println(" total memory after gc"); 60 61 } catch (Exception e) { 62 System.out.println(" caught a " + e.getClass() + 63 "\n with message: " + e.getMessage()); 64 } 65 } 66 67 public static void indexDocs(IndexWriter writer, File file) 68 throws Exception { 69 if (file.isDirectory()) { 70 String [] files = file.list(); 71 for (int i = 0; i < files.length; i++) 72 indexDocs(writer, new File (file, files[i])); 73 } else { 74 System.out.println("adding " + file); 75 writer.addDocument(FileDocument.Document(file)); 76 } 77 } 78 } 79 | Popular Tags |