How to update the index in Lucene
<p>I am using Apache Lucene and my Database is approx 3 GB. </p>

<p>While I create index using Lucene first time it will take approx 25 min. But i want my application like it will update every time when am using it. </p>

<p>So how can I do these thing so my index can update every time and while updating it will take less time? </p>

<p>Database changes are very less but new entry of database should be indexed. </p>

<pre><code>Directory directory = new SimpleFSDirectory(INDEX_DIRECTORY);
        //Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
         SimpleAnalyzer analyzer = new SimpleAnalyzer(Version.LUCENE_36);  
           IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_36, analyzer);
           indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
           IndexWriter iWriter = new IndexWriter(FSDirectory.open(indexDirNEW), indexWriterConfig);
        IndexWriter iWriter = new IndexWriter(directory, analyzer, true,MaxFieldLength.UNLIMITED);



        int count = 0;
        while(rs.next()) {
            Document doc = new Document();
            doc.add(new Field("NAME", rs.getString("NAME")==null?"":rs.getString("NAME"), Field.Store.YES, Field.Index.ANALYZED ));
            doc.add(new Field("CUSTOMER", rs.getString("CUSTOMER")==null?"":rs.getString("CUSTOMER"), Field.Store.YES, Field.Index.ANALYZED ));
            iWriter.addDocument(doc);
            count++;
        }

        System.out.println(count+" record indexed");
        iWriter.optimize(); 
        iWriter.commit();
        iWriter.close();
</code></pre>