public Group addOrderBy(ExpressionNode exp, boolean asc) {
        if (orderByExp.size() >= MAX_ORDERBY_EXPRESSIONS) {
            throw new IllegalArgumentException("You have reached the limit for number of orderby expressions of " + MAX_ORDERBY_EXPRESSIONS);
        }
        if (exp instanceof AggregationResult) {
            exp = new AggregationRefNode((AggregationResult)exp);
        }
        RefResolver refResolver = new RefResolver(aggregationResults);
        exp.select(REF_LOCATOR, refResolver);
        aggregationResults = refResolver.results;
        orderByExp = add(orderByExp, exp);
        orderByIdx = add(orderByIdx, (asc ? 1 : -1) * orderByExp.size());
        return this;
    }
Adds an order-by expression to this group. If the expression is an AggregationResult, it will be added to the
list of this group's AggregationResults, and a reference to that expression is added instead. If the
AggregationResult is already present, a reference to THAT result is created instead.

@param exp the result to add
@param asc true to sort ascending, false to sort descending
@return this, to allow chaining
searchlib/src/main/java/com/yahoo/searchlib/aggregation/Group.java