public static void main1 ( String [ ] args ) { if ( INDEX_DIR . exists ( ) ) { System . out . println ( "Cannot save index to '" + INDEX_DIR + "' directory, please delete it first" ) ; System . exit ( 1 ) ; } LuceneIndexer indexer = new LuceneIndexer ( ) ; Date start = new Date ( ) ; try { IndexWriter writer = new IndexWriter ( INDEX_DIR , new StandardAnalyzer ( ) , true ) ; System . out . println ( "Indexing to directory '" + INDEX_DIR + "'..." ) ; indexer . indexDocs ( writer , DOC_DIR ) ; System . out . println ( "Optimizing..." ) ; writer . optimize ( ) ; writer . close ( ) ; Date end = new Date ( ) ; System . out . println ( end . getTime ( ) - start . getTime ( ) + " total milliseconds" ) ; } catch ( IOException e ) { System . out . println ( " caught a " + e . getClass ( ) + "\n with message: " + e . getMessage ( ) ) ; } }
Index all text files under a directory .