public void organize(Choice templateChoice, Resolution resolution, Result result) {
        PageTemplate template = (PageTemplate)templateChoice.get(resolution.getResolution(templateChoice)).get(0);
        SectionHitGroup sectionGroup = toGroup(template.getSection(), resolution, result);
        ErrorHit errors = result.hits().getErrorHit();

        // transfer state from existing hit
        sectionGroup.setQuery(result.hits().getQuery());
        if (errors instanceof DefaultErrorHit)
            sectionGroup.add((DefaultErrorHit)errors);
        result.hits().forEachField((name, value) -> sectionGroup.setField(name, value));
        result.setHits(sectionGroup);
    }
Organizes the given result

@param templateChoice a choice between singleton lists of PageTemplates
@param resolution the resolution of (at least) the template choice and all choices contained in that template
@param result the result to organize
container-search/src/main/java/com/yahoo/search/pagetemplates/engine/Organizer.java