public static void updateTimestamp( Directory directory, Date timestamp ) throws IOException { synchronized ( directory ) { Date currentTimestamp = getTimestamp( directory ); if ( timestamp != null && ( currentTimestamp == null || !currentTimestamp.equals( timestamp ) ) ) { deleteTimestamp( directory ); IndexOutput io = directory.createOutput( TIMESTAMP_FILE, IOContext.DEFAULT ); try { io.writeLong( timestamp.getTime() ); } finally { close( io ); } } } }
public static void copyDirectory( Directory source, Directory target ) throws IOException { //FIXME: check if this copies too much, Lucene 4 has no filter for lucene files //Directory.copy( source, target, false ); for ( String file : source.listAll() ) { target.copyFrom( source, file, file, IOContext.DEFAULT ); } copyFile( source, target, IndexingContext.INDEX_UPDATER_PROPERTIES_FILE ); copyFile( source, target, IndexingContext.INDEX_PACKER_PROPERTIES_FILE ); Date ts = getTimestamp( source ); updateTimestamp( target, ts ); }
public static Document updateDocument( Document doc, IndexingContext context, boolean updateLastModified ) { return updateDocument( doc, context, updateLastModified, null ); }
public static Document updateDocument( Document doc, IndexingContext context, boolean updateLastModified ) { ArtifactInfo ai = constructArtifactInfo( doc, context ); if ( ai == null ) { return doc; } Document document = new Document(); // unique key document.add( new Field( ArtifactInfo.UINFO, ai.getUinfo(), Field.Store.YES, Field.Index.NOT_ANALYZED ) ); if ( updateLastModified || doc.getField( ArtifactInfo.LAST_MODIFIED ) == null ) { document.add( new Field( ArtifactInfo.LAST_MODIFIED, // Long.toString( System.currentTimeMillis() ), Field.Store.YES, Field.Index.NO ) ); } else { document.add( doc.getField( ArtifactInfo.LAST_MODIFIED ) ); } for ( IndexCreator ic : context.getIndexCreators() ) { ic.updateDocument( ai, document ); } return document; }
IndexUtils.updateTimestamp( w.getDirectory(), date ); ArtifactInfo ai = IndexUtils.constructArtifactInfo( doc, context ); if ( ai != null ) w.addDocument( IndexUtils.updateDocument( doc, context, false, ai ) );
public synchronized void replace( Directory directory ) throws IOException { final Date ts = IndexUtils.getTimestamp( directory ); closeReaders(); deleteIndexFiles( false ); IndexUtils.copyDirectory( directory, indexDirectory ); openAndWarmup(); // reclaim the index as mine storeDescriptor(); rebuildGroups(); updateTimestamp( true, ts ); optimize(); }
if ( collector.getTotalHits() == 0 ) w.addDocument( IndexUtils.updateDocument( d, this, false ) ); Date mergedTimestamp = IndexUtils.getTimestamp( directory );
if ( update ) IndexUtils.copyDirectory( context.getIndexDirectory(), directory );
public static Date getTimestamp( Directory directory ) { synchronized ( directory ) { Date result = null; try { if ( directory.fileExists( TIMESTAMP_FILE ) ) { IndexInput ii = null; try { ii = directory.openInput( TIMESTAMP_FILE, IOContext.DEFAULT); result = new Date( ii.readLong() ); } finally { close( ii ); } } } catch ( IOException ex ) { } return result; } }
public IndexDataReadResult readIndex( IndexWriter w, IndexingContext context ) throws IOException { long timestamp = readHeader(); Date date = null; if ( timestamp != -1 ) { date = new Date( timestamp ); IndexUtils.updateTimestamp( w.getDirectory(), date ); } int n = 0; Document doc; while ( ( doc = readDocument() ) != null ) { w.addDocument( IndexUtils.updateDocument( doc, context, false ) ); n++; } w.commit(); w.forceMerge(1); w.commit(); IndexDataReadResult result = new IndexDataReadResult(); result.setDocumentCount( n ); result.setTimestamp( date ); return result; }
public void updateTimestamp( boolean save, Date timestamp ) throws IOException { this.timestamp = timestamp; if ( save ) { IndexUtils.updateTimestamp( indexDirectory, getTimestamp() ); } }
public static boolean copyFile( Directory source, Directory target, String name ) throws IOException { return copyFile( source, target, name, name ); }
IndexUtils.deleteTimestamp( indexDirectory );
timestamp = IndexUtils.getTimestamp( indexDirectory );
public static Document updateDocument( Document doc, IndexingContext context, boolean updateLastModified, ArtifactInfo ai ) { if ( ai == null ) { ai = constructArtifactInfo( doc, context ); if ( ai == null ) { return doc; } } Document document = new Document(); // unique key document.add( new Field( ArtifactInfo.UINFO, ai.getUinfo(), Field.Store.YES, Field.Index.NOT_ANALYZED ) ); if ( updateLastModified || doc.getField( ArtifactInfo.LAST_MODIFIED ) == null ) { document.add( new Field( ArtifactInfo.LAST_MODIFIED, // Long.toString( System.currentTimeMillis() ), Field.Store.YES, Field.Index.NO ) ); } else { document.add( doc.getField( ArtifactInfo.LAST_MODIFIED ) ); } for ( IndexCreator ic : context.getIndexCreators() ) { ic.updateDocument( ai, document ); } return document; }
IndexUtils.updateTimestamp( w.getDirectory(), date ); ArtifactInfo ai = IndexUtils.constructArtifactInfo( doc, context ); if ( ai != null ) w.addDocument( IndexUtils.updateDocument( doc, context, false, ai ) );
public synchronized void replace( Directory directory, Set<String> allGroups, Set<String> rootGroups ) throws IOException { final Date ts = IndexUtils.getTimestamp( directory ); closeReaders(); deleteIndexFiles( false ); IndexUtils.copyDirectory( directory, indexDirectory ); openAndWarmup(); // reclaim the index as mine storeDescriptor(); if ( allGroups == null && rootGroups == null ) { rebuildGroups(); } else { if ( allGroups != null ) { setAllGroups( allGroups ); } if ( rootGroups != null ) { setRootGroups( rootGroups ); } } updateTimestamp( true, ts ); optimize(); }
if ( collector.getTotalHits() == 0 ) w.addDocument( IndexUtils.updateDocument( d, this, false ) ); Date mergedTimestamp = IndexUtils.getTimestamp( directory );
if ( update ) IndexUtils.copyDirectory( context.getIndexDirectory(), directory );