Package org.sonatype.nexus.index.context

Examples of org.sonatype.nexus.index.context.IndexingContext


       
        BooleanQuery q = new BooleanQuery();       
        q.add( indexer.constructQuery( ArtifactInfo.GROUP_ID, "org.apache.archiva" ), Occur.SHOULD );
        q.add( indexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "archiva-index-methods-jar-test" ), Occur.SHOULD );
       
        IndexingContext context = indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), new File( repositoryConfig.getLocation() ),
                                    new File( repositoryConfig.getLocation(), ".indexer" ), null, null, NexusIndexer.FULL_INDEX );
        context.setSearchable( true );
       
        FlatSearchRequest request = new FlatSearchRequest( q );
        FlatSearchResponse response = indexer.searchFlat( request );
       
        assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
View Full Code Here


            else
            {
                indexDirectory = new File( managedRepository, ".indexer" );
            }
           
            IndexingContext context = null;
            try
            {
                context =
                    new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository,
                                            indexDirectory, null, null, NexusIndexer.FULL_INDEX, false );
                context.setSearchable( repository.isScanned() );
               
                File artifactFile = indexingTask.getResourceFile();               
                ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );
               
                if( ac != null )
                {  
                    if( indexingTask.getAction().equals( ArtifactIndexingTask.ADD ) )
                    {
                        boolean add = true;
                        IndexReader r = context.getIndexReader();     
                        for ( int i = 0; i < r.numDocs(); i++ )
                        {
                            if ( !r.isDeleted( i ) )
                            {
                                Document d = r.document( i );         
                                String uinfo = d.get( ArtifactInfo.UINFO );                               
                                if( ac.getArtifactInfo().getUinfo().equals( uinfo ) )
                                {
                                    add = false;
                                    break;
                                }
                            }
                        }
                       
                        if( add )
                        {  
                            log.debug( "Adding artifact '" + ac.getArtifactInfo() + "' to index.." );
                            indexerEngine.index( context, ac );
                        }
                        else
                        {
                            log.debug( "Updating artifact '" + ac.getArtifactInfo() + "' in index.." );
                            indexerEngine.update( context, ac );
                        }
                    }
                    else
                    {                          
                        log.debug( "removing artifact '" + ac.getArtifactInfo() + "' from index.." );
                        indexerEngine.remove( context, ac );
                    }
                   
                    final File indexLocation = new File( managedRepository, ".index" );
                    IndexPackingRequest request = new IndexPackingRequest( context, indexLocation );
                    indexPacker.packIndex( request );
                }               
            }
            catch ( IOException e )
            {
                throw new TaskExecutionException( "Error occurred while executing indexing task '" +
                    indexingTask.getName() + "'" );
            }
            catch ( UnsupportedExistingLuceneIndexException e )
            {
                throw new TaskExecutionException( "Unsupported Lucene index format: " + e.getMessage() );
            }
            finally
            {
                if( context != null )
                {
                    try
                    {
                        context.close( false );
                    }
                    catch ( IOException e )
                    {
                        throw new TaskExecutionException( "Error occurred while closing context: " + e.getMessage() );
                    }
View Full Code Here

                    else
                    {
                        indexDirectory = new File( repoConfig.getLocation(), ".indexer" );
                    }
                   
                    IndexingContext context =
                        indexer.addIndexingContext( repoConfig.getId(), repoConfig.getId(), new File( repoConfig.getLocation() ),
                                                    indexDirectory, null, null, NexusIndexer.FULL_INDEX );
                    context.setSearchable( repoConfig.isScanned() );
                }
                else
                {
                    log.warn( "Repository '" + repo + "' not found in configuration." );
                }
View Full Code Here

        else
        {
            indexDirectory = new File( managedRepository, ".indexer" );
        }

        IndexingContext context =
            new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
                                        null, null, NexusIndexer.FULL_INDEX, false );
        context.setSearchable( repository.isScanned() );
        return context;
    }
View Full Code Here

        BooleanQuery q = new BooleanQuery();
        q.add( indexer.constructQuery( ArtifactInfo.GROUP_ID, "org.apache.archiva" ), Occur.SHOULD );
        q.add( indexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "archiva-index-methods-jar-test" ), Occur.SHOULD );

        IndexingContext context =
            indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
                                        new File( repositoryConfig.getLocation() ),
                                        new File( repositoryConfig.getLocation(), ".indexer" ), null, null,
                                        NexusIndexer.FULL_INDEX );
        context.setSearchable( true );

        FlatSearchRequest request = new FlatSearchRequest( q );
        FlatSearchResponse response = indexer.searchFlat( request );

        assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
        assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
        assertEquals( 1, response.getTotalHits() );

        Set<ArtifactInfo> results = response.getResults();

        ArtifactInfo artifactInfo = (ArtifactInfo) results.iterator().next();
        assertEquals( "org.apache.archiva", artifactInfo.groupId );
        assertEquals( "archiva-index-methods-jar-test", artifactInfo.artifactId );
        assertEquals( "test-repo", artifactInfo.repository );

        context.close( true );
    }
View Full Code Here

        synchronized ( indexerEngine )
        {
            ArtifactIndexingTask indexingTask = (ArtifactIndexingTask) task;

            ManagedRepositoryConfiguration repository = indexingTask.getRepository();
            IndexingContext context = indexingTask.getContext();

            if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction() ) )
            {
                try
                {
                    context.optimize();

                    File managedRepository = new File( repository.getLocation() );
                    final File indexLocation = new File( managedRepository, ".index" );
                    IndexPackingRequest request = new IndexPackingRequest( context, indexLocation );
                    indexPacker.packIndex( request );

                    log.debug( "Index file packaged at '" + indexLocation.getPath() + "'." );
                }
                catch ( IOException e )
                {
                    log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage() );
                    throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask
                        + "'", e );
                }
                finally
                {
                    if ( context != null )
                    {
                        try
                        {
                            context.close( false );
                        }
                        catch ( IOException e )
                        {
                            log.error( "Error occurred while closing context: " + e.getMessage() );
                            throw new TaskExecutionException( "Error occurred while closing context: " + e.getMessage() );
                        }
                    }
                }
            }
            else
            {
                if ( context.getIndexDirectory() == null )
                {
                    throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" );
                }
               
                try
                {
                    File artifactFile = indexingTask.getResourceFile();
                    ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );

                    if ( ac != null )
                    {
                        if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
                        {
                            boolean add = true;
                            IndexReader r = context.getIndexReader();
                            for ( int i = 0; i < r.numDocs(); i++ )
                            {
                                if ( !r.isDeleted( i ) )
                                {
                                    Document d = r.document( i );
                                    String uinfo = d.get( ArtifactInfo.UINFO );
                                    if ( ac.getArtifactInfo().getUinfo().equals( uinfo ) )
                                    {
                                        add = false;
                                        break;
                                    }
                                }
                            }

                            if ( add )
                            {
                                log.debug( "Adding artifact '" + ac.getArtifactInfo() + "' to index.." );
                                indexerEngine.index( context, ac );
                                context.getIndexWriter().commit();
                            }
                            else
                            {
                                log.debug( "Updating artifact '" + ac.getArtifactInfo() + "' in index.." );
                                indexerEngine.update( context, ac );
                                context.getIndexWriter().commit();
                            }
                        }
                        else
                        {
                            log.debug( "Removing artifact '" + ac.getArtifactInfo() + "' from index.." );
                            indexerEngine.remove( context, ac );
                            context.getIndexWriter().commit();
                        }
                    }
                }
                catch ( IOException e )
                {
View Full Code Here

        BooleanQuery q = new BooleanQuery();
        q.add( indexer.constructQuery( ArtifactInfo.GROUP_ID, "org.apache.archiva" ), Occur.SHOULD );
        q.add( indexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "archiva-index-methods-jar-test" ), Occur.SHOULD );

        IndexingContext context =
            indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
                                        new File( repositoryConfig.getLocation() ), destDir, null, null,
                                        NexusIndexer.FULL_INDEX );
        context.setSearchable( true );

        FlatSearchRequest request = new FlatSearchRequest( q );
        FlatSearchResponse response = indexer.searchFlat( request );

        assertEquals( 1, response.getTotalHits() );

        Set<ArtifactInfo> results = response.getResults();

        ArtifactInfo artifactInfo = (ArtifactInfo) results.iterator().next();
        assertEquals( "org.apache.archiva", artifactInfo.groupId );
        assertEquals( "archiva-index-methods-jar-test", artifactInfo.artifactId );
        assertEquals( "test-repo", artifactInfo.repository );

        context.close( true );
    }
View Full Code Here

            throw new ConsumerException( "Can't run index cleanup consumer: " + e.getMessage() );
        }

        ManagedRepositoryConfiguration repository = repoContent.getRepository();

        IndexingContext context = null;
        try
        {
            File artifactFile = new File( repoContent.getRepoRoot(), repoContent.toPath( artifact ) );

            if ( !artifactFile.exists() )
View Full Code Here

            else
            {
                indexDirectory = new File( managedRepository, ".indexer" );
            }
           
            IndexingContext context = null;
            try
            {
                context =
                    new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository,
                                            indexDirectory, null, null, NexusIndexer.FULL_INDEX, false );
                context.setSearchable( repository.isScanned() );
               
                File artifactFile = indexingTask.getResourceFile();               
                ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );
               
                if( ac != null )
                {  
                    if( indexingTask.getAction().equals( ArtifactIndexingTask.ADD ) )
                    {
                        boolean add = true;
                        IndexReader r = context.getIndexReader();     
                        for ( int i = 0; i < r.numDocs(); i++ )
                        {
                            if ( !r.isDeleted( i ) )
                            {
                                Document d = r.document( i );         
                                String uinfo = d.get( ArtifactInfo.UINFO );                               
                                if( ac.getArtifactInfo().getUinfo().equals( uinfo ) )
                                {
                                    add = false;
                                    break;
                                }
                            }
                        }
                       
                        if( add )
                        {  
                            log.debug( "Adding artifact '" + ac.getArtifactInfo() + "' to index.." );
                            indexerEngine.index( context, ac );
                            context.optimize();
                        }
                        else
                        {
                            log.debug( "Updating artifact '" + ac.getArtifactInfo() + "' in index.." );
                            indexerEngine.update( context, ac );
                            context.optimize();
                        }
                    }
                    else
                    {                          
                        log.debug( "Removing artifact '" + ac.getArtifactInfo() + "' from index.." );
                        indexerEngine.remove( context, ac );
                        context.optimize();
                    }
                   
                    final File indexLocation = new File( managedRepository, ".index" );
                    IndexPackingRequest request = new IndexPackingRequest( context, indexLocation );
                    indexPacker.packIndex( request );
                   
                    log.debug( "Index file packaged at '" + indexLocation.getPath() + "'." );
                }               
            }
            catch ( IOException e )
            {
                log.error( "Error occurred while executing indexing task '" + indexingTask.getName() + "'" );               
                throw new TaskExecutionException( "Error occurred while executing indexing task '" +
                    indexingTask.getName() + "'" );
            }
            catch ( UnsupportedExistingLuceneIndexException e )
            {
                log.error( "Unsupported Lucene index format: " + e.getMessage() );
                throw new TaskExecutionException( "Unsupported Lucene index format: " + e.getMessage() );
            }
            finally
            {
                if( context != null )
                {
                    try
                    {  
                        context.close( false );
                    }
                    catch ( IOException e )
                    {
                        log.error( "Error occurred while closing context: " + e.getMessage() );
                        throw new TaskExecutionException( "Error occurred while closing context: " + e.getMessage() );
View Full Code Here

       
        BooleanQuery q = new BooleanQuery();       
        q.add( indexer.constructQuery( ArtifactInfo.GROUP_ID, "org.apache.archiva" ), Occur.SHOULD );
        q.add( indexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "archiva-index-methods-jar-test" ), Occur.SHOULD );
       
        IndexingContext context = indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), new File( repositoryConfig.getLocation() ),
                                    new File( repositoryConfig.getLocation(), ".indexer" ), null, null, NexusIndexer.FULL_INDEX );
        context.setSearchable( true );
       
        FlatSearchRequest request = new FlatSearchRequest( q );
        FlatSearchResponse response = indexer.searchFlat( request );
       
        assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.index.context.IndexingContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.