private float getDistance(Document d, ColorLayout cl, ScalableColor sc, EdgeHistogram eh) {
    float distance = 0f;
    int descriptorCount = 0;

    if (cl != null) {
      String[] cls = d.getValues(DocumentBuilder.FIELD_NAME_COLORLAYOUT);
      if (cls != null && cls.length > 0) {
        ColorLayout clsi = new ColorLayout();
        clsi.setStringRepresentation(cls[0]);
        distance += cl.getDistance(clsi) * colorDistributionWeight;
        descriptorCount++;
      }
    }

    if (sc != null) {
      String[] scs = d.getValues(DocumentBuilder.FIELD_NAME_SCALABLECOLOR);
      if (scs != null && scs.length > 0) {
        ScalableColor scsi = new ScalableColor();
        scsi.setStringRepresentation(scs[0]);
        distance += sc.getDistance(scsi) * colorHistogramWeight;
        descriptorCount++;
      }
    }

    if (eh != null) {
      String[] ehs = d.getValues(DocumentBuilder.FIELD_NAME_EDGEHISTOGRAM);
      if (ehs != null && ehs.length > 0) {
        EdgeHistogram ehsi = new EdgeHistogram();
        ehsi.setStringRepresentation(ehs[0]);
        distance += eh.getDistance(ehsi) * textureWeight;
        descriptorCount++;
      }
    }

    if (descriptorCount > 0) {
      // TODO: find some better scoring mechanism, e.g. some normalization. One thing would be
      // linearization of the features!
      // For now: Averaging ...
      distance = distance / (float) descriptorCount;
    }
    return distance;
  }