code: private void resolveParents(final Map<Integer, Set<GeoName>> childMap) throws IOException {
          Map<Integer, GeoName> parentMap = new HashMap<Integer, GeoName>();
          Map<Integer, Set<GeoName>> grandParentMap = new HashMap<Integer, Set<GeoName>>();
          for (Integer parentId : childMap.keySet()) {
              // Lucene query used to look for exact match on the "geonameID" field
              Query q = NumericRangeQuery.newIntRange(GEONAME_ID.key(), parentId, parentId, true, true);
              TopDocs results = indexSearcher.search(q, null, 1, POPULATION_SORT);
              if (results.scoreDocs.length > 0) {
                  Document doc = indexSearcher.doc(results.scoreDocs[0].doc);
                  GeoName parent = BasicGeoName.parseFromGeoNamesRecord(doc.get(GEONAME.key()), doc.get(PREFERRED_NAME.key()));
                  parentMap.put(parent.getGeonameID(), parent);
                  if (!parent.isAncestryResolved()) {
                      Integer grandParentId = PARENT_ID.getValue(doc);
                      if (grandParentId != null) {
                          Set<GeoName> geos = grandParentMap.get(grandParentId);
                          if (geos == null) {
                              geos = new HashSet<GeoName>();
                              grandParentMap.put(grandParentId, geos);
                          }
                          geos.add(parent);
                      }
                  }
              } else {
                  LOG.error("Unable to find parent GeoName [{}]", parentId);
              }
          }
  
          // find all parents of the parents
          if (!grandParentMap.isEmpty()) {
              resolveParents(grandParentMap);
          }
  
          // set parents of children
          for (Integer parentId : childMap.keySet()) {
              GeoName parent = parentMap.get(parentId);
              if (parent == null) {
                  LOG.info("Unable to find parent with ID [{}]", parentId);
                  continue;
              }
              for (GeoName child : childMap.get(parentId)) {
                  child.setParent(parent);
              }
          }
      }
docs: Retrieves and sets the parents of the provided children.
  @param childMap the map of parent geonameID to the set of children that belong to it
  @throws IOException if an error occurs during parent resolution