> > indexWriter = new IndexWriter(FSDirectory.open(new File(indexDirName)), > getAnalyzer(), true, MaxFieldLength.UNLIMITED); > > Does this statement cleans up existing index files?
yes > If yes, then how do I > tackle a scenario where lets say I brought down my application server > hosting code to create lucene index and then start it again, this way a new > JVM will start creating indexWriter instance again which will eventually > clean up my existing index files. > indexWriter = new IndexWriter(FSDirectory.open(new File(indexDirName)), getAnalyzer(), *false*, MaxFieldLength.UNLIMITED); Note: To avoid using deprecated method use the equivalent code: Directory idx = new NIOFSDirectory(new File(indexDirName), null); IndexWriterConfig iConfig = new IndexWriterConfig(Version.LUCENE_31,getAnalyzer()); iConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); indexWriter = new IndexWriter(idx, iConfig);