/** * Creates a new {@link IndexSearcher} * * @return a new {@link IndexSearcher} * @throws IOException */ public IndexSearcher newIndexSearcher() throws IOException { return indexingContext.acquireIndexSearcher(); }
private synchronized boolean isClosed() { // It is theoretically possible to "reopen" closed indexing context by context.replace(Directory) // To guarantee balance of acquireIndexSearcher/releaseIndexSearcher calls, closed context must stay close if (!closed) { closed = context.getIndexDirectory() == null; } return closed; }
throws IOException final File repositoryDirectory = context.getRepository(); if ( repositoryDirectory == null ) final File tmpFile = File.createTempFile( context.getId() + "-tmp", "" ); final File tmpDir = new File( tmpFile.getParentFile(), tmpFile.getName() + ".dir" ); if ( !tmpDir.mkdirs() ) if ( update ) IndexUtils.copyDirectory( context.getIndexDirectory(), directory ); tmpContext = new DefaultIndexingContext( context.getId() + "-tmp", // context.getRepositoryId(), // context.getRepository(), // context.getRepositoryUrl(), // context.getIndexUpdateUrl(), // context.getIndexCreators(), // true ); tmpContext.updateTimestamp( true ); context.replace( tmpContext.getIndexDirectory() ); throw new IOException("Error scanning context " + context.getId() + ": " + ex, ex); tmpContext.close( true );
@Override public void artifactDiscovered( final ArtifactContext ac ) { try { LOGGER.debug( "Adding artifact gav: {}; ctx id: {}; idx dir: {}", new String[]{ ac.getGav().toString(), context.getId(), context.getIndexDirectory().toString() } ); getIndexer().addArtifactsToIndex( asList( ac ), context ); totalFiles++; } catch ( IOException ex ) { LOGGER.error( "Artifact index error", ex ); } } }
List<IndexingContext> memberContexts = new ArrayList<IndexingContext>(); for (IndexingContext context : lockedContexts.contexts.values()) { if (context != null && !repository.getId().equals(context.getRepositoryId())) { memberContexts.add(context); lockedContext = new MergedIndexingContext(groupContext.getId(), // groupContext.getRepositoryId(), // groupContext.getRepository(), // groupContext.getIndexDirectory(), // groupContext.isSearchable(), // new StaticContextMemberProvider(memberContexts))
context.optimize(); context.setRootGroups( groups ); context.setAllGroups( allGroups ); if ( update && !context.isReceivingUpdates() ) context.updateTimestamp( true ); context.optimize();
context.optimize( ); log.debug( "Creating packed index from {} on {}", context.getIndexDirectoryFile( ), icf.getLocalPackedIndexPath( ) ); IndexPackingRequest request = new IndexPackingRequest( context, // context.acquireIndexSearcher( ).getIndexReader( ), context.updateTimestamp( true );
private Document getOldDocument( IndexingContext context, ArtifactContext ac ) { try { final IndexSearcher indexSearcher = context.acquireIndexSearcher(); try { TopDocs result = indexSearcher.search( new TermQuery( new Term( ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo() ) ), 2 ); if ( result.totalHits == 1 ) { return indexSearcher.doc( result.scoreDocs[0].doc ); } } finally { context.releaseIndexSearcher( indexSearcher ); } } catch ( IOException e ) { // huh? throw new IllegalStateException( e ); } return null; }
fetcher.connect( context.getId(), context.getIndexUpdateUrl() );
context.rebuildGroups(); context.commit(); context.updateTimestamp(true); context.optimize(); context.getRepositoryId(), discovered, added, updated, removed, DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - scanningStarted) );
@Override public void pack( final ArchivaIndexingContext context ) throws IndexUpdateFailedException { executeUpdateFunction( context, indexingContext -> { try { IndexPackingRequest request = new IndexPackingRequest( indexingContext, indexingContext.acquireIndexSearcher( ).getIndexReader( ), indexingContext.getIndexDirectoryFile( ) ); indexPacker.packIndex( request ); indexingContext.updateTimestamp( true ); } catch ( IOException e ) { log.error( "IOException while packing index of context " + context.getId( ) + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ) ); throw new IndexUpdateFailedException( "IOException during update of " + context.getId( ), e ); } } ); }
@Override public Date getTimestamp() { return context.getTimestamp(); }
void writeIndexProperties( IndexPackingRequest request, Properties info ) throws IOException { File propertyFile = new File( request.getContext().getIndexDirectoryFile(), IndexingContext.INDEX_PACKER_PROPERTIES_FILE ); File targetPropertyFile = new File( request.getTargetDir(), IndexingContext.INDEX_REMOTE_PROPERTIES_FILE ); info.setProperty( IndexingContext.INDEX_ID, request.getContext().getId() ); try ( OutputStream os = new FileOutputStream( propertyFile ) ) { info.store( os, null ); } try ( OutputStream os = new FileOutputStream( targetPropertyFile ) ) { info.store( os, null ); } if ( request.isCreateChecksumFiles() ) { FileUtils.fileWrite( new File( targetPropertyFile.getParentFile(), targetPropertyFile.getName() + ".sha1" ).getAbsolutePath(), DigesterUtils.getSha1Digest( targetPropertyFile ) ); FileUtils.fileWrite( new File( targetPropertyFile.getParentFile(), targetPropertyFile.getName() + ".md5" ).getAbsolutePath(), DigesterUtils.getMd5Digest( targetPropertyFile ) ); } }
@Override public File getIndexDirectoryFile() { return context.getIndexDirectoryFile(); }
final Date centralContextCurrentTimestamp = mergedContext.getTimestamp(); final IndexUpdateRequest updateRequest = new IndexUpdateRequest( mergedContext, resourceFetcher ); IndexUpdateResult updateResult = null; mergedContext.commit(); mergedContext.close( false );
IndexingContext indexingContext = this.remoteRepository.getIndexingContext().getBaseContext(IndexingContext.class); tempIndexDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex" ); Path indexCacheDirectory = Paths.get( indexingContext.getIndexDirectoryFile().getParent(), ".indexCache" ); Files.createDirectories( indexCacheDirectory ); if ( Files.exists(tempIndexDirectory) ) String baseIndexUrl = indexingContext.getIndexUpdateUrl(); proxyInfo ); Path indexDirectory = indexingContext.getIndexDirectoryFile().toPath(); if ( !Files.exists(indexDirectory) ) indexingContext.updateTimestamp( true );
TopScoreDocCollector collector = TopScoreDocCollector.create(NexusRepositoryIndexerImpl.MAX_RESULT_COUNT, true); for (IndexingContext context : contexts) { IndexSearcher searcher = context.acquireIndexSearcher(); try { searcher.search(refClassQuery, collector); ArtifactInfo ai = IndexUtils.constructArtifactInfo(d, context); if (ai != null) { ai.repository = context.getRepositoryId(); List<NBVersionInfo> version = NexusRepositoryIndexerImpl.convertToNBVersionInfo(Collections.singleton(ai)); if (!version.isEmpty()) { context.releaseIndexSearcher(searcher);
public void addArtifactToIndex( ArtifactContext ac, IndexingContext context ) throws IOException { if ( ac != null ) { indexerEngine.update( context, ac ); context.commit(); } }
private void initialize( IndexingContext ctx ) throws IOException, CorruptIndexException final IndexSearcher indexSearcher = ctx.acquireIndexSearcher(); try if ( !ctx.isReceivingUpdates() ) ctx.releaseIndexSearcher( indexSearcher );