code: function sortFieldsByIndex(userFields, index) {
    var indexFields = index.def.fields.map(getKey);
  
    return userFields.slice().sort(function (a, b) {
      var aIdx = indexFields.indexOf(a);
      var bIdx = indexFields.indexOf(b);
      if (aIdx === -1) {
        aIdx = Number.MAX_VALUE;
      }
      if (bIdx === -1) {
        bIdx = Number.MAX_VALUE;
      }
      return utils.compare(aIdx, bIdx);
    });
  }
docs: sort the user fields by their position in the index, if they're in the index