List of usage examples for org.apache.solr.client.solrj.util ClientUtils toXML
public static String toXML(SolrInputDocument doc)
From source file:bamboo.trove.demand.OnDemandWarcManager.java
License:Apache License
public String index(long warcId, long warcOffset) throws Exception { if (!running) { return "<error>Offline</error>"; }// w ww .ja v a 2 s .co m log.info("Indexing on demand. Warc #{}", warcId); WarcProgressManager batch = getAndEnqueueWarc(warcId, warcOffset, 0); IndexerDocument responseDocument = batch.getTrackedDocument(); log.info("Warc #{} has {} documents. Loading has completed.", warcId, batch.size()); while (!batch.isFilterComplete()) { Thread.sleep(100); checkErrors(batch); } log.info("Warc #{} has finished filtering...", warcId); while (!batch.isTransformComplete()) { Thread.sleep(100); checkErrors(batch); } log.info("Warc #{} has finished transform...", warcId); while (!batch.isIndexComplete()) { Thread.sleep(100); checkErrors(batch); } log.info("Warc #{} has finished indexing...", warcId); warcsProcessed++; lastWarcId = warcId; return ClientUtils.toXML(responseDocument.getSolrDocument()); }
From source file:edu.cmu.lti.oaqa.annographix.solr.SolrServerWrapper.java
License:Apache License
/** * Converts an object of the type {@link org.apache.solr.common.SolrInputDocument} * into XML to post over HTTP for indexing. * // w w w . j a va 2 s . com * @param solrDoc a document to be indexed, which is represented by * an object of the type {@link org.apache.solr.common.SolrInputDocument}. * * @return a textual representation of the document in XML format. * @throws Exception */ public String convertSolrDocInXML(SolrInputDocument solrDoc) throws Exception { return ClientUtils.toXML(solrDoc); }
From source file:edu.unc.lib.dl.data.ingest.solr.indexing.SolrUpdateDriver.java
License:Apache License
/** * Perform a partial document update from a IndexDocumentBean. Null fields are considered to be unspecified and will * not be changed, except for the update timestamp field which is always set. * //w w w . j a va 2s . c o m * @param operation * @param idb * @throws IndexingException */ public void updateDocument(String operation, IndexDocumentBean idb) throws IndexingException { try { SolrInputDocument sid = solrServer.getBinder().toSolrInputDocument(idb); 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); } } } log.debug("Performing partial update:\n" + ClientUtils.toXML(sid)); solrServer.add(sid); } catch (IOException e) { throw new IndexingException("Failed to add document to solr", e); } catch (SolrServerException e) { throw new IndexingException("Failed to add document to solr", e); } }
From source file:org.apache.camel.component.solr.SolrSpringTest.java
License:Apache License
@DirtiesContext @Test/*w w w . ja v a2 s .c om*/ public void endToEndIndexDirectXML() throws Exception { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "MA147LL/A", 1.0f); String docAsXml = ClientUtils.toXML(doc); directXmlRoute.sendBody(docAsXml); QueryResponse response = executeSolrQuery("id:MA147LL/A"); assertEquals(0, response.getStatus()); assertEquals(1, response.getResults().getNumFound()); }
From source file:org.apache.camel.component.solr.SolrUpdateTest.java
License:Apache License
@Test public void testInsertSolrInputDocumentAsXMLWithoutAddRoot() throws Exception { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "MA147LL/A", 1.0f); String docAsXml = ClientUtils.toXML(doc); template.sendBodyAndHeader("direct:start", docAsXml, SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT); solrCommit();// w ww.ja v a2 s .c o m QueryResponse response = executeSolrQuery("id:MA147LL/A"); assertEquals(0, response.getStatus()); assertEquals(1, response.getResults().getNumFound()); }
From source file:org.apache.camel.component.solr.SolrUpdateTest.java
License:Apache License
@Test public void testInsertSolrInputDocumentAsXMLWithAddRoot() throws Exception { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "MA147LL/A", 1.0f); String docAsXml = "<add>" + ClientUtils.toXML(doc) + "</add>"; template.sendBodyAndHeader("direct:start", docAsXml, SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT); solrCommit();/* w ww. j av a 2s . co m*/ QueryResponse response = executeSolrQuery("id:MA147LL/A"); assertEquals(0, response.getStatus()); assertEquals(1, response.getResults().getNumFound()); }
From source file:uk.bl.wa.indexer.WARCIndexerCommand.java
License:Open Source License
/** * Checks whether a List of SolrInputDocuments has grown large enough to * be submitted to a SolrWebServer.//from w w w.ja v a 2s.c o m * * @param solr * @param docs * @param limit * @throws SolrServerException * @throws IOException */ private static void checkSubmission(SolrWebServer solr, List<SolrInputDocument> docs, int limit, boolean force) { if (docs.size() > 0 && (docs.size() >= limit || force)) { try { final long start = System.nanoTime(); if (log.isTraceEnabled() || debugMode) { for (SolrInputDocument doc : docs) { try { solr.updateSolrDoc(doc); } catch (Exception e) { log.error("Failed to post document - got exception: ", e); log.error("Failed document was:\n" + ClientUtils.toXML(doc)); System.exit(1); } } } else { solr.add(docs); } Instrument.timeRel("WARCIndexerCommand.parseWarcFiles#docdelivery", "WARCIndexerCommanc.checkSubmission#solrSendBatch", start); docs.clear(); } catch (SolrServerException s) { log.warn("SolrServerException: ", s); } catch (IOException i) { log.warn("IOException: ", i); } } }
From source file:uk.bl.wa.solr.SolrRecord.java
License:Open Source License
public String toXml() { return ClientUtils.toXML(doc); }