lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r808190 - /lucene/java/trunk/src/demo/org/apache/lucene/demo/IndexHTML.java
Date Wed, 26 Aug 2009 21:28:15 GMT
Author: markrmiller
Date: Wed Aug 26 21:28:13 2009
New Revision: 808190

URL: http://svn.apache.org/viewvc?rev=808190&view=rev
Log:
improve to 1. show stacktrace on error, 2. alert user when they don't pass the path to index
rather than cryptic nullpointerexception

Modified:
    lucene/java/trunk/src/demo/org/apache/lucene/demo/IndexHTML.java

Modified: lucene/java/trunk/src/demo/org/apache/lucene/demo/IndexHTML.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/demo/org/apache/lucene/demo/IndexHTML.java?rev=808190&r1=808189&r2=808190&view=diff
==============================================================================
--- lucene/java/trunk/src/demo/org/apache/lucene/demo/IndexHTML.java (original)
+++ lucene/java/trunk/src/demo/org/apache/lucene/demo/IndexHTML.java Wed Aug 26 21:28:13 2009
@@ -42,7 +42,7 @@
   /** Indexer for HTML files.*/
   public static void main(String[] argv) {
     try {
-      String index = "index";
+      File index = new File("index");
       boolean create = false;
       File root = null;
 
@@ -55,7 +55,7 @@
 
       for (int i = 0; i < argv.length; i++) {
         if (argv[i].equals("-index")) {		  // parse -index option
-          index = argv[++i];
+          index = new File(argv[++i]);
         } else if (argv[i].equals("-create")) {	  // parse -create option
           create = true;
         } else if (i != argv.length-1) {
@@ -64,6 +64,12 @@
         } else
           root = new File(argv[i]);
       }
+      
+      if(root == null) {
+        System.err.println("Specify directory to index");
+        System.err.println("Usage: " + usage);
+        return;
+      }
 
       Date start = new Date();
 
@@ -71,7 +77,7 @@
         deleting = true;
         indexDocs(root, index, create);
       }
-      writer = new IndexWriter(FSDirectory.open(new File(index)), new StandardAnalyzer(Version.LUCENE_CURRENT),
create, 
+      writer = new IndexWriter(FSDirectory.open(index), new StandardAnalyzer(Version.LUCENE_CURRENT),
create, 
                                new IndexWriter.MaxFieldLength(1000000));
       indexDocs(root, index, create);		  // add new docs
 
@@ -85,8 +91,7 @@
       System.out.println(" total milliseconds");
 
     } catch (Exception e) {
-      System.out.println(" caught a " + e.getClass() +
-          "\n with message: " + e.getMessage());
+      e.printStackTrace();
     }
   }
 
@@ -96,11 +101,11 @@
   /* documents, to be indexed.
    */
 
-  private static void indexDocs(File file, String index, boolean create)
+  private static void indexDocs(File file, File index, boolean create)
        throws Exception {
     if (!create) {				  // incrementally update
 
-      reader = IndexReader.open(FSDirectory.open(new File(index)), false);		  // open existing
index
+      reader = IndexReader.open(FSDirectory.open(index), false);		  // open existing index
       uidIter = reader.terms(new Term("uid", "")); // init uid iterator
 
       indexDocs(file);



Mime
View raw message