class IndexedQueryEngine implements QueryEngine {

  @Nullable
  @VisibleForTesting
  static IndexRange extractBestIndexRange(Query query) {
    // TODO: consider any startAt/endAt bounds on the query.

    double currentSelectivity = -1;

    if (!query.getFilters().isEmpty()) {
      Filter selectedFilter = null;
      for (Filter currentFilter : query.getFilters()) {
        double estimatedSelectivity = estimateFilterSelectivity(currentFilter);
        if (estimatedSelectivity > currentSelectivity) {
          selectedFilter = currentFilter;
          currentSelectivity = estimatedSelectivity;
        }
      }
      hardAssert(selectedFilter != null, "Filter should be defined");
      return convertFilterToIndexRange(selectedFilter);
    } else {
      // If there are no filters, use the first orderBy constraint when performing the index lookup.
      // This index lookup will remove results that do not contain the field we use for ordering.
      FieldPath orderPath = query.getOrderBy().get(0).getField();
      if (!orderPath.equals(FieldPath.KEY_PATH)) {
        return IndexRange.builder().setFieldPath(query.getOrderBy().get(0).getField()).build();
      }
    }

    return null;
  }

  public  IndexedQueryEngine(SQLiteCollectionIndex collectionIndex);

}