private void assignOrderer(Section section,Resolution resolution,List<String> sourceList,HitGroup group) {
        if (section.getOrder()==null) { // then sort by relevance, source
            group.setOrderer(new HitSortOrderer(new RelevanceComparator(new SourceOrderComparator(sourceList))));
            return;
        }

        // replace a source field comparison by one which knows the source list order
        // and add default sorting at the end if necessary
        Sorting sorting=section.getOrder();
        int rankIndex=-1;
        int sourceIndex=-1;
        for (int i=0; i<sorting.fieldOrders().size(); i++) {
            Sorting.FieldOrder order=sorting.fieldOrders().get(i);
            if ("[relevance]".equals(order.getFieldName()) || "[rank]".equals(order.getFieldName()))
                rankIndex=i;
            else if (order.getFieldName().equals("[source]"))
                sourceIndex=i;
        }

        ChainableComparator comparator;
        Sorting beforeSource=null;
        Sorting afterSource=null;
        if (sourceIndex>=0) { // replace alphabetical sorting on source by sourceList order sorting
            if (sourceIndex>0) // sort fields before the source
                beforeSource=new Sorting(new ArrayList<>(sorting.fieldOrders().subList(0,sourceIndex)));
            if (sorting.fieldOrders().size()>sourceIndex+1) // sort fields after the source
                afterSource=new Sorting(new ArrayList<>(sorting.fieldOrders().subList(sourceIndex+1,sorting.fieldOrders().size()+1)));

            comparator=new SourceOrderComparator(sourceList, FieldComparator.create(afterSource));
            if (beforeSource!=null)
                comparator=new FieldComparator(beforeSource,comparator);

        }
        else if (rankIndex>=0) { // add sort by source at the end
            comparator=new FieldComparator(sorting,new SourceOrderComparator(sourceList));
        }
        else { // add sort by rank,source at the end
            comparator=new FieldComparator(sorting,new RelevanceComparator(new SourceOrderComparator(sourceList)));
        }
        group.setOrderer(new HitSortOrderer(comparator));
    }
Creates the hit group corresponding to a section, drawing data from the given result
container-search/src/main/java/com/yahoo/search/pagetemplates/engine/Organizer.java