docs: private List<String> sortIds(Set<String> docIdSet,
                                   List<FieldSort> sortDocument,
                                   List<Index> indexes,
                                   SQLDatabase db) throws QueryException {
          boolean smallResultSet = (docIdSet.size() < SMALL_RESULT_SET_SIZE_THRESHOLD);
          SqlParts orderBy = sqlToSortIds(docIdSet, sortDocument, indexes);
  
          List<String> sortedIds = null;
          // The query will iterate through a sorted list of docIds.
          // This means that if we create a new array and add entries
          // to that array as we iterate through the result set which
          // are part of the query's results, we'll end up with an
          // ordered set of results.
          Cursor cursor = null;
          try {
              cursor = db.rawQuery(orderBy.sqlWithPlaceHolders, orderBy.placeHolderValues);
              while (cursor.moveToNext()) {
                  if (sortedIds == null) {
                      sortedIds = new ArrayList<String>();
                  }
  
                  String candidateId = cursor.getString(0);
  
                  if (smallResultSet) {
                      sortedIds.add(candidateId);
                  } else {
                      if (docIdSet.contains(candidateId)) {
                          sortedIds.add(candidateId);
                      }
                  }
              }
          } catch (SQLException e) {
              logger.log(Level.SEVERE, "Failed to sort doc ids.", e);
              return null;
          } finally {
              DatabaseUtils.closeCursorQuietly(cursor);
          }
  
          return sortedIds;
      }