docInQuery method Null safety

bool docInQuery(
  1. Map<String, dynamic> doc
)

Implementation

bool docInQuery(Map<String, dynamic> doc) {
  for (Map query in compoundBody["query"]["bool"]["must"]) {
    if (query.containsKey("match")) {
      final match = query["match"] as Map;
      final key = match.keys.first;
      final value = match.values.first;

      dynamic source = (doc["_source"] as Map);
      for (String token in key.split(".")) {
        if (source.containsKey(token)) {
          source = source[token];
        } else {
          return false;
        }
      }
      if (source != value) return false;
    } else if (query.containsKey("range")) {
      // TODO
    }
  }
  return true;
}