code: function sort() {
    var args = mlutil.asArray.apply(null, arguments);
    if (args.length === 0) {
      throw new Error('missing sorted index');
    }
  
    var firstIndex = asIndex(args[0]);
    // null is a legitimate value of score
    var isScore    = (firstIndex.score !== void 0);
  
    var sorter = {};
    if (isScore) {
      sorter.score = firstIndex.score;
    } else {
      addIndex(sorter, firstIndex, false);
    }
  
    var arg = null;
    for (var i=1; i < args.length; i++) {
      arg = args[i];
      if (typeof arg === 'string' || arg instanceof String) {
        switch (arg) {
        case 'ascending':
        case 'descending':
          sorter.direction = arg;
          break;
        default:
          if (!isScore && /^xs:/.test(arg)) {
            sorter.type = arg;
          }
          break;
        }
      } else if (isScore) {
      } else if (arg.datatype != null) {
        sorter.type = arg.datatype;
        if (arg.collation != null) {
          sorter.collation = arg.collation;
        }
      } else if (arg.collation != null) {
        sorter.type = 'xs:string';
        sorter.collation = arg.collation;
      }
    }
  
    return sorter;
  }
docs: A sort definition returned by the {@link queryBuilder#sort} function
  to pass to a {@link queryBuilder#orderBy} function.
  @typedef {object} queryBuilder.Sort
  @since 1.0
   
  Specifies the direction for sorting documents for a range index or
  relevance score.
  @method
  @since 1.0
  @memberof queryBuilder#
  @param {queryBuilder.IndexedName|queryBuilder.Score} sortItem - a
  JSON property, XML element or attribute, field, or path with a range index
  or the relevance ranking of the document returned
  by the {@link queryBuilder#score} function.
  @param {string} direction - a specification from the
  ascending|descending enumeration.
  @returns {queryBuilder.Sort} a sort definition
  for the {@link queryBuilder#orderBy} function