Beispiel #1
0
 public static void addMetadataToDocument(
     LocalDocument doc, String fieldPrefix, Metadata metadata) {
   for (String name : metadata.names()) {
     if (metadata.getValues(name).length > 1) {
       doc.putContentField(fieldPrefix + name, Arrays.asList(metadata.getValues(name)));
     } else {
       doc.putContentField(fieldPrefix + name, metadata.get(name));
     }
   }
 }
Beispiel #2
0
  public static Map<String, Object> getFieldMatchingPattern(LocalDocument doc, String pattern) {
    Map<String, Object> fieldToUrl = new HashMap<String, Object>();

    for (String field : doc.getContentFields()) {
      Pattern p = Pattern.compile(pattern);
      Matcher m = p.matcher(field);
      if (m.matches()) {
        String toField;
        if (m.groupCount() >= 1) {
          toField = m.group(1);
        } else {
          toField = m.group();
        }
        Logger.debug("Added " + doc.getContentField(field) + " to " + toField);
        fieldToUrl.put(toField, doc.getContentField(field));
      }
    }

    return fieldToUrl;
  }
Beispiel #3
0
 public static void addLanguageToDocument(LocalDocument doc, String fieldPrefix, String text) {
   doc.putContentField(fieldPrefix + "language", new LanguageIdentifier(text).getLanguage());
 }
Beispiel #4
0
 public static void addTextToDocument(
     LocalDocument doc, String fieldPrefix, StringWriter textData) {
   doc.putContentField(fieldPrefix + "content", textData.toString());
 }