lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mihai Caraman <caraman.mi...@gmail.com>
Subject Re: Questions on index Writer
Date Sat, 16 Jul 2011 20:08:06 GMT
>
> 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);

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message