private static Set<String> getStringSet(SolrDocument doc, SolrName field) {
    Set<String> set = new HashSet<String>();

    if (doc.containsKey(field.solrName())) {
      for (Object val : doc.getFieldValues(field.solrName())) {
        set.add((String) val);
      }
    }

    return set;
  }
예제 #2
0
 public static boolean isLocalDirectory(SolrDocument doc) {
   if (doc.containsKey(TITLE)) {
     Object title = doc.get(TITLE);
     String titleContents = "";
     if (title instanceof ArrayList) {
       titleContents = (String) ((ArrayList) title).get(0);
     } else if (title instanceof String) {
       titleContents = (String) title;
     }
     return titleContents.startsWith("Index of /");
   }
   return false;
 }
예제 #3
0
  public SolrRecord(SolrDocument doc, List<String> fields) {

    JSONObject jsonObject = new JSONObject();
    for (String s : fields) {
      if (doc.containsKey(s)) {
        jsonObject.put(s, doc.get(s));
      }
    }
    String contentStr = jsonObject.toString(3).replaceAll("\n", DEFAULT_NEWLINE);
    content = contentStr.getBytes();
    contentType = SolrUtils.getDocumentContentType(doc);
    id = getFieldStringValue(doc, ID, "not_found");
    fileName = new File(id).getName();
  }
  public SolrDocument doc2SolrDoc(Document doc) {
    SolrDocument solrDoc = new SolrDocument();
    for (IndexableField field : doc) {
      String fieldName = field.name();
      SchemaField sf =
          getSchemaField(
              fieldName); // hack-patch of this.core.getLatestSchema().getFieldOrNull(fieldName);
                          // makes it a lot faster!!
      Object val = null;
      try {
        FieldType ft = null;
        if (sf != null) ft = sf.getType();
        if (ft == null) {
          BytesRef bytesRef = field.binaryValue();
          if (bytesRef != null) {
            if (bytesRef.offset == 0 && bytesRef.length == bytesRef.bytes.length) {
              val = bytesRef.bytes;
            } else {
              final byte[] bytes = new byte[bytesRef.length];
              System.arraycopy(bytesRef.bytes, bytesRef.offset, bytes, 0, bytesRef.length);
              val = bytes;
            }
          } else {
            val = field.stringValue();
          }
        } else {
          val = ft.toObject(field);
        }
      } catch (Throwable e) {
        continue;
      }

      if (sf != null && sf.multiValued() && !solrDoc.containsKey(fieldName)) {
        ArrayList<Object> l = new ArrayList<Object>();
        l.add(val);
        solrDoc.addField(fieldName, l);
      } else {
        solrDoc.addField(fieldName, val);
      }
    }
    return solrDoc;
  }
 private static boolean has(SolrDocument doc, SolrName field) {
   return doc.containsKey(field.solrName());
 }
예제 #6
0
 public static Object getFieldValue(SolrDocument doc, String fieldName) {
   return (doc != null && doc.containsKey(fieldName)) ? doc.get(fieldName) : null;
 }