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