@Override
    public Result search(Query query, Execution e) {
        try {
            Parameters parameters = new Parameters(query);

            query.trace("MultipleResultsSearcher: " + parameters, false, 2);
            HitsRetriever hitsRetriever = new HitsRetriever(query,e,parameters);

            for (DocumentGroup documentGroup : parameters.documentGroups) {
                if (  hitsRetriever.numHits(documentGroup) < documentGroup.targetNumberOfDocuments) {
                    hitsRetriever.retrieveMoreHits(documentGroup);
                }
            }

            return hitsRetriever.createMultipleResultSets();
        } catch(ParameterException exception) {
            Result result = new Result(query);
            result.hits().addError(ErrorMessage.createInvalidQueryParameter(exception.msg));
            return result;
        }
    }
Groups hits according to document type.
For each group, the desired number of hits can be specified.

@author Tony Vaagenes
container-search/src/main/java/com/yahoo/prelude/searcher/MultipleResultsSearcher.java