1 17 18 19 20 package org.apache.lenya.lucene.index; 21 22 import java.io.File ; 23 import java.util.Date ; 24 25 import org.apache.lenya.lucene.IndexConfiguration; 26 import org.apache.lenya.xml.DOMUtil; 27 import org.apache.lenya.xml.DocumentHelper; 28 import org.apache.lenya.xml.XPath; 29 import org.w3c.dom.Document ; 30 31 public class Index { 32 37 public static void main(String [] argv) { 38 try { 39 String index = "index"; 40 boolean create = false; 41 File root = null; 42 43 String usage = "Index <lucene.xconf> [file]"; 44 45 if (argv.length == 0) { 46 System.err.println("Usage: " + usage); 47 48 return; 49 } 50 51 IndexConfiguration ie = new IndexConfiguration(argv[0]); 52 index = ie.resolvePath(ie.getIndexDir()); 53 root = new File (ie.resolvePath(ie.getHTDocsDumpDir())); 54 55 if (ie.getUpdateIndexType().equals("new")) { 56 create = true; 57 } else if (ie.getUpdateIndexType().equals("incremental")) { 58 create = false; 59 } else { 60 System.err.println("ERROR: No such update-index/@type: " + ie.getUpdateIndexType()); 61 62 return; 63 } 64 65 Date start = new Date (); 66 67 Indexer indexer = (Indexer) ie.getIndexerClass().newInstance(); 68 69 DOMUtil du = new DOMUtil(); 70 String path = argv[0]; 71 72 Document config = DocumentHelper.readDocument(new File (path)); 73 indexer.configure(du.getElement(config.getDocumentElement(), new XPath("indexer")), argv[0]); 74 75 if (argv.length == 2) { 76 indexer.indexDocument(new File (argv[1])); 77 return; 78 } 79 80 if (create) { 81 indexer.createIndex(root, new File (index)); 82 } else { 83 indexer.updateIndex(root, new File (index)); 84 } 85 86 Date end = new Date (); 87 88 System.out.print(end.getTime() - start.getTime()); 89 System.out.println(" total milliseconds"); 90 } catch (Exception e) { 91 e.printStackTrace(System.out); 92 } 93 } 94 95 98 public static Indexer getIndexer(String luceneConfig) throws Exception { 99 IndexConfiguration ie = new IndexConfiguration(luceneConfig); 100 Indexer indexer = (Indexer) ie.getIndexerClass().newInstance(); 101 DOMUtil du = new DOMUtil(); 102 Document config = DocumentHelper.readDocument(new File (luceneConfig)); 103 indexer.configure(du.getElement(config.getDocumentElement(), new XPath("indexer")), luceneConfig); 104 105 return indexer; 106 } 107 } 108 | Popular Tags |