public static String getValueFromField(SearchInputDocument doc, String fieldName) { SearchInputField field = doc.getField(fieldName); if (field == null) { return "UNKNOWN"; } else { Object value = field.getFirstValue(); return (value == null) ? "UNKNOWN" : String.valueOf(value); } }
public static String format(SearchInputDocument doc) { StringBuilder sb = new StringBuilder(); sb.append( "SearchInputDocument: Name='" + getValueFromField(doc, "nameRaw") + "', URI='" + getValueFromField(doc, "URI") + "', boost='" + doc.getDocumentBoost() + "', " + doc.getFieldMap().size() + " fields \n"); for (SearchInputField field : new TreeMap<>(doc.getFieldMap()).values()) { sb.append(format(field, " ").append('\n')); } return sb.toString(); }