List of usage examples for org.apache.solr.client.solrj.util ClientUtils writeXML
public static void writeXML(SolrInputDocument doc, Writer writer) throws IOException
From source file:edu.unc.lib.dl.data.ingest.solr.test.AtomicUpdateTest.java
License:Apache License
@Test public void atomicUpdate() throws IOException { IndexDocumentBean idb = new IndexDocumentBean(); idb.setId("id"); idb.setStatus(Arrays.asList("Unpublished", "Parent Unpublished")); DocumentObjectBinder binder = new DocumentObjectBinder(); SolrInputDocument sid = binder.toSolrInputDocument(idb); String operation = "set"; for (String fieldName : sid.getFieldNames()) { if (!ID_FIELD.equals(fieldName)) { SolrInputField inputField = sid.getField(fieldName); // Adding in each non-null field value, except the timestamp field which gets cleared if not specified so // that it always gets updated as part of a partial update // TODO enable timestamp updating when fix for SOLR-4133 is released, which enables setting null fields if (inputField != null && (inputField.getValue() != null || UPDATE_TIMESTAMP.equals(fieldName))) { Map<String, Object> partialUpdate = new HashMap<String, Object>(); partialUpdate.put(operation, inputField.getValue()); sid.setField(fieldName, partialUpdate); }// ww w. ja v a2 s . c om } } /* Map<String,String> mapField = new HashMap<String,String>(); mapField.put("", arg1) Map<String, Object> partialUpdate = new HashMap<String, Object>(); partialUpdate.put("set", inputField.getFirstValue()); sid.setField(fieldName, partialUpdate);*/ StringWriter writer = new StringWriter(); ClientUtils.writeXML(sid, writer); System.out.println(writer.toString()); System.out.println(sid.toString()); }
From source file:uk.bl.wa.solr.SolrRecord.java
License:Open Source License
/** * Write the SolrDocument to the provided writer, sans XML-header. * Intended for creating batches of documents. *//*from w w w . jav a2 s.com*/ public void writeXml(Writer writer) throws IOException { ClientUtils.writeXML(doc, writer); }