List of usage examples for org.apache.solr.client.solrj.response UpdateResponse toString
@Override
public String toString()
From source file:com.norconex.committer.solr.SolrCommitterSolrIntegrationTest.java
License:Apache License
@Test public void testCommitQueueWith3AddCommandAnd1DeleteCommand() throws Exception { UpdateResponse worked = server.deleteByQuery("*:*"); committer.commit();/*ww w . jav a2 s.c o m*/ System.out.println("deleted " + worked.toString()); String content1 = "Document 1"; InputStream doc1Content = IOUtils.toInputStream(content1); String id1 = "1"; Properties doc1Metadata = new Properties(); doc1Metadata.addString("id", id1); String content2 = "Document 2"; String id2 = "2"; InputStream doc2Content = IOUtils.toInputStream(content2); Properties doc2Metadata = new Properties(); doc2Metadata.addString("id", "2"); String content3 = "Document 3"; String id3 = "3"; InputStream doc3Content = IOUtils.toInputStream(content3); Properties doc3Metadata = new Properties(); doc2Metadata.addString("id", "3"); committer.add(id1, doc1Content, doc1Metadata); committer.add(id2, doc2Content, doc2Metadata); //TODO hacking this part of the test until a more solid fix is found in //SolrCommitter committer.commit(); committer.remove(id1, doc1Metadata); committer.add(id3, doc3Content, doc3Metadata); committer.commit(); IOUtils.closeQuietly(doc1Content); IOUtils.closeQuietly(doc2Content); IOUtils.closeQuietly(doc3Content); //Check that there is 2 documents in Solr SolrDocumentList results = getAllDocs(); System.out.println("results " + results.toString()); assertEquals(2, results.getNumFound()); System.out.println("Writing/Reading this => " + committer); }
From source file:com.norconex.committer.solr.SolrCommitterSolrIntegrationTest.java
License:Apache License
@Test public void testCommitQueueWith3AddCommandAnd2DeleteCommand() throws Exception { UpdateResponse worked = server.deleteByQuery("*:*"); committer.commit();/*ww w . java2 s. c o m*/ System.out.println("deleted " + worked.toString()); String content = "Document 1"; InputStream doc1Content = IOUtils.toInputStream(content); String id1 = "1"; Properties doc1Metadata = new Properties(); doc1Metadata.addString("id", id1); String content2 = "Document 2"; String id2 = "2"; InputStream doc2Content = IOUtils.toInputStream(content2); Properties doc2Metadata = new Properties(); doc2Metadata.addString("id", "2"); String content3 = "Document 3"; String id3 = "3"; InputStream doc3Content = IOUtils.toInputStream(content3); Properties doc3Metadata = new Properties(); doc2Metadata.addString("id", "3"); committer.add(id1, doc1Content, doc1Metadata); committer.add(id2, doc2Content, doc2Metadata); //TODO hacking this part of the test until a more solid fix is found in //SolrCommitter committer.commit(); committer.remove(id1, doc1Metadata); committer.remove(id2, doc1Metadata); committer.add(id3, doc3Content, doc3Metadata); committer.commit(); IOUtils.closeQuietly(doc1Content); IOUtils.closeQuietly(doc2Content); IOUtils.closeQuietly(doc3Content); //Check that there is 2 documents in Solr SolrDocumentList results = getAllDocs(); System.out.println("results " + results.toString()); assertEquals(1, results.getNumFound()); System.out.println("Writing/Reading this => " + committer); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.solr.SolrWriter_ImplBase.java
License:Apache License
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { super.collectionProcessComplete(); try {//w ww. j a va 2 s . c o m UpdateResponse response = solrServer.commit(waitFlush, waitSearcher); getLogger() .info(String.format("Solr server at '%s' responded: %s", targetLocation, response.toString())); solrServer.close(); } catch (SolrServerException | IOException e) { throw new AnalysisEngineProcessException(e); } }
From source file:eumetsat.pn.solr.SolrFeeder.java
@Override protected void indexDirContent(Path aSrcDir) { log.info("Indexing dir content {}", aSrcDir); JSONParser parser = new JSONParser(); YamlNode endpointConfig = this.config.get("endpoint"); String collection = endpointConfig.get("collection").asTextValue(); SolrServer solr;/* ww w.j a v a 2 s .c om*/ if (this.server != null) { solr = server; log.info("Using embedded SolrServer: {}", solr); } else { log.info("Endpoint configuration: {}", endpointConfig); String solrEndpoint = endpointConfig.get("url").asTextValue(); solr = new ConcurrentUpdateSolrServer(solrEndpoint + "/" + collection, 10, 1); // CloudSolrServer solr = new CloudSolrServer(solrEndpoint); // solr.setDefaultCollection(collection); log.info("Using HTTP SolrServer: {}", solr); } SolrPingResponse ping; try { ping = solr.ping(); log.debug("Pinged Solr server: {}", ping); } catch (SolrServerException | IOException | RemoteSolrException e) { log.error("Could not ping Solr server", e); } // Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", endpointConfig.get("cluster.name").asTextValue()).build(); int cpt = 0; Collection<File> inputFiles = FileUtils.listFiles(aSrcDir.toFile(), new String[] { "json" }, false); log.info("Indexing {} files...", inputFiles.size()); for (File file : inputFiles) { try { String jsonStr = FileUtils.readFileToString(file); JSONObject jsObj = (JSONObject) parser.parse(jsonStr); try { SolrInputDocument input = createInputDoc(jsObj); log.debug("Adding {} to collection {}", file.getName(), collection); log.trace("Full json of {}: {}", file.getName(), input); solr.add(input); cpt++; } catch (RuntimeException e) { log.error("Error processing input document {}: {}, {}", file, e, e.getMessage()); } if (cpt % 42 == 0) { // periodically flush log.info("Commiting to server, document count is {}", cpt); UpdateResponse response = solr.commit(); log.info("Response status: {} (time: {}): {}", response.getStatus(), response.getElapsedTime(), response.toString()); } } catch (IOException | ParseException | SolrServerException e) { log.error("Error comitting document based on file {}", file, e); } } try { solr.commit(); } catch (IOException | SolrServerException e) { log.error("Error comitting document", e); } solr.shutdown(); log.info("Indexed {} of {} files.", cpt, inputFiles.size()); }
From source file:org.apache.gora.solr.store.SolrStore.java
License:Apache License
@Override public boolean delete(K key) { String keyField = mapping.getPrimaryKey(); try {//w ww . j a v a 2 s . c o m UpdateResponse rsp = server.deleteByQuery(keyField + ":" + escapeQueryKey(key.toString())); server.commit(); LOG.info(rsp.toString()); return true; } catch (Exception e) { LOG.error(e.getMessage(), e); } return false; }
From source file:org.apache.gora.solr.store.SolrStore.java
License:Apache License
@Override public long deleteByQuery(Query<K, T> query) { String q = ((SolrQuery<K, T>) query).toSolrQuery(); try {/* www . j a va 2 s . c om*/ UpdateResponse rsp = server.deleteByQuery(q); server.commit(); LOG.info(rsp.toString()); } catch (Exception e) { LOG.error(e.getMessage(), e); } return 0; }
From source file:org.apache.ranger.audit.destination.SolrAuditDestination.java
License:Apache License
@Override public boolean log(Collection<AuditEventBase> events) { try {/*from w w w . j a v a 2s . co m*/ logStatusIfRequired(); addTotalCount(events.size()); if (solrClient == null) { connect(); if (solrClient == null) { // Solr is still not initialized. So need return error addDeferredCount(events.size()); return false; } } final Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); for (AuditEventBase event : events) { AuthzAuditEvent authzEvent = (AuthzAuditEvent) event; // Convert AuditEventBase to Solr document SolrInputDocument document = toSolrDoc(authzEvent); docs.add(document); } try { PrivilegedExceptionAction<UpdateResponse> action = new PrivilegedExceptionAction<UpdateResponse>() { @Override public UpdateResponse run() throws Exception { UpdateResponse response = solrClient.add(docs); return response; }; }; UpdateResponse response = null; UserGroupInformation ugi = MiscUtil.getUGILoginUser(); if (ugi != null) { response = ugi.doAs(action); } else { response = action.run(); } if (response.getStatus() != 0) { addFailedCount(events.size()); logFailedEvent(events, response.toString()); } else { addSuccessCount(events.size()); } } catch (SolrException ex) { addFailedCount(events.size()); logFailedEvent(events, ex); } } catch (Throwable t) { addDeferredCount(events.size()); logError("Error sending message to Solr", t); return false; } return true; }
From source file:org.apache.ranger.patch.cliutil.DbToSolrMigrationUtil.java
License:Apache License
public void send2solr(XXAccessAuditV4 xXAccessAudit) throws Throwable { SolrInputDocument document = new SolrInputDocument(); toSolrDocument(xXAccessAudit, document); UpdateResponse response = solrClient.add(document); if (response.getStatus() != 0) { logger.info("Response=" + response.toString() + ", status= " + response.getStatus() + ", event=" + xXAccessAudit.toString()); throw new Exception("Failed to send audit event ID=" + xXAccessAudit.getId()); }// w ww .j ava 2 s .co m }
From source file:org.apache.ranger.patch.cliutil.DbToSolrMigrationUtil.java
License:Apache License
public void send2solr(XXAccessAuditV5 xXAccessAudit) throws Throwable { SolrInputDocument document = new SolrInputDocument(); toSolrDocument(xXAccessAudit, document); UpdateResponse response = solrClient.add(document); if (response.getStatus() != 0) { logger.info("Response=" + response.toString() + ", status= " + response.getStatus() + ", event=" + xXAccessAudit.toString()); throw new Exception("Failed to send audit event ID=" + xXAccessAudit.getId()); }/* w w w.j a v a2 s .c om*/ }
From source file:org.apache.ranger.patch.cliutil.DbToSolrMigrationUtil.java
License:Apache License
public void send2solr(XXAccessAudit xXAccessAudit) throws Throwable { SolrInputDocument document = new SolrInputDocument(); toSolrDocument(xXAccessAudit, document); UpdateResponse response = solrClient.add(document); if (response.getStatus() != 0) { logger.info("Response=" + response.toString() + ", status= " + response.getStatus() + ", event=" + xXAccessAudit.toString()); throw new Exception("Failed to send audit event ID=" + xXAccessAudit.getId()); }/*from w w w . j a v a2 s.c o m*/ }