private static void indexFile ( IndexWriter writer , File f ) throws IOException { if ( f . isHidden ( ) || ! f . exists ( ) || ! f . canRead ( ) ) { System . err . println ( "Could not write " + f . getName ( ) ) ; return ; } System . err . println ( "Indexing " + f . getCanonicalPath ( ) ) ; Document doc = new Document ( ) ; doc . add ( new Field ( "path" , f . getCanonicalPath ( ) , Field . Store . YES , Field . Index . NOT_ANALYZED ) ) ; doc . add ( new Field ( "modified" , DateTools . timeToString ( f . lastModified ( ) , DateTools . Resolution . MINUTE ) , Field . Store . YES , Field . Index . NOT_ANALYZED ) ) ; doc . add ( new Field ( "contents" , new FileReader ( f ) ) ) ; writer . addDocument ( doc ) ; }
method to actually index a file using Lucene adds a document onto the index writer