code: function findBestMatchingIndex(selector, userFields, sortOrder, indexes) {
  
    var matchingIndexes = findMatchingIndexes(selector, userFields, sortOrder, indexes);
  
    if (matchingIndexes.length === 0) {
      //return `all_docs` as a default index;
      //I'm assuming that _all_docs is always first
      var defaultIndex = indexes[0];
      defaultIndex.defaultUsed = true;
      return defaultIndex;
    }
    if (matchingIndexes.length === 1) {
      return matchingIndexes[0];
    }
  
    var userFieldsMap = utils.arrayToObject(userFields);
  
    function scoreIndex(index) {
      var indexFields = index.def.fields.map(getKey);
      var score = 0;
      for (var i = 0, len = indexFields.length; i < len; i++) {
        var indexField = indexFields[i];
        if (userFieldsMap[indexField]) {
          score++;
        }
      }
      return score;
    }
  
    return utils.max(matchingIndexes, scoreIndex);
  }
docs: find the best index, i.e. the one that matches the most fields in the user's query