writer.optimize();
if ( optimizeNeeded(newAdded) ) { LOG.debug("Optimize Threshold reached! Optimizing index!"); writer.optimize(); newAdded = Integer.MIN_VALUE; }
    private synchronized Entry[] storeEntries(Entry[] entries) throws IOException    {        if ( !isInitialized() )            throw new IllegalStateException("Database must be initialized before use!");        if ( entries == null )            throw new IllegalArgumentException("Parameter 'entries' is not allowed to be null");                IndexWriter writer = null;        IndexReader reader = null;        try {            if ( IndexReader.indexExists(indexDir) ) {                reader = getReader();                for (int i = 0; i < entries.length; i++ ) {                    deleteEntries(new URL[] {entries[i].getUrl()}, reader);                }                reader.close();                reader = null;            }            writer = getWriter();                        Date now = new Date();            for (int i = 0; i < entries.length; i++ ) {                LOG.debug("Adding Entry to index: "+ entries[i].getUrl().toString());                entries[i].setEdited(now);                                Document doc = entries[i].getDocument();                doc.add( Field.Keyword(URLHASH, computeHash(entries[i].getUrl())) );                writer.addDocument(doc);            }            writer.optimize(); // TODO should this be delayed in a web env?        } finally {            if ( writer != null )                writer.close();            if ( reader != null )                reader.close();        }                persistLastUpdate();        return entries;    }