]> source.dussan.org Git - archiva.git/blob
7e2fb57e227827f01822d3b6c0e5280eaf759ff4
[archiva.git] /
1 package org.apache.archiva.indexer.search;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import org.apache.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.ManagedRepository;
24 import org.apache.archiva.admin.model.beans.ProxyConnector;
25 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
26 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
27 import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
28 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
29 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
30 import org.apache.archiva.indexer.util.SearchUtil;
31 import org.apache.commons.lang.StringUtils;
32 import org.apache.lucene.search.BooleanClause.Occur;
33 import org.apache.lucene.search.BooleanQuery;
34 import org.apache.maven.index.ArtifactInfo;
35 import org.apache.maven.index.FlatSearchRequest;
36 import org.apache.maven.index.FlatSearchResponse;
37 import org.apache.maven.index.MAVEN;
38 import org.apache.maven.index.NexusIndexer;
39 import org.apache.maven.index.OSGI;
40 import org.apache.maven.index.context.IndexCreator;
41 import org.apache.maven.index.context.IndexingContext;
42 import org.apache.maven.index.expr.SourcedSearchExpression;
43 import org.apache.maven.index.expr.UserInputSearchExpression;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46 import org.springframework.stereotype.Service;
47
48 import javax.inject.Inject;
49 import java.io.IOException;
50 import java.util.ArrayList;
51 import java.util.Collection;
52 import java.util.Collections;
53 import java.util.HashSet;
54 import java.util.List;
55 import java.util.Map;
56 import java.util.Set;
57
58 /**
59  * RepositorySearch implementation which uses the Maven Indexer for searching.
60  */
61 @Service("repositorySearch#maven")
62 public class MavenRepositorySearch
63     implements RepositorySearch
64 {
65     private Logger log = LoggerFactory.getLogger( getClass() );
66
67     private NexusIndexer indexer;
68
69     private ManagedRepositoryAdmin managedRepositoryAdmin;
70
71     private ProxyConnectorAdmin proxyConnectorAdmin;
72
73     private MavenIndexerUtils mavenIndexerUtils;
74
75     protected MavenRepositorySearch()
76     {
77         // for test purpose
78     }
79
80     @Inject
81     public MavenRepositorySearch( PlexusSisuBridge plexusSisuBridge, ManagedRepositoryAdmin managedRepositoryAdmin,
82                                   MavenIndexerUtils mavenIndexerUtils, ProxyConnectorAdmin proxyConnectorAdmin )
83         throws PlexusSisuBridgeException
84     {
85         this.indexer = plexusSisuBridge.lookup( NexusIndexer.class );
86         this.managedRepositoryAdmin = managedRepositoryAdmin;
87         this.mavenIndexerUtils = mavenIndexerUtils;
88         this.proxyConnectorAdmin = proxyConnectorAdmin;
89     }
90
91     /**
92      * @see RepositorySearch#search(String, List, String, SearchResultLimits, List)
93      */
94     public SearchResults search( String principal, List<String> selectedRepos, String term, SearchResultLimits limits,
95                                  List<String> previousSearchTerms )
96         throws RepositorySearchException
97     {
98         List<String> indexingContextIds = addIndexingContexts( selectedRepos );
99
100         // since upgrade to nexus 2.0.0, query has changed from g:[QUERIED TERM]* to g:*[QUERIED TERM]*
101         //      resulting to more wildcard searches so we need to increase max clause count
102         BooleanQuery.setMaxClauseCount( Integer.MAX_VALUE );
103         BooleanQuery q = new BooleanQuery();
104
105         if ( previousSearchTerms == null || previousSearchTerms.isEmpty() )
106         {
107             constructQuery( term, q );
108         }
109         else
110         {
111             for ( String previousTerm : previousSearchTerms )
112             {
113                 BooleanQuery iQuery = new BooleanQuery();
114                 constructQuery( previousTerm, iQuery );
115
116                 q.add( iQuery, Occur.MUST );
117             }
118
119             BooleanQuery iQuery = new BooleanQuery();
120             constructQuery( term, iQuery );
121             q.add( iQuery, Occur.MUST );
122         }
123
124         // we retun only artifacts without classifier in quick search, olamy cannot find a way to say with this field empty
125         // FIXME  cannot find a way currently to setup this in constructQuery !!!
126         return search( limits, q, indexingContextIds, NoClassifierArtifactInfoFilter.LIST, selectedRepos, true );
127
128     }
129
130     /**
131      * @see RepositorySearch#search(String, SearchFields, SearchResultLimits)
132      */
133     public SearchResults search( String principal, SearchFields searchFields, SearchResultLimits limits )
134         throws RepositorySearchException
135     {
136         if ( searchFields.getRepositories() == null )
137         {
138             throw new RepositorySearchException( "Repositories cannot be null." );
139         }
140
141         List<String> indexingContextIds = addIndexingContexts( searchFields.getRepositories() );
142
143         // if no index found in the specified ones return an empty search result instead of doing a search on all index
144         // olamy: IMHO doesn't make sense
145         if ( !searchFields.getRepositories().isEmpty() && ( indexingContextIds == null
146             || indexingContextIds.isEmpty() ) )
147         {
148             return new SearchResults();
149         }
150
151         BooleanQuery q = new BooleanQuery();
152         if ( StringUtils.isNotBlank( searchFields.getGroupId() ) )
153         {
154             q.add( indexer.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( searchFields.getGroupId() ) ),
155                    Occur.MUST );
156         }
157
158         if ( StringUtils.isNotBlank( searchFields.getArtifactId() ) )
159         {
160             q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID,
161                                            new UserInputSearchExpression( searchFields.getArtifactId() ) ),
162                    Occur.MUST );
163         }
164
165         if ( StringUtils.isNotBlank( searchFields.getVersion() ) )
166         {
167             q.add( indexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression( searchFields.getVersion() ) ),
168                    Occur.MUST );
169         }
170
171         if ( StringUtils.isNotBlank( searchFields.getPackaging() ) )
172         {
173             q.add(
174                 indexer.constructQuery( MAVEN.PACKAGING, new UserInputSearchExpression( searchFields.getPackaging() ) ),
175                 Occur.MUST );
176         }
177
178         if ( StringUtils.isNotBlank( searchFields.getClassName() ) )
179         {
180             q.add( indexer.constructQuery( MAVEN.CLASSNAMES,
181                                            new UserInputSearchExpression( searchFields.getClassName() ) ), Occur.MUST );
182         }
183
184         if ( StringUtils.isNotBlank( searchFields.getBundleSymbolicName() ) )
185         {
186             q.add( indexer.constructQuery( OSGI.SYMBOLIC_NAME,
187                                            new UserInputSearchExpression( searchFields.getBundleSymbolicName() ) ),
188                    Occur.MUST );
189         }
190
191         if ( StringUtils.isNotBlank( searchFields.getBundleVersion() ) )
192         {
193             q.add( indexer.constructQuery( OSGI.VERSION,
194                                            new UserInputSearchExpression( searchFields.getBundleVersion() ) ),
195                    Occur.MUST );
196         }
197
198         if ( StringUtils.isNotBlank( searchFields.getBundleExportPackage() ) )
199         {
200             q.add( indexer.constructQuery( OSGI.EXPORT_PACKAGE,
201                                            new UserInputSearchExpression( searchFields.getBundleExportPackage() ) ),
202                    Occur.MUST );
203         }
204
205         if ( StringUtils.isNotBlank( searchFields.getBundleExportService() ) )
206         {
207             q.add( indexer.constructQuery( OSGI.EXPORT_SERVICE,
208                                            new UserInputSearchExpression( searchFields.getBundleExportService() ) ),
209                    Occur.MUST );
210         }
211
212         if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) )
213         {
214             q.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE,
215                                            new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ),
216                    Occur.MUST );
217         }
218
219         if ( StringUtils.isNotBlank( searchFields.getBundleName() ) )
220         {
221             q.add( indexer.constructQuery( OSGI.NAME, new UserInputSearchExpression( searchFields.getBundleName() ) ),
222                    Occur.MUST );
223         }
224
225         if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) )
226         {
227             q.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE,
228                                            new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ),
229                    Occur.MUST );
230         }
231
232         if ( StringUtils.isNotBlank( searchFields.getBundleRequireBundle() ) )
233         {
234             q.add( indexer.constructQuery( OSGI.REQUIRE_BUNDLE,
235                                            new UserInputSearchExpression( searchFields.getBundleRequireBundle() ) ),
236                    Occur.MUST );
237         }
238
239         if ( StringUtils.isNotBlank( searchFields.getClassifier() ) )
240         {
241             q.add( indexer.constructQuery( MAVEN.CLASSIFIER,
242                                            new UserInputSearchExpression( searchFields.getClassifier() ) ),
243                    Occur.MUST );
244         }
245
246         if ( q.getClauses() == null || q.getClauses().length <= 0 )
247         {
248             throw new RepositorySearchException( "No search fields set." );
249         }
250
251         return search( limits, q, indexingContextIds, Collections.<ArtifactInfoFilter>emptyList(),
252                        searchFields.getRepositories(), searchFields.isIncludePomArtifacts() );
253     }
254
255     private SearchResults search( SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds,
256                                   List<? extends ArtifactInfoFilter> filters, List<String> selectedRepos,
257                                   boolean includePoms )
258         throws RepositorySearchException
259     {
260
261         try
262         {
263             FlatSearchRequest request = new FlatSearchRequest( q );
264
265             request.setContexts( getIndexingContexts( indexingContextIds ) );
266
267             FlatSearchResponse response = indexer.searchFlat( request );
268
269             if ( response == null || response.getTotalHits() == 0 )
270             {
271                 SearchResults results = new SearchResults();
272                 results.setLimits( limits );
273                 return results;
274             }
275
276             return convertToSearchResults( response, limits, filters, selectedRepos, includePoms );
277         }
278         catch ( IOException e )
279         {
280             throw new RepositorySearchException( e.getMessage(), e );
281         }
282         catch ( RepositoryAdminException e )
283         {
284             throw new RepositorySearchException( e.getMessage(), e );
285         }
286
287     }
288
289     private List<IndexingContext> getIndexingContexts( List<String> ids )
290     {
291         List<IndexingContext> contexts = new ArrayList<>( ids.size() );
292
293         for ( String id : ids )
294         {
295             IndexingContext context = indexer.getIndexingContexts().get( id );
296             if ( context != null )
297             {
298                 contexts.add( context );
299             }
300             else
301             {
302                 log.warn( "context with id {} not exists", id );
303             }
304         }
305
306         return contexts;
307     }
308
309     private void constructQuery( String term, BooleanQuery q )
310     {
311         q.add( indexer.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD );
312         q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD );
313         q.add( indexer.constructQuery( MAVEN.VERSION, new UserInputSearchExpression( term ) ), Occur.SHOULD );
314         q.add( indexer.constructQuery( MAVEN.PACKAGING, new UserInputSearchExpression( term ) ), Occur.SHOULD );
315         q.add( indexer.constructQuery( MAVEN.CLASSNAMES, new UserInputSearchExpression( term ) ), Occur.SHOULD );
316
317         //Query query =
318         //    new WildcardQuery( new Term( MAVEN.CLASSNAMES.getFieldName(), "*" ) );
319         //q.add( query, Occur.MUST_NOT );
320         // olamy IMHO we could set this option as at least one must match
321         //q.setMinimumNumberShouldMatch( 1 );
322     }
323
324
325     /**
326      * @param selectedRepos
327      * @return indexing contextId used
328      */
329     private List<String> addIndexingContexts( List<String> selectedRepos )
330     {
331         Set<String> indexingContextIds = new HashSet<String>();
332         for ( String repo : selectedRepos )
333         {
334             try
335             {
336                 ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repo );
337
338                 if ( repoConfig != null )
339                 {
340
341                     IndexingContext context = managedRepositoryAdmin.createIndexContext( repoConfig );
342                     if ( context.isSearchable() )
343                     {
344                         indexingContextIds.addAll( getRemoteIndexingContextIds( repo ) );
345                         indexingContextIds.add( context.getId() );
346                     }
347                     else
348                     {
349                         log.warn( "indexingContext with id {} not searchable", repoConfig.getId() );
350                     }
351
352                 }
353                 else
354                 {
355                     log.warn( "Repository '{}' not found in configuration.", repo );
356                 }
357             }
358             catch ( RepositoryAdminException e )
359             {
360                 log.warn( "RepositoryAdminException occured while accessing index of repository '{}' : {}", repo,
361                           e.getMessage() );
362                 continue;
363             }
364         }
365
366         return new ArrayList<>( indexingContextIds );
367     }
368
369
370     public Set<String> getRemoteIndexingContextIds( String managedRepoId )
371         throws RepositoryAdminException
372     {
373         Set<String> ids = new HashSet<String>();
374
375         List<ProxyConnector> proxyConnectors = proxyConnectorAdmin.getProxyConnectorAsMap().get( managedRepoId );
376
377         if ( proxyConnectors == null || proxyConnectors.isEmpty() )
378         {
379             return ids;
380         }
381
382         for ( ProxyConnector proxyConnector : proxyConnectors )
383         {
384             String remoteId = "remote-" + proxyConnector.getTargetRepoId();
385             IndexingContext context = indexer.getIndexingContexts().get( remoteId );
386             if ( context != null && context.isSearchable() )
387             {
388                 ids.add( remoteId );
389             }
390         }
391
392         return ids;
393     }
394
395     public Collection<String> getAllGroupIds( String principal, List<String> selectedRepos )
396         throws RepositorySearchException
397     {
398         List<IndexingContext> indexContexts = getIndexingContexts( selectedRepos );
399
400         if ( indexContexts == null || indexContexts.isEmpty() )
401         {
402             return Collections.emptyList();
403         }
404
405         try
406         {
407             Set<String> allGroupIds = new HashSet<String>();
408             for ( IndexingContext indexingContext : indexContexts )
409             {
410                 allGroupIds.addAll( indexingContext.getAllGroups() );
411             }
412             return allGroupIds;
413         }
414         catch ( IOException e )
415         {
416             throw new RepositorySearchException( e.getMessage(), e );
417         }
418
419     }
420
421
422     protected List<? extends IndexCreator> getAllIndexCreators()
423     {
424         return mavenIndexerUtils.getAllIndexCreators();
425     }
426
427
428     private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits,
429                                                   List<? extends ArtifactInfoFilter> artifactInfoFilters,
430                                                   List<String> selectedRepos, boolean includePoms )
431         throws RepositoryAdminException
432     {
433         SearchResults results = new SearchResults();
434         Set<ArtifactInfo> artifactInfos = response.getResults();
435
436         for ( ArtifactInfo artifactInfo : artifactInfos )
437         {
438             if ( StringUtils.equalsIgnoreCase( "pom", artifactInfo.fextension ) && !includePoms )
439             {
440                 continue;
441             }
442             String id = SearchUtil.getHitId( artifactInfo.groupId, artifactInfo.artifactId, artifactInfo.classifier,
443                                              artifactInfo.packaging );
444             Map<String, SearchResultHit> hitsMap = results.getHitsMap();
445
446             if ( !applyArtifactInfoFilters( artifactInfo, artifactInfoFilters, hitsMap ) )
447             {
448                 continue;
449             }
450
451             SearchResultHit hit = hitsMap.get( id );
452             if ( hit != null )
453             {
454                 if ( !hit.getVersions().contains( artifactInfo.version ) )
455                 {
456                     hit.addVersion( artifactInfo.version );
457                 }
458             }
459             else
460             {
461                 hit = new SearchResultHit();
462                 hit.setArtifactId( artifactInfo.artifactId );
463                 hit.setGroupId( artifactInfo.groupId );
464                 hit.setRepositoryId( artifactInfo.repository );
465                 hit.addVersion( artifactInfo.version );
466                 hit.setBundleExportPackage( artifactInfo.bundleExportPackage );
467                 hit.setBundleExportService( artifactInfo.bundleExportService );
468                 hit.setBundleSymbolicName( artifactInfo.bundleSymbolicName );
469                 hit.setBundleVersion( artifactInfo.bundleVersion );
470                 hit.setBundleDescription( artifactInfo.bundleDescription );
471                 hit.setBundleDocUrl( artifactInfo.bundleDocUrl );
472                 hit.setBundleRequireBundle( artifactInfo.bundleRequireBundle );
473                 hit.setBundleImportPackage( artifactInfo.bundleImportPackage );
474                 hit.setBundleLicense( artifactInfo.bundleLicense );
475                 hit.setBundleName( artifactInfo.bundleName );
476                 hit.setContext( artifactInfo.context );
477                 hit.setGoals( artifactInfo.goals );
478                 hit.setPrefix( artifactInfo.prefix );
479                 hit.setPackaging( artifactInfo.packaging );
480                 hit.setClassifier( artifactInfo.classifier );
481                 hit.setFileExtension( artifactInfo.fextension );
482                 hit.setUrl( getBaseUrl( artifactInfo, selectedRepos ) );
483             }
484
485             results.addHit( id, hit );
486         }
487
488         results.setTotalHits( response.getTotalHitsCount() );
489         results.setTotalHitsMapSize( results.getHitsMap().values().size() );
490         results.setReturnedHitsCount( response.getReturnedHitsCount() );
491         results.setLimits( limits );
492
493         if ( limits == null || limits.getSelectedPage() == SearchResultLimits.ALL_PAGES )
494         {
495             return results;
496         }
497         else
498         {
499             return paginate( results );
500         }
501     }
502
503     /**
504      * calculate baseUrl without the context and base Archiva Url
505      *
506      * @param artifactInfo
507      * @return
508      */
509     protected String getBaseUrl( ArtifactInfo artifactInfo, List<String> selectedRepos )
510         throws RepositoryAdminException
511     {
512         StringBuilder sb = new StringBuilder();
513         if ( StringUtils.startsWith( artifactInfo.context, "remote-" ) )
514         {
515             // it's a remote index result we search a managed which proxying this remote and on which
516             // current user has read karma
517             String managedRepoId =
518                 getManagedRepoId( StringUtils.substringAfter( artifactInfo.context, "remote-" ), selectedRepos );
519             if ( managedRepoId != null )
520             {
521                 sb.append( '/' ).append( managedRepoId );
522                 artifactInfo.context = managedRepoId;
523             }
524         }
525         else
526         {
527             sb.append( '/' ).append( artifactInfo.context );
528         }
529
530         sb.append( '/' ).append( StringUtils.replaceChars( artifactInfo.groupId, '.', '/' ) );
531         sb.append( '/' ).append( artifactInfo.artifactId );
532         sb.append( '/' ).append( artifactInfo.version );
533         sb.append( '/' ).append( artifactInfo.artifactId );
534         sb.append( '-' ).append( artifactInfo.version );
535         if ( StringUtils.isNotBlank( artifactInfo.classifier ) )
536         {
537             sb.append( '-' ).append( artifactInfo.classifier );
538         }
539         // maven-plugin packaging is a jar
540         if ( StringUtils.equals( "maven-plugin", artifactInfo.packaging ) )
541         {
542             sb.append( "jar" );
543         }
544         else
545         {
546             sb.append( '.' ).append( artifactInfo.packaging );
547         }
548
549         return sb.toString();
550     }
551
552     /**
553      * return a managed repo for a remote result
554      *
555      * @param remoteRepo
556      * @param selectedRepos
557      * @return
558      * @throws RepositoryAdminException
559      */
560     private String getManagedRepoId( String remoteRepo, List<String> selectedRepos )
561         throws RepositoryAdminException
562     {
563         Map<String, List<ProxyConnector>> proxyConnectorMap = proxyConnectorAdmin.getProxyConnectorAsMap();
564         if ( proxyConnectorMap == null || proxyConnectorMap.isEmpty() )
565         {
566             return null;
567         }
568         if ( selectedRepos != null && !selectedRepos.isEmpty() )
569         {
570             for ( Map.Entry<String, List<ProxyConnector>> entry : proxyConnectorMap.entrySet() )
571             {
572                 if ( selectedRepos.contains( entry.getKey() ) )
573                 {
574                     for ( ProxyConnector proxyConnector : entry.getValue() )
575                     {
576                         if ( StringUtils.equals( remoteRepo, proxyConnector.getTargetRepoId() ) )
577                         {
578                             return proxyConnector.getSourceRepoId();
579                         }
580                     }
581                 }
582             }
583         }
584
585         // we don't find in search selected repos so return the first one
586         for ( Map.Entry<String, List<ProxyConnector>> entry : proxyConnectorMap.entrySet() )
587         {
588
589             for ( ProxyConnector proxyConnector : entry.getValue() )
590             {
591                 if ( StringUtils.equals( remoteRepo, proxyConnector.getTargetRepoId() ) )
592                 {
593                     return proxyConnector.getSourceRepoId();
594                 }
595             }
596
597         }
598         return null;
599     }
600
601     private boolean applyArtifactInfoFilters( ArtifactInfo artifactInfo,
602                                               List<? extends ArtifactInfoFilter> artifactInfoFilters,
603                                               Map<String, SearchResultHit> currentResult )
604     {
605         if ( artifactInfoFilters == null || artifactInfoFilters.isEmpty() )
606         {
607             return true;
608         }
609
610         for ( ArtifactInfoFilter filter : artifactInfoFilters )
611         {
612             if ( !filter.addArtifactInResult( artifactInfo, currentResult ) )
613             {
614                 return false;
615             }
616         }
617         return true;
618     }
619
620     protected SearchResults paginate( SearchResults results )
621     {
622         SearchResultLimits limits = results.getLimits();
623         SearchResults paginated = new SearchResults();
624
625         int fetchCount = limits.getPageSize();
626         int offset = ( limits.getSelectedPage() * limits.getPageSize() );
627
628         if ( fetchCount > results.getTotalHits() )
629         {
630             fetchCount = results.getTotalHits();
631         }
632
633         // Goto offset.
634         if ( offset < results.getTotalHits() )
635         {
636             // only process if the offset is within the hit count.
637             for ( int i = 0; i < fetchCount; i++ )
638             {
639                 // Stop fetching if we are past the total # of available hits.
640                 if ( offset + i >= results.getHits().size() )
641                 {
642                     break;
643                 }
644
645                 SearchResultHit hit = results.getHits().get( ( offset + i ) );
646                 if ( hit != null )
647                 {
648                     String id = SearchUtil.getHitId( hit.getGroupId(), hit.getArtifactId(), hit.getClassifier(),
649                                                      hit.getPackaging() );
650                     paginated.addHit( id, hit );
651                 }
652                 else
653                 {
654                     break;
655                 }
656             }
657         }
658         paginated.setTotalHits( results.getTotalHits() );
659         paginated.setReturnedHitsCount( paginated.getHits().size() );
660         paginated.setTotalHitsMapSize( results.getTotalHitsMapSize() );
661         paginated.setLimits( limits );
662
663         return paginated;
664     }
665
666
667 }