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() ), 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


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

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

            if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction() )
                && indexingTask.isExecuteOnEntireRepo() )
            {
                log.debug( "Finishing indexing task on repo: " + repository.getId() );
                finishIndexingTask( indexingTask, repository, context );
            }
            else
            {
                // create context if not a repo scan request
                if( !indexingTask.isExecuteOnEntireRepo() )
                {
                    try
                    {
                        log.debug( "Creating indexing context on resource: " + indexingTask.getResourceFile().getPath() );
                        context = TaskCreator.createContext( repository );
                    }
                    catch( IOException e )
                    {
                        log.error( "Error occurred while creating context: " + e.getMessage() );
                        throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage() );
                    }
                    catch( UnsupportedExistingLuceneIndexException e )
                    {
                        log.error( "Error occurred while creating context: " + e.getMessage() );
                        throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage() );   
                    }
                }

                if ( context == null || 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 ) )
                        {
                            IndexSearcher s = context.getIndexSearcher();
                            String uinfo = ac.getArtifactInfo().getUinfo();
                            TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );
                            if ( d.totalHits == 0 )
                            {
                                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();
                            }

                            // close the context if not a repo scan request
                            if( !indexingTask.isExecuteOnEntireRepo() )
                            {
                                log.debug( "Finishing indexing task on resource file : " + indexingTask.getResourceFile().getPath() );
                                finishIndexingTask( indexingTask, repository, context );  
                            }
                        }
                        else
                        {
                            log.debug( "Removing artifact '" + ac.getArtifactInfo() + "' from index.." );
                            indexerEngine.remove( context, ac );
                            context.getIndexWriter().commit();
                        }
                    }
                }
                catch ( IOException e )
                {
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( 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

        // search!
        BooleanQuery q = new BooleanQuery();       
        q.add( nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "org.apache.archiva" ), Occur.SHOULD );
        q.add( nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "archiva-index-methods-jar-test" ), Occur.SHOULD );
       
        IndexingContext context = nexusIndexer.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 = nexusIndexer.searchFlat( request );
       
        assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
View Full Code Here

        ArchivaArtifact artifact =
            new ArchivaArtifact( "org.apache.archiva", "archiva-lucene-consumers", "1.2", null, "jar", "test-repo" );
        ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
        repoContent.setRepository( repositoryConfig );

        IndexingContext context =
            new DefaultIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
                                        new File( repositoryConfig.getLocation() ),
                                        new File( repositoryConfig.getIndexDir() ), null, null,
                                        NexusIndexer.FULL_INDEX, false );
View Full Code Here

        ArchivaArtifact artifact =
            new ArchivaArtifact( "org.apache.maven.archiva", "archiva-lucene-cleanup", "1.0", null, "jar", "test-repo" );
        ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
        repoContent.setRepository( repositoryConfig );

        IndexingContext context =
            new DefaultIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
                                        new File( repositoryConfig.getLocation() ),
                                        new File( repositoryConfig.getIndexDir() ), null, null,
                                        NexusIndexer.FULL_INDEX, false );
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.