protected FL_Link buildResultFromDocument(SolrDocument sd) {

    FL_Link.Builder linkBuilder = FL_Link.newBuilder();

    FL_PropertyDescriptors linkDescriptors = _applicationConfiguration.getLinkDescriptors();
    FL_PropertyDescriptors entityDescriptors = _applicationConfiguration.getEntityDescriptors();

    final String type = getTypeFromDocument(sd, linkDescriptors);

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

    String uid =
        sd.getFieldValue(
                PropertyDescriptorHelper.mapKey(
                    FL_RequiredPropertyKey.ID.name(), linkDescriptors.getProperties(), type))
            .toString();

    Object oSource =
        sd.getFieldValue(
            PropertyDescriptorHelper.mapKey(
                FL_RequiredPropertyKey.FROM.name(), linkDescriptors.getProperties(), type));
    String sSource =
        oSource instanceof String
            ? (String) oSource
            : oSource instanceof Integer ? Integer.toString((Integer) oSource) : null;

    linkBuilder.setProvenance(null);
    linkBuilder.setUncertainty(null);
    linkBuilder.setType(type);

    List<FL_Property> props = getPropertiesFromDocument(sd, type, linkDescriptors.getProperties());

    linkBuilder.setProperties(props);

    linkBuilder.setLinkTypes(null);

    linkBuilder.setUid(_namespaceHandler.globalFromLocalEntityId(InfluentId.LINK, type, uid));

    String sourceUID = null;
    if (sSource != null) {
      InfluentId infId;
      if (isMultitype) {
        infId = InfluentId.fromTypedId(InfluentId.ACCOUNT, sSource);
      } else {
        infId =
            InfluentId.fromNativeId(
                InfluentId.ACCOUNT, entityDescriptors.getTypes().get(0).getKey(), sSource);
      }
      sourceUID = infId.toString();
    }

    linkBuilder.setSource(sourceUID);
    linkBuilder.setTarget(getTarget(sd));

    return linkBuilder.build();
  }
  // 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;
  }