1 package org.apache.archiva.indexer.maven.search;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.ProxyConnector;
24 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
25 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
26 import org.apache.archiva.indexer.UnsupportedBaseContextException;
27 import org.apache.archiva.indexer.search.ArtifactInfoFilter;
28 import org.apache.archiva.indexer.search.NoClassifierArtifactInfoFilter;
29 import org.apache.archiva.indexer.search.RepositorySearch;
30 import org.apache.archiva.indexer.search.RepositorySearchException;
31 import org.apache.archiva.indexer.search.SearchFields;
32 import org.apache.archiva.indexer.search.SearchResultHit;
33 import org.apache.archiva.indexer.search.SearchResultLimits;
34 import org.apache.archiva.indexer.search.SearchResults;
35 import org.apache.archiva.indexer.util.SearchUtil;
36 import org.apache.archiva.model.ArchivaArtifactModel;
37 import org.apache.archiva.repository.RemoteRepository;
38 import org.apache.archiva.repository.Repository;
39 import org.apache.archiva.repository.RepositoryRegistry;
40 import org.apache.archiva.repository.RepositoryType;
41 import org.apache.commons.lang.StringUtils;
42 import org.apache.maven.index.ArtifactInfo;
43 import org.apache.maven.index.FlatSearchRequest;
44 import org.apache.maven.index.FlatSearchResponse;
45 import org.apache.maven.index.Indexer;
46 import org.apache.maven.index.MAVEN;
47 import org.apache.maven.index.OSGI;
48 import org.apache.maven.index.QueryCreator;
49 import org.apache.maven.index.SearchType;
50 import org.apache.maven.index.context.IndexingContext;
51 import org.apache.maven.index.expr.SearchExpression;
52 import org.apache.maven.index.expr.SearchTyped;
53 import org.apache.maven.index.expr.SourcedSearchExpression;
54 import org.apache.maven.index.expr.UserInputSearchExpression;
55 import org.apache.maven.index_shaded.lucene.search.BooleanClause;
56 import org.apache.maven.index_shaded.lucene.search.BooleanClause.Occur;
57 import org.apache.maven.index_shaded.lucene.search.BooleanQuery;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
60 import org.springframework.stereotype.Service;
62 import javax.inject.Inject;
63 import java.io.IOException;
64 import java.util.ArrayList;
65 import java.util.Collection;
66 import java.util.Collections;
67 import java.util.HashSet;
68 import java.util.List;
73 * RepositorySearch implementation which uses the Maven Indexer for searching.
75 @Service( "repositorySearch#maven" )
76 public class MavenRepositorySearch
77 implements RepositorySearch
79 private Logger log = LoggerFactory.getLogger( getClass() );
81 private Indexer indexer;
83 private QueryCreator queryCreator;
86 RepositoryRegistry repositoryRegistry;
88 private ProxyConnectorAdmin proxyConnectorAdmin;
90 protected MavenRepositorySearch()
96 public MavenRepositorySearch( Indexer nexusIndexer, RepositoryRegistry repositoryRegistry,
98 ProxyConnectorAdmin proxyConnectorAdmin, QueryCreator queryCreator )
99 throws PlexusSisuBridgeException
101 this.indexer = nexusIndexer;
102 this.queryCreator = queryCreator;
103 this.repositoryRegistry = repositoryRegistry;
104 this.proxyConnectorAdmin = proxyConnectorAdmin;
108 * @see RepositorySearch#search(String, List, String, SearchResultLimits, List)
111 public SearchResults search(String principal, List<String> selectedRepos, String term, SearchResultLimits limits,
112 List<String> previousSearchTerms )
113 throws RepositorySearchException
115 List<String> indexingContextIds = addIndexingContexts( selectedRepos );
117 // since upgrade to nexus 2.0.0, query has changed from g:[QUERIED TERM]* to g:*[QUERIED TERM]*
118 // resulting to more wildcard searches so we need to increase max clause count
119 BooleanQuery.setMaxClauseCount( Integer.MAX_VALUE );
120 BooleanQuery.Builder qb = new BooleanQuery.Builder();
122 if ( previousSearchTerms == null || previousSearchTerms.isEmpty() )
124 constructQuery( term, qb );
128 for ( String previousTerm : previousSearchTerms )
130 BooleanQuery.Builder iQuery = new BooleanQuery.Builder();
131 constructQuery( previousTerm, iQuery );
133 qb.add( iQuery.build(), BooleanClause.Occur.MUST );
136 BooleanQuery.Builder iQuery = new BooleanQuery.Builder();
137 constructQuery( term, iQuery );
138 qb.add( iQuery.build(), BooleanClause.Occur.MUST );
141 // we retun only artifacts without classifier in quick search, olamy cannot find a way to say with this field empty
142 // FIXME cannot find a way currently to setup this in constructQuery !!!
143 return search( limits, qb.build(), indexingContextIds, NoClassifierArtifactInfoFilter.LIST, selectedRepos, true );
148 * @see RepositorySearch#search(String, SearchFields, SearchResultLimits)
151 public SearchResults search( String principal, SearchFields searchFields, SearchResultLimits limits )
152 throws RepositorySearchException
154 if ( searchFields.getRepositories() == null )
156 throw new RepositorySearchException( "Repositories cannot be null." );
159 List<String> indexingContextIds = addIndexingContexts( searchFields.getRepositories() );
161 // if no index found in the specified ones return an empty search result instead of doing a search on all index
162 // olamy: IMHO doesn't make sense
163 if ( !searchFields.getRepositories().isEmpty() && ( indexingContextIds == null
164 || indexingContextIds.isEmpty() ) )
166 return new SearchResults();
169 BooleanQuery.Builder qb = new BooleanQuery.Builder();
170 if ( StringUtils.isNotBlank( searchFields.getGroupId() ) )
172 qb.add( indexer.constructQuery( MAVEN.GROUP_ID, searchFields.isExactSearch() ? new SourcedSearchExpression(
173 searchFields.getGroupId() ) : new UserInputSearchExpression( searchFields.getGroupId() ) ),
174 BooleanClause.Occur.MUST );
177 if ( StringUtils.isNotBlank( searchFields.getArtifactId() ) )
179 qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID,
180 searchFields.isExactSearch()
181 ? new SourcedSearchExpression( searchFields.getArtifactId() )
182 : new UserInputSearchExpression( searchFields.getArtifactId() ) ),
183 BooleanClause.Occur.MUST );
186 if ( StringUtils.isNotBlank( searchFields.getVersion() ) )
188 qb.add( indexer.constructQuery( MAVEN.VERSION, searchFields.isExactSearch() ? new SourcedSearchExpression(
189 searchFields.getVersion() ) : new SourcedSearchExpression( searchFields.getVersion() ) ),
190 BooleanClause.Occur.MUST );
193 if ( StringUtils.isNotBlank( searchFields.getPackaging() ) )
195 qb.add( indexer.constructQuery( MAVEN.PACKAGING, searchFields.isExactSearch() ? new SourcedSearchExpression(
196 searchFields.getPackaging() ) : new UserInputSearchExpression( searchFields.getPackaging() ) ),
197 BooleanClause.Occur.MUST );
200 if ( StringUtils.isNotBlank( searchFields.getClassName() ) )
202 qb.add( indexer.constructQuery( MAVEN.CLASSNAMES,
203 new UserInputSearchExpression( searchFields.getClassName() ) ),
204 BooleanClause.Occur.MUST );
207 if ( StringUtils.isNotBlank( searchFields.getBundleSymbolicName() ) )
209 qb.add( indexer.constructQuery( OSGI.SYMBOLIC_NAME,
210 new UserInputSearchExpression( searchFields.getBundleSymbolicName() ) ),
211 BooleanClause.Occur.MUST );
214 if ( StringUtils.isNotBlank( searchFields.getBundleVersion() ) )
216 qb.add( indexer.constructQuery( OSGI.VERSION,
217 new UserInputSearchExpression( searchFields.getBundleVersion() ) ),
218 BooleanClause.Occur.MUST );
221 if ( StringUtils.isNotBlank( searchFields.getBundleExportPackage() ) )
223 qb.add( indexer.constructQuery( OSGI.EXPORT_PACKAGE,
224 new UserInputSearchExpression( searchFields.getBundleExportPackage() ) ),
228 if ( StringUtils.isNotBlank( searchFields.getBundleExportService() ) )
230 qb.add( indexer.constructQuery( OSGI.EXPORT_SERVICE,
231 new UserInputSearchExpression( searchFields.getBundleExportService() ) ),
235 if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) )
237 qb.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE,
238 new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ),
242 if ( StringUtils.isNotBlank( searchFields.getBundleName() ) )
244 qb.add( indexer.constructQuery( OSGI.NAME, new UserInputSearchExpression( searchFields.getBundleName() ) ),
248 if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) )
250 qb.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE,
251 new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ),
255 if ( StringUtils.isNotBlank( searchFields.getBundleRequireBundle() ) )
257 qb.add( indexer.constructQuery( OSGI.REQUIRE_BUNDLE,
258 new UserInputSearchExpression( searchFields.getBundleRequireBundle() ) ),
262 if ( StringUtils.isNotBlank( searchFields.getClassifier() ) )
264 qb.add( indexer.constructQuery( MAVEN.CLASSIFIER, searchFields.isExactSearch() ? new SourcedSearchExpression(
265 searchFields.getClassifier() ) : new UserInputSearchExpression( searchFields.getClassifier() ) ),
268 else if ( searchFields.isExactSearch() )
270 //TODO improvement in case of exact search and no classifier we must query for classifier with null value
271 // currently it's done in DefaultSearchService with some filtering
274 BooleanQuery qu = qb.build();
275 if ( qu.clauses() == null || qu.clauses().size() <= 0 )
277 throw new RepositorySearchException( "No search fields set." );
279 if (qu.clauses()!=null) {
280 log.debug("CLAUSES ", qu.clauses());
281 for (BooleanClause cl : qu.clauses()) {
282 log.debug("Clause ",cl);
286 return search( limits, qu, indexingContextIds, Collections.<ArtifactInfoFilter>emptyList(),
287 searchFields.getRepositories(), searchFields.isIncludePomArtifacts() );
290 private static class NullSearch
291 implements SearchTyped, SearchExpression
293 private static final NullSearch INSTANCE = new NullSearch();
296 public String getStringValue()
298 return "[[NULL_VALUE]]";
302 public SearchType getSearchType()
304 return SearchType.EXACT;
308 private SearchResults search( SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds,
309 List<? extends ArtifactInfoFilter> filters, List<String> selectedRepos,
310 boolean includePoms )
311 throws RepositorySearchException
316 FlatSearchRequest request = new FlatSearchRequest( q );
318 request.setContexts( getIndexingContexts( indexingContextIds ) );
319 if ( limits != null )
321 // we apply limits only when first page asked
322 if ( limits.getSelectedPage() == 0 )
324 request.setCount( limits.getPageSize() * ( Math.max( 1, limits.getSelectedPage() ) ) );
328 FlatSearchResponse response = indexer.searchFlat( request );
330 if ( response == null || response.getTotalHits() == 0 )
332 SearchResults results = new SearchResults();
333 results.setLimits( limits );
337 return convertToSearchResults( response, limits, filters, selectedRepos, includePoms );
339 catch ( IOException e )
341 throw new RepositorySearchException( e.getMessage(), e );
343 catch ( RepositoryAdminException e )
345 throw new RepositorySearchException( e.getMessage(), e );
350 private IndexingContext getIndexingContext(String id) {
352 if (StringUtils.startsWith(id, "remote-")) {
353 repoId = StringUtils.substringAfter(id, "remote-");
357 Repository repo = repositoryRegistry.getRepository(repoId);
361 if (repo.getIndexingContext()!=null) {
363 return repo.getIndexingContext().getBaseContext(IndexingContext.class);
364 } catch (UnsupportedBaseContextException e) {
373 private List<IndexingContext> getIndexingContexts( List<String> ids )
375 List<IndexingContext> contexts = new ArrayList<>( ids.size() );
377 for ( String id : ids )
379 IndexingContext context = getIndexingContext(id);
380 if ( context != null )
382 contexts.add( context );
386 log.warn( "context with id {} not exists", id );
393 private void constructQuery( String term, BooleanQuery.Builder q )
395 q.add( indexer.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD );
396 q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD );
397 q.add( indexer.constructQuery( MAVEN.VERSION, new UserInputSearchExpression( term ) ), Occur.SHOULD );
398 q.add( indexer.constructQuery( MAVEN.PACKAGING, new UserInputSearchExpression( term ) ), Occur.SHOULD );
399 q.add( indexer.constructQuery( MAVEN.CLASSNAMES, new UserInputSearchExpression( term ) ), Occur.SHOULD );
402 // new WildcardQuery( new Term( MAVEN.CLASSNAMES.getFieldName(), "*" ) );
403 //q.add( query, Occur.MUST_NOT );
404 // olamy IMHO we could set this option as at least one must match
405 //q.setMinimumNumberShouldMatch( 1 );
410 * @param selectedRepos
411 * @return indexing contextId used
413 private List<String> addIndexingContexts( List<String> selectedRepos )
415 Set<String> indexingContextIds = new HashSet<>();
416 for ( String repo : selectedRepos )
420 Repository rRepo = repositoryRegistry.getRepository(repo);
425 if (rRepo.getType().equals(RepositoryType.MAVEN)) {
426 assert rRepo.getIndexingContext() != null;
427 IndexingContext context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);
428 if (context.isSearchable()) {
429 indexingContextIds.addAll(getRemoteIndexingContextIds(repo));
430 indexingContextIds.add(context.getId());
432 log.warn("indexingContext with id {} not searchable", rRepo.getId());
439 log.warn( "Repository '{}' not found in configuration.", repo );
442 catch ( RepositorySearchException e )
444 log.warn( "RepositorySearchException occured while accessing index of repository '{}' : {}", repo,
447 } catch (UnsupportedBaseContextException e) {
448 log.error("Fatal situation: Maven repository without IndexingContext found.");
453 return new ArrayList<>( indexingContextIds );
458 public Set<String> getRemoteIndexingContextIds( String managedRepoId )
459 throws RepositorySearchException
461 Set<String> ids = new HashSet<>();
463 List<ProxyConnector> proxyConnectors = null;
466 proxyConnectors = proxyConnectorAdmin.getProxyConnectorAsMap().get( managedRepoId );
468 catch ( RepositoryAdminException e )
470 throw new RepositorySearchException( e.getMessage(), e );
473 if ( proxyConnectors == null || proxyConnectors.isEmpty() )
478 for ( ProxyConnector proxyConnector : proxyConnectors )
480 String remoteId = "remote-" + proxyConnector.getTargetRepoId();
481 RemoteRepository repo = repositoryRegistry.getRemoteRepository(proxyConnector.getTargetRepoId());
482 if (repo.getType()==RepositoryType.MAVEN) {
484 IndexingContext context = repo.getIndexingContext() != null ? repo.getIndexingContext().getBaseContext(IndexingContext.class) : null;
485 if (context!=null && context.isSearchable()) {
488 } catch (UnsupportedBaseContextException e) {
498 public Collection<String> getAllGroupIds( String principal, List<String> selectedRepos )
499 throws RepositorySearchException
501 List<IndexingContext> indexContexts = getIndexingContexts( selectedRepos );
503 if ( indexContexts == null || indexContexts.isEmpty() )
505 return Collections.emptyList();
510 Set<String> allGroupIds = new HashSet<>();
511 for ( IndexingContext indexingContext : indexContexts )
513 allGroupIds.addAll( indexingContext.getAllGroups() );
517 catch ( IOException e )
519 throw new RepositorySearchException( e.getMessage(), e );
524 private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits,
525 List<? extends ArtifactInfoFilter> artifactInfoFilters,
526 List<String> selectedRepos, boolean includePoms )
527 throws RepositoryAdminException
529 SearchResults results = new SearchResults();
530 Set<ArtifactInfo> artifactInfos = response.getResults();
532 for ( ArtifactInfo artifactInfo : artifactInfos )
534 if ( StringUtils.equalsIgnoreCase( "pom", artifactInfo.getFileExtension() ) && !includePoms )
538 String id = SearchUtil.getHitId( artifactInfo.getGroupId(), //
539 artifactInfo.getArtifactId(), //
540 artifactInfo.getClassifier(), //
541 artifactInfo.getPackaging() );
542 Map<String, SearchResultHit> hitsMap = results.getHitsMap();
545 if ( !applyArtifactInfoFilters( artifactInfo, artifactInfoFilters, hitsMap ) )
550 SearchResultHit hit = hitsMap.get( id );
553 if ( !hit.getVersions().contains( artifactInfo.getVersion() ) )
555 hit.addVersion( artifactInfo.getVersion() );
560 hit = new SearchResultHit();
561 hit.setArtifactId( artifactInfo.getArtifactId() );
562 hit.setGroupId( artifactInfo.getGroupId() );
563 hit.setRepositoryId( artifactInfo.getRepository() );
564 hit.addVersion( artifactInfo.getVersion() );
565 hit.setBundleExportPackage( artifactInfo.getBundleExportPackage() );
566 hit.setBundleExportService( artifactInfo.getBundleExportService() );
567 hit.setBundleSymbolicName( artifactInfo.getBundleSymbolicName() );
568 hit.setBundleVersion( artifactInfo.getBundleVersion() );
569 hit.setBundleDescription( artifactInfo.getBundleDescription() );
570 hit.setBundleDocUrl( artifactInfo.getBundleDocUrl() );
571 hit.setBundleRequireBundle( artifactInfo.getBundleRequireBundle() );
572 hit.setBundleImportPackage( artifactInfo.getBundleImportPackage() );
573 hit.setBundleLicense( artifactInfo.getBundleLicense() );
574 hit.setBundleName( artifactInfo.getBundleName() );
575 hit.setContext( artifactInfo.getContext() );
576 hit.setGoals( artifactInfo.getGoals() );
577 hit.setPrefix( artifactInfo.getPrefix() );
578 hit.setPackaging( artifactInfo.getPackaging() );
579 hit.setClassifier( artifactInfo.getClassifier() );
580 hit.setFileExtension( artifactInfo.getFileExtension() );
581 hit.setUrl( getBaseUrl( artifactInfo, selectedRepos ) );
584 results.addHit( id, hit );
587 results.setTotalHits( response.getTotalHitsCount() );
588 results.setTotalHitsMapSize( results.getHitsMap().values().size() );
589 results.setReturnedHitsCount( response.getReturnedHitsCount() );
590 results.setLimits( limits );
592 if ( limits == null || limits.getSelectedPage() == SearchResultLimits.ALL_PAGES )
598 return paginate( results );
603 * calculate baseUrl without the context and base Archiva Url
605 * @param artifactInfo
608 protected String getBaseUrl( ArtifactInfo artifactInfo, List<String> selectedRepos )
609 throws RepositoryAdminException
611 StringBuilder sb = new StringBuilder();
612 if ( StringUtils.startsWith( artifactInfo.getContext(), "remote-" ) )
614 // it's a remote index result we search a managed which proxying this remote and on which
615 // current user has read karma
616 String managedRepoId =
617 getManagedRepoId( StringUtils.substringAfter( artifactInfo.getContext(), "remote-" ), selectedRepos );
618 if ( managedRepoId != null )
620 sb.append( '/' ).append( managedRepoId );
621 artifactInfo.setContext( managedRepoId );
626 sb.append( '/' ).append( artifactInfo.getContext() );
629 sb.append( '/' ).append( StringUtils.replaceChars( artifactInfo.getGroupId(), '.', '/' ) );
630 sb.append( '/' ).append( artifactInfo.getArtifactId() );
631 sb.append( '/' ).append( artifactInfo.getVersion() );
632 sb.append( '/' ).append( artifactInfo.getArtifactId() );
633 sb.append( '-' ).append( artifactInfo.getVersion() );
634 if ( StringUtils.isNotBlank( artifactInfo.getClassifier() ) )
636 sb.append( '-' ).append( artifactInfo.getClassifier() );
638 // maven-plugin packaging is a jar
639 if ( StringUtils.equals( "maven-plugin", artifactInfo.getPackaging() ) )
645 sb.append( '.' ).append( artifactInfo.getPackaging() );
648 return sb.toString();
652 * return a managed repo for a remote result
655 * @param selectedRepos
657 * @throws RepositoryAdminException
659 private String getManagedRepoId( String remoteRepo, List<String> selectedRepos )
660 throws RepositoryAdminException
662 Map<String, List<ProxyConnector>> proxyConnectorMap = proxyConnectorAdmin.getProxyConnectorAsMap();
663 if ( proxyConnectorMap == null || proxyConnectorMap.isEmpty() )
667 if ( selectedRepos != null && !selectedRepos.isEmpty() )
669 for ( Map.Entry<String, List<ProxyConnector>> entry : proxyConnectorMap.entrySet() )
671 if ( selectedRepos.contains( entry.getKey() ) )
673 for ( ProxyConnector proxyConnector : entry.getValue() )
675 if ( StringUtils.equals( remoteRepo, proxyConnector.getTargetRepoId() ) )
677 return proxyConnector.getSourceRepoId();
684 // we don't find in search selected repos so return the first one
685 for ( Map.Entry<String, List<ProxyConnector>> entry : proxyConnectorMap.entrySet() )
688 for ( ProxyConnector proxyConnector : entry.getValue() )
690 if ( StringUtils.equals( remoteRepo, proxyConnector.getTargetRepoId() ) )
692 return proxyConnector.getSourceRepoId();
700 private boolean applyArtifactInfoFilters( ArtifactInfo artifactInfo,
701 List<? extends ArtifactInfoFilter> artifactInfoFilters,
702 Map<String, SearchResultHit> currentResult )
704 if ( artifactInfoFilters == null || artifactInfoFilters.isEmpty() )
709 ArchivaArtifactModel artifact = new ArchivaArtifactModel();
710 artifact.setArtifactId( artifactInfo.getArtifactId() );
711 artifact.setClassifier( artifactInfo.getClassifier() );
712 artifact.setGroupId( artifactInfo.getGroupId() );
713 artifact.setRepositoryId( artifactInfo.getRepository() );
714 artifact.setVersion( artifactInfo.getVersion() );
715 artifact.setChecksumMD5( artifactInfo.getMd5() );
716 artifact.setChecksumSHA1( artifactInfo.getSha1() );
717 for ( ArtifactInfoFilter filter : artifactInfoFilters )
719 if ( !filter.addArtifactInResult( artifact, currentResult ) )
727 protected SearchResults paginate( SearchResults results )
729 SearchResultLimits limits = results.getLimits();
730 SearchResults paginated = new SearchResults();
732 // ( limits.getPageSize() * ( Math.max( 1, limits.getSelectedPage() ) ) );
734 int fetchCount = limits.getPageSize();
735 int offset = ( limits.getSelectedPage() * limits.getPageSize() );
737 if ( fetchCount > results.getTotalHits() )
739 fetchCount = results.getTotalHits();
743 if ( offset < results.getTotalHits() )
745 // only process if the offset is within the hit count.
746 for ( int i = 0; i < fetchCount; i++ )
748 // Stop fetching if we are past the total # of available hits.
749 if ( offset + i >= results.getHits().size() )
754 SearchResultHit hit = results.getHits().get( ( offset + i ) );
757 String id = SearchUtil.getHitId( hit.getGroupId(), hit.getArtifactId(), hit.getClassifier(),
758 hit.getPackaging() );
759 paginated.addHit( id, hit );
767 paginated.setTotalHits( results.getTotalHits() );
768 paginated.setReturnedHitsCount( paginated.getHits().size() );
769 paginated.setTotalHitsMapSize( results.getTotalHitsMapSize() );
770 paginated.setLimits( limits );