示例#1
0
  private static String format(SearchResultDocument doc, String padding) {
    StringBuilder sb = new StringBuilder();
    int valuesCount = 0;
    for (Collection<Object> values : doc.getFieldValuesMap().values()) {
      valuesCount += values.size();
    }
    sb.append(
        "SearchResultDocument: Name='"
            + getValueFromField(doc, "nameRaw")
            + "', URI='"
            + getValueFromField(doc, "URI")
            + "', "
            + doc.getFieldNames().size()
            + " fields with "
            + valuesCount
            + " values \n");

    for (String fieldName : new TreeMap<>(doc.getFieldValuesMap()).keySet()) {
      sb.append(padding)
          .append(
              "Field: Name='"
                  + fieldName
                  + "', "
                  + doc.getFieldValues(fieldName).size()
                  + " values \n");

      for (Object value : doc.getFieldValues(fieldName)) {
        sb.append(padding).append("   '").append(String.valueOf(value)).append("' \n");
      }
    }

    return sb.toString();
  }
示例#2
0
 public static String getValueFromField(SearchResultDocument doc, String fieldName) {
   Object value = doc.getFirstValue(fieldName);
   return (value == null) ? "UNKNOWN" : String.valueOf(value);
 }