public List<ArtifactDTO> searchGrouped(Query query, GAGrouping grouping) throws IOException { List<ArtifactDTO> answer = new ArrayList<ArtifactDTO>(); GroupedSearchResponse response = indexer.searchGrouped(new GroupedSearchRequest(query, grouping, mergedContext)); int index = 0; for (Map.Entry<String, ArtifactInfoGroup> entry : response.getResults().entrySet()) { ArtifactInfo ai = entry.getValue().getArtifactInfos().iterator().next(); ArtifactDTO dto = createArtifactDTO(ai); answer.add(dto); if (++index > SEARCH_LIMIT) { break; } } return answer; }
public void searchGroupedAndDump( Indexer nexusIndexer, String descr, Query q, Grouping g ) throws IOException { System.out.println( "Searching for " + descr ); GroupedSearchResponse response = nexusIndexer.searchGrouped( new GroupedSearchRequest( q, g, centralContext ) ); for ( Map.Entry<String, ArtifactInfoGroup> entry : response.getResults().entrySet() ) { ArtifactInfo ai = entry.getValue().getArtifactInfos().iterator().next(); System.out.println( "* Entry " + ai ); System.out.println( " Latest version: " + ai.getVersion() ); System.out.println( StringUtils.isBlank( ai.getDescription() ) ? "No description in plugin's POM." : StringUtils.abbreviate( ai.getDescription(), MAX_WIDTH ) ); System.out.println(); } System.out.println( "------" ); System.out.println( "Total record hits: " + response.getTotalHitsCount() ); System.out.println(); } }