docs: 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;
  }