Package org.apache.maven.index

Examples of org.apache.maven.index.IteratorSearchResponse


        Query q = indexer.constructQuery( MAVEN.GROUP_ID, "qdox", SearchType.SCORED );

        IteratorSearchRequest request = new IteratorSearchRequest( q );

        IteratorSearchResponse response = indexer.searchIterator( request );

        assertEquals( 2, response.getTotalHits() );

        for ( ArtifactInfo ai : response.getResults() )
        {
            assertEquals( "GroupId must match \"qdox\"!", "qdox", ai.groupId );
        }
    }
View Full Code Here


        filter.addField( MAVEN.GROUP_ID );
        filter.addField( MAVEN.ARTIFACT_ID );

        IteratorSearchRequest request = new IteratorSearchRequest( q, filter );

        IteratorSearchResponse response = indexer.searchIterator( request );

        assertEquals( "15 total hits (before filtering!)", 15, response.getTotalHits() );

        ArtifactInfo ai = response.getResults().next();
        assertTrue( "Iterator has to have next (2 should be returned)", ai != null );

        ai = response.getResults().next();
        assertTrue( "Iterator has to have next (2 should be returned)", ai != null );

        assertEquals( "Property that is not unique has to have \"COLLAPSED\" value!",
            UniqueArtifactFilterPostprocessor.COLLAPSED, ai.version );
        assertEquals( "Property that is not unique has to have \"COLLAPSED\" value!",
View Full Code Here

        String rootPartialGroupId = StringUtils.strip( root.getPath().replaceAll( "/", "." ), "." );

        folders.put( Type.G + ":" + rootPartialGroupId, root );

        IteratorSearchResponse artifacts = getArtifacts( root, request );

        try
        {
            for ( ArtifactInfo ai : artifacts )
            {
                String versionKey = Type.V + ":" + ai.artifactId + ":" + ai.version;

                TreeNode versionResource = folders.get( versionKey );

                if ( versionResource == null )
                {
                    String artifactKey = Type.A + ":" + ai.artifactId;

                    TreeNode artifactResource = folders.get( artifactKey );

                    if ( artifactResource == null )
                    {
                        TreeNode groupParentResource = root;

                        TreeNode groupResource = root;

                        // here comes the twist: we have to search for parent G node
                        String partialGroupId = null;

                        String[] groupIdElems = ai.groupId.split( "\\." );

                        for ( String groupIdElem : groupIdElems )
                        {
                            if ( partialGroupId == null )
                            {
                                partialGroupId = groupIdElem;
                            }
                            else
                            {
                                partialGroupId = partialGroupId + "." + groupIdElem;
                            }

                            String groupKey = Type.G + ":" + partialGroupId;

                            groupResource = folders.get( groupKey );

                            // it needs to be created only if not found (is null) and is _below_ groupParentResource
                            if ( groupResource == null
                                && groupParentResource.getPath().length() < getPathForAi( ai, MAVEN.GROUP_ID ).length() )
                            {
                                String gNodeName =
                                    partialGroupId.lastIndexOf( '.' ) > -1 ? partialGroupId.substring(
                                        partialGroupId.lastIndexOf( '.' ) + 1, partialGroupId.length() )
                                        : partialGroupId;

                                groupResource =
                                    request.getFactory().createGNode( this, request,
                                        "/" + partialGroupId.replaceAll( "\\.", "/" ) + "/", gNodeName );

                                groupParentResource.getChildren().add( groupResource );

                                folders.put( groupKey, groupResource );

                                groupParentResource = groupResource;
                            }
                            else if ( groupResource != null )
                            {
                                // we found it as already existing, break if this is the node we want
                                if ( groupResource.getPath().equals( getPathForAi( ai, MAVEN.GROUP_ID ) ) )
                                {
                                    break;
                                }

                                groupParentResource = groupResource;
                            }
                        }

                        artifactResource =
                            request.getFactory().createANode( this, request, ai, getPathForAi( ai, MAVEN.ARTIFACT_ID ) );

                        groupParentResource.getChildren().add( artifactResource );

                        folders.put( artifactKey, artifactResource );
                    }

                    versionResource =
                        request.getFactory().createVNode( this, request, ai, getPathForAi( ai, MAVEN.VERSION ) );

                    artifactResource.getChildren().add( versionResource );

                    folders.put( versionKey, versionResource );
                }

                String nodePath = getPathForAi( ai, null );

                versionResource.getChildren().add(
                    request.getFactory().createArtifactNode( this, request, ai, nodePath ) );
            }
        }
        finally
        {
            artifacts.close();
        }

        if ( !request.hasFieldHints() )
        {
            Set<String> groups = getGroups( path, allGroups );
View Full Code Here

            return getHintedArtifacts( root, request );
        }

        String path = root.getPath();

        IteratorSearchResponse result = null;

        String g = null;

        String a = null;

        String v = null;

        // "working copy" of path
        String wp = null;

        // remove last / from path
        if ( path.endsWith( "/" ) )
        {
            path = path.substring( 0, path.length() - 1 );
        }

        // 1st try, let's consider path is a group

        // reset wp
        wp = path;

        g = wp.substring( 1 ).replace( '/', '.' );

        result = getArtifactsByG( g, request );

        if ( result.getTotalHitsCount() > 0 )
        {
            return result;
        }
        else
        {
            result.close();
        }

        // 2nd try, lets consider path a group + artifactId, we must ensure there is at least one / but not as root

        if ( path.lastIndexOf( '/' ) > 0 )
        {
            // reset wp
            wp = path;

            a = wp.substring( wp.lastIndexOf( '/' ) + 1, wp.length() );

            g = wp.substring( 1, wp.lastIndexOf( '/' ) ).replace( '/', '.' );

            result = getArtifactsByGA( g, a, request );

            if ( result.getTotalHitsCount() > 0 )
            {
                return result;
            }
            else
            {
                result.close();
            }

            // 3rd try, let's consider path a group + artifactId + version. There is no 100% way to detect this!

            try
            {
                // reset wp
                wp = path;

                v = wp.substring( wp.lastIndexOf( '/' ) + 1, wp.length() );

                wp = wp.substring( 0, wp.lastIndexOf( '/' ) );

                a = wp.substring( wp.lastIndexOf( '/' ) + 1, wp.length() );

                g = wp.substring( 1, wp.lastIndexOf( '/' ) ).replace( '/', '.' );

                result = getArtifactsByGAV( g, a, v, request );

                if ( result.getTotalHitsCount() > 0 )
                {
                    return result;
                }
                else
                {
                    result.close();
                }
            }
            catch ( StringIndexOutOfBoundsException e )
            {
                // nothing
            }
        }

        // if we are here, no hits found
        return IteratorSearchResponse.empty( result.getQuery() );
    }
View Full Code Here

        IteratorSearchRequest searchRequest = new IteratorSearchRequest( q, request.getArtifactInfoFilter() );

        searchRequest.getContexts().add( request.getIndexingContext() );

        IteratorSearchResponse result = getIndexer().searchIterator( searchRequest );

        return result;
    }
View Full Code Here

        else
        {
            req = new IteratorSearchRequest( q );
        }

        IteratorSearchResponse response = indexer.searchIterator( req );

        ArrayList<ArtifactInfo> ais = new ArrayList<ArtifactInfo>( response.getTotalHits() );

        for ( ArtifactInfo ai : response )
        {
            ais.add( ai );
        }
View Full Code Here

    public void testClassnameSearchNgWithHighlighting()
        throws Exception
    {
        IteratorSearchRequest request = createHighlightedRequest( MAVEN.CLASSNAMES, "Logger", SearchType.SCORED );

        IteratorSearchResponse response = nexusIndexer.searchIterator( request );

        for ( ArtifactInfo ai : response )
        {
            // These are _all_ classnames
            String classnames = ai.classNames;

            for ( MatchHighlight mh : ai.getMatchHighlights() )
            {
                for ( String highlighted : mh.getHighlightedMatch() )
                {
                    // Logger and LoggerFactory
                    assertTrue( "Class name should be highlighted", highlighted.contains( "<B>Logger" ) );
                    assertFalse( "Class name should not contain \"/\" alone (but okay within HTML, see above!)",
                        highlighted.matches( "\\p{Lower}/\\p{Upper}" ) );
                    assertFalse( "Class name should not begin with \".\" or \"/\"", highlighted.startsWith( "." )
                        || highlighted.startsWith( "/" ) );
                }
            }
        }

        assertEquals( "found in jcl104-over-slf4j and commons-logging", 5, response.getTotalHits() );
    }
View Full Code Here

    public void testGAVSearchNgWithHighlighting()
        throws Exception
    {
        IteratorSearchRequest request = createHighlightedRequest( MAVEN.GROUP_ID, "commons", SearchType.SCORED );

        IteratorSearchResponse response = nexusIndexer.searchIterator( request );

        for ( ArtifactInfo ai : response )
        {
            for ( MatchHighlight mh : ai.getMatchHighlights() )
            {
                assertTrue(
                    "Group ID should be highlighted",
                    mh.getHighlightedMatch().contains( "<B>commons</B>-logging" )
                        || mh.getHighlightedMatch().contains( "<B>commons</B>-cli" ) );
            }
        }

        assertEquals( "found in commons-logging and commons-cli", 15, response.getTotalHits() );
    }
View Full Code Here

    IndexingContext indexingContext = data.getIndexingContext();

        Query pq = indexer.constructQuery(MAVEN.PACKAGING, "deb", SearchType.EXACT);

        IteratorSearchRequest sreq = new IteratorSearchRequest(pq, indexingContext);
        IteratorSearchResponse hits = indexer.searchIterator(sreq);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OutputStreamWriter w = new OutputStreamWriter(baos);

        for (ArtifactInfo hit : hits) {
View Full Code Here

    // RuntimeException and ThreadDeath will leave locks locked. Not sure if there is a nice way to avoid this

    try {
      req.getContexts().addAll(lockedContexts.contexts.values());

      IteratorSearchResponse result = mavenIndexer.searchIterator(req);

      Query query = result.getQuery();
      int totalHints = result.getTotalHitsCount();
      IteratorResultSet results = new LockingIteratorResultSet(result.getResults(), lockedContexts.lock);

      return new IteratorSearchResponse(query, totalHints, results);
    }
    catch (BooleanQuery.TooManyClauses e) {
      lockedContexts.lock.unlock();

      if (log.isDebugEnabled()) {
View Full Code Here

TOP

Related Classes of org.apache.maven.index.IteratorSearchResponse

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.