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(); }
protected void setGroups( Collection<String> groups, String groupField, String groupFieldValue, String groupListField ) throws IOException, CorruptIndexException { final IndexWriter w = getIndexWriter(); w.updateDocument( new Term( groupField, groupFieldValue ), createGroupsDocument( groups, groupField, groupFieldValue, groupListField ) ); }
public synchronized void purge() throws IOException { closeReaders(); deleteIndexFiles( true ); openAndWarmup(); try { prepareIndex( true ); } catch ( ExistingLuceneIndexMismatchException e ) { // just deleted it } rebuildGroups(); updateTimestamp( true, null ); }
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(); }
public synchronized void merge( Directory directory, DocumentFilter filter ) throws IOException final IndexSearcher s = acquireIndexSearcher(); try final IndexWriter w = getIndexWriter(); final IndexReader directoryReader = DirectoryReader.open( directory ); TopScoreDocCollector collector = null; commit(); rebuildGroups(); Date mergedTimestamp = IndexUtils.getTimestamp( directory ); if ( getTimestamp() != null && mergedTimestamp != null && mergedTimestamp.after( getTimestamp() ) ) updateTimestamp( true, mergedTimestamp ); updateTimestamp( true ); optimize(); releaseIndexSearcher( s );
private void prepareCleanIndex( boolean deleteExisting ) throws IOException { if ( deleteExisting ) { closeReaders(); // unlock the dir forcibly if ( IndexWriter.isLocked( indexDirectory ) ) { unlockForcibly( lockFactory, indexDirectory ); } deleteIndexFiles( true ); } openAndWarmup(); if ( StringUtils.isEmpty( getRepositoryId() ) ) { throw new IllegalArgumentException( "The repositoryId cannot be null when creating new repository!" ); } storeDescriptor(); }
public synchronized void rebuildGroups() throws IOException final IndexSearcher is = acquireIndexSearcher(); try setRootGroups( rootGroups ); setAllGroups( allGroups ); optimize(); releaseIndexSearcher( is );
storeDescriptor(); return; if ( getSize() > 0 ) final IndexSearcher indexSearcher = acquireIndexSearcher(); try storeDescriptor(); return; if ( getRepositoryId() == null ) else if ( !getRepositoryId().equals( repoId ) ) + "[" + repoId + "] and not for repository [" + getRepositoryId() + "]" ); releaseIndexSearcher( indexSearcher );
public IndexingContext addIndexingContextForced( String id, String repositoryId, File repository, Directory directory, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexers ) throws IOException { IndexingContext context = new DefaultIndexingContext( id, repositoryId, repository, directory, repositoryUrl, indexUpdateUrl, IndexCreatorSorter.sort( indexers ), true ); indexingContexts.put( context.getId(), context ); return context; }
public synchronized void close( boolean deleteFiles ) throws IOException { if ( indexDirectory != null ) { IndexUtils.updateTimestamp( indexDirectory, getTimestamp() ); closeReaders(); if ( deleteFiles ) { deleteIndexFiles( true ); } indexDirectory.close(); } indexDirectory = null; }
protected void openAndWarmup() throws IOException { // IndexWriter (close) if ( indexWriter != null ) { indexWriter.close(); indexWriter = null; } if ( searcherManager != null ) { searcherManager.close(); searcherManager = null; } this.indexWriter = new NexusIndexWriter( getIndexDirectory(), getWriterConfig() ); this.indexWriter.commit(); // LUCENE-2386 this.searcherManager = new SearcherManager( indexWriter, false, new NexusIndexSearcherFactory( this ) ); }
unlockForcibly( lockFactory, indexDirectory ); openAndWarmup(); checkAndUpdateIndexDescriptor( reclaimIndex ); prepareCleanIndex( true ); prepareCleanIndex( false );
public int getSize() throws IOException { final IndexSearcher is = acquireIndexSearcher(); try { return is.getIndexReader().numDocs(); } finally { releaseIndexSearcher( is ); } }
DirSupport.mkdir(location.toPath()); final DefaultIndexingContext temporary = new DefaultIndexingContext(indexId, // runnable.run(temporary); temporary.updateTimestamp(true); temporary.close(false); DirSupport.deleteIfExists(location.toPath());
public void updateTimestamp() throws IOException { updateTimestamp( false ); }
openAndWarmup(); checkAndUpdateIndexDescriptor( reclaimIndex ); prepareCleanIndex( true ); prepareCleanIndex( false );
public synchronized void optimize() throws CorruptIndexException, IOException { getIndexWriter().forceMerge(1); commit(); }
@Override public void run(IndexingContext target) throws IOException { // TODO igorf guard against concurrent configuration changes // it is possible that Repository and/or target IndexingContext configuration have changed // and temporary context is populated based contains old/stale configuration // need to detect when this happens based on target timestamp for example and skip replace if (target != null) { target.replace(temporary.getIndexDirectory()); } else { log.warn("Could not perform index operation on repository {}", repository.getId(), new Exception()); } } });
@Override public void optimize() throws IOException { super.optimize(); // NEXUS-6156: Make SearcherManager be notified about this // This will release the deleted files removed after. SearcherManager is not reachable (private, no getter) // so this is the only way to make superclass invoke SearcherManager#maybeRefresh() releaseIndexSearcher(acquireIndexSearcher()); }