Exemplo n.º 1
0
  private static SolrInputDocument toSolrInputDocument(StoredDocument doc, IndexSchema schema) {
    SolrInputDocument out = new SolrInputDocument();
    for (StorableField f : doc.getFields()) {
      String fname = f.name();
      SchemaField sf = schema.getFieldOrNull(f.name());
      Object val = null;
      if (sf != null) {
        if (!sf.stored() || schema.isCopyFieldTarget(sf)) continue;
        val = sf.getType().toObject(f); // object or external string?
      } else {
        val = f.stringValue();
        if (val == null) val = f.numericValue();
        if (val == null) val = f.binaryValue();
        if (val == null) val = f;
      }

      // todo: how to handle targets of copy fields (including polyfield sub-fields)?
      out.addField(fname, val);
    }
    return out;
  }
Exemplo n.º 2
0
  private static SolrDocument toSolrDoc(StoredDocument doc, IndexSchema schema) {
    SolrDocument out = new SolrDocument();
    for (StorableField f : doc.getFields()) {
      // Make sure multivalued fields are represented as lists
      Object existing = out.get(f.name());
      if (existing == null) {
        SchemaField sf = schema.getFieldOrNull(f.name());

        // don't return copyField targets
        if (sf != null && schema.isCopyFieldTarget(sf)) continue;

        if (sf != null && sf.multiValued()) {
          List<Object> vals = new ArrayList<Object>();
          vals.add(f);
          out.setField(f.name(), vals);
        } else {
          out.setField(f.name(), f);
        }
      } else {
        out.addField(f.name(), f);
      }
    }
    return out;
  }