/** * Converts a SolrInputDocument into a Map * * @param doc the SolrInputDocument to convert * @return the input document as a map */ private Map<String, Object> convertToMap(SolrInputDocument doc) { // create the Map we will put the fields in Map<String, Object> newDoc = new HashMap<String, Object>(); // loop though all the fields and insert them into the map Collection<SolrInputField> fields = doc.values(); if (fields != null) { for (SolrInputField field : fields) { newDoc.put(field.getName(), field.getValue()); } } return newDoc; }
@Override public void load(SolrInputDocument doc) throws IOException, SolrServerException { String uniqueKeyFieldName = getSchema().getUniqueKeyField().getName(); Object id = doc.getFieldValue(uniqueKeyFieldName); if (id == null) { throw new IllegalArgumentException("Missing value for (required) unique document key: " + uniqueKeyFieldName + " (see Solr schema.xml)"); } try { context.write(new Text(id.toString()), new SolrInputDocumentWritable(doc)); } catch (InterruptedException e) { throw new IOException("Interrupted while writing " + doc, e); } if (LOG.isDebugEnabled()) { long numParserOutputBytes = 0; for (SolrInputField field : doc.values()) { numParserOutputBytes += sizeOf(field.getValue()); } context.getCounter(MorphlineCounters.class.getName(), MorphlineCounters.PARSER_OUTPUT_BYTES.toString()).increment(numParserOutputBytes); } context.getCounter(MorphlineCounters.class.getName(), MorphlineCounters.DOCS_READ.toString()).increment(1); }
@Override public void load(SolrInputDocument doc) throws IOException, SolrServerException { String uniqueKeyFieldName = getSchema().getUniqueKeyField().getName(); Object id = doc.getFieldValue(uniqueKeyFieldName); if (id == null) { throw new IllegalArgumentException("Missing value for (required) unique document key: " + uniqueKeyFieldName + " (see Solr schema.xml)"); } try { context.write(new Text(id.toString()), new SolrInputDocumentWritable(doc)); } catch (InterruptedException e) { throw new IOException("Interrupted while writing " + doc, e); } if (LOG.isDebugEnabled()) { long numParserOutputBytes = 0; for (SolrInputField field : doc.values()) { numParserOutputBytes += sizeOf(field.getValue()); } context.getCounter(MorphlineCounters.class.getName(), MorphlineCounters.PARSER_OUTPUT_BYTES.toString()).increment(numParserOutputBytes); } context.getCounter(MorphlineCounters.class.getName(), MorphlineCounters.DOCS_READ.toString()).increment(1); }
public void writeSolrInputDocument(SolrInputDocument sdoc) throws IOException { List<SolrInputDocument> children = sdoc.getChildDocuments(); int sz = sdoc.size() + (children==null ? 0 : children.size()); writeTag(SOLRINPUTDOC, sz); writeFloat(1f); // document boost for (SolrInputField inputField : sdoc.values()) { writeExternString(inputField.getName()); writeVal(inputField.getValue()); } if (children != null) { for (SolrInputDocument child : children) { writeSolrInputDocument(child); } } }
public void writeSolrInputDocument(SolrInputDocument sdoc) throws IOException { List<SolrInputDocument> children = sdoc.getChildDocuments(); int sz = sdoc.size() + (children==null ? 0 : children.size()); writeTag(SOLRINPUTDOC, sz); writeFloat(sdoc.getDocumentBoost()); for (SolrInputField inputField : sdoc.values()) { if (inputField.getBoost() != 1.0f) { writeFloat(inputField.getBoost()); } writeExternString(inputField.getName()); writeVal(inputField.getValue()); } if (children != null) { for (SolrInputDocument child : children) { writeSolrInputDocument(child); } } }