class NpmSearchResponseFactory extends ComponentSupport {

  public NpmSearchResponse buildResponseForResults(final List<Terms.Bucket> buckets, final int size, final int from) {
    List<NpmSearchResponseObject> objects = buckets.stream()
        .map(bucket -> (TopHits) bucket.getAggregations().get("versions"))
        .map(TopHits::getHits)
        .map(searchHits -> searchHits.getAt(0))
        .map(this::buildSearchResponseObject)
        .skip(from)
        .limit(size)
        .collect(toList());

    return buildResponseForObjects(objects);
  }

  @Inject public  NpmSearchResponseFactory(final NpmSearchHitExtractor npmSearchHitExtractor);

}