// Build an FL_Link result from a list of SolrDocuments returned from a group command in a query
  protected FL_Link buildResultFromGroupedDocuments(SolrDocumentList dl) {

    // Build the initial result from the first document
    FL_Link link = buildResultFromDocument(dl.get(0));

    // Get the nodetype
    String targetField =
        PropertyDescriptorHelper.mapKey(
            FL_RequiredPropertyKey.TO.name(),
            _applicationConfiguration.getLinkDescriptors().getProperties(),
            link.getType());

    // Add the remaining document properties to the entity
    // Currently only the TO field is aggregated from grouping of one-to-many links
    for (int i = 1; i < dl.size(); i++) {
      SolrDocument sd = dl.get(i);
      String target = (String) sd.getFieldValue(targetField);

      FL_Property property = null;
      List<FL_Property> properties = link.getProperties();
      for (FL_Property prop : link.getProperties()) {
        if (prop.getKey().equals(FL_RequiredPropertyKey.TO.name())) {
          property = prop;
        }
      }

      if (property != null) {
        Object range = property.getRange();

        if (range instanceof FL_ListRange) {
          List<Object> values = ((FL_ListRange) range).getValues();
          values.add(target);
        } else if (range instanceof FL_SingletonRange) {
          List<Object> values = new ArrayList<Object>();
          values.add(((FL_SingletonRange) range).getValue());
          values.add(target);
          property.setRange(
              FL_ListRange.newBuilder().setType(FL_PropertyType.STRING).setValues(values).build());
        }

        link.setProperties(properties);
      }

      link.setTarget(link.getTarget() + "," + getTarget(sd));
    }

    return link;
  }
  private String getTarget(SolrDocument sd) {
    FL_PropertyDescriptors linkDescriptors = _applicationConfiguration.getLinkDescriptors();
    FL_PropertyDescriptors entityDescriptors = _applicationConfiguration.getEntityDescriptors();

    final String type = getTypeFromDocument(sd, linkDescriptors);

    Object oTarget =
        sd.getFieldValue(
            PropertyDescriptorHelper.mapKey(
                FL_RequiredPropertyKey.TO.name(), linkDescriptors.getProperties(), type));
    String sTarget =
        oTarget instanceof String
            ? (String) oTarget
            : oTarget instanceof Integer ? Integer.toString((Integer) oTarget) : null;

    Boolean isMultitype = (entityDescriptors.getTypes().size() > 1);

    String targetUID = "";
    for (String individualTarget : sTarget.split("\\s*,\\s*")) {
      String individualTargetUID = null;
      if (individualTarget != null) {
        char toClass = InfluentId.ACCOUNT;
        String toType;
        if (isMultitype) {
          InfluentId infId = InfluentId.fromTypedId(toClass, individualTarget);
          toType = infId.getIdType();
          individualTarget = infId.getNativeId();
        } else {
          toType = entityDescriptors.getTypes().get(0).getKey();
        }
        individualTargetUID =
            _namespaceHandler.globalFromLocalEntityId(toClass, toType, individualTarget);
      }
      if (individualTargetUID != null) {
        targetUID += individualTargetUID + ",";
      }
    }
    targetUID = targetUID.substring(0, targetUID.length() - 1);

    return targetUID;
  }