@Override public void commit(SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush) throws ServiceException, IOException { try { if (!this.commit) { LOG.warn("The flag / property \"solr.index.commit\" is set to false but a commit is being forced via the API."); } if (LOG.isDebugEnabled()) { LOG.debug("Committing changes to Solr index: softCommit: " + softCommit + ", waitSearcher: " + waitSearcher + ", waitFlush: " + waitFlush); } server.commit(waitFlush, waitSearcher, softCommit); } catch (SolrServerException e) { throw new ServiceException("Could not commit changes to Solr index", e); } }
@Override public void deleteAllDocuments(SolrClient server) throws ServiceException { try { String deleteQuery = "*:*"; LOG.debug("Deleting by query: " + deleteQuery); server.deleteByQuery(deleteQuery); server.commit(); } catch (Exception e) { throw new ServiceException("Could not delete documents", e); } }
public void updateState(List<TridentTuple> tuples) { try { SolrRequest solrRequest = solrMapper.toSolrRequest(tuples); solrClient.request(solrRequest, solrMapper.getCollection()); solrClient.commit(solrMapper.getCollection()); } catch (Exception e) { final String msg = String.format("%s", tuples); logger.warn(msg); throw new FailedException(msg, e); } } }
@Override public void deleteAllNamespaceDocuments(SolrClient server) throws ServiceException { try { String deleteQuery = StringUtil.sanitize(shs.getNamespaceFieldName()) + ":(\"" + StringUtil.sanitize(solrConfiguration.getNamespace()) + "\")"; LOG.debug("Deleting by query: " + deleteQuery); server.deleteByQuery(deleteQuery); //Explicitly do a hard commit here since we just deleted the entire index server.commit(); } catch (Exception e) { if (ServiceException.class.isAssignableFrom(e.getClass())) { throw (ServiceException) e; } throw new ServiceException("Could not delete documents", e); } }
private void ack(Tuple tuple) throws SolrServerException, IOException { if (commitStgy == null) { collector.ack(tuple); } else { final boolean isTickTuple = TupleUtils.isTick(tuple); if (!isTickTuple) { // Don't ack tick tuples toCommitTuples.add(tuple); commitStgy.update(); } if (isTickTuple || commitStgy.commit()) { solrClient.commit(solrMapper.getCollection()); ackCommittedTuples(); } } }
/** * Delete a record from the database. * * @param table * The name of the table * @param key * The record key of the record to delete. * @return Zero on success, a non-zero error code on error. See this class's description for a * discussion of error codes. */ @Override public Status delete(String table, String key) { try { UpdateResponse response; if (batchMode) { response = client.deleteById(table, key, commitTime); } else { response = client.deleteById(table, key); client.commit(table); } return checkStatus(response.getStatus()); } catch (IOException | SolrServerException e) { e.printStackTrace(); } return Status.ERROR; }
/** * Delete a record from the database. * * @param table * The name of the table * @param key * The record key of the record to delete. * @return Zero on success, a non-zero error code on error. See this class's description for a * discussion of error codes. */ @Override public Status delete(String table, String key) { try { UpdateResponse response; if (batchMode) { response = client.deleteById(table, key, commitTime); } else { response = client.deleteById(table, key); client.commit(table); } return checkStatus(response.getStatus()); } catch (IOException | SolrServerException e) { e.printStackTrace(); } return Status.ERROR; }
} else { writeResponse = client.add(table, updatedDoc); client.commit(table);
} else { writeResponse = client.add(table, updatedDoc); client.commit(table);
} else { response = client.add(table, doc); client.commit(table);
} else { response = client.add(table, doc); client.commit(table);
this.client.commit(collection);
@Override public Document update(Document update, Optional<String> rawIndex) throws IOException { Document newVersion = update; // Handle any case where we're given comments in Map form, instead of raw String Object commentsObj = update.getDocument().get(COMMENTS_FIELD); if ( commentsObj instanceof List && ((List<Object>) commentsObj).size() > 0 && ((List<Object>) commentsObj).get(0) instanceof Map) { newVersion = new Document(update); convertCommentsToRaw(newVersion.getDocument()); } try { SolrInputDocument solrInputDocument = SolrUtilities.toSolrInputDocument(newVersion); Optional<String> index = SolrUtilities .getIndex(config.getIndexSupplier(), newVersion.getSensorType(), rawIndex); if (index.isPresent()) { this.client.add(index.get(), solrInputDocument); this.client.commit(index.get()); } else { throw new IllegalStateException("Index must be specified or inferred."); } } catch (SolrServerException e) { throw new IOException(e); } return newVersion; }
@Override public Document addAlertsToMetaAlert(String metaAlertGuid, List<GetRequest> alertRequests) throws IOException, IllegalStateException { Document metaAlert = getRetrieveLatestDao() .getLatest(metaAlertGuid, MetaAlertConstants.METAALERT_TYPE); if (MetaAlertStatus.ACTIVE.getStatusString() .equals(metaAlert.getDocument().get(MetaAlertConstants.STATUS_FIELD))) { Iterable<Document> alerts = getRetrieveLatestDao().getAllLatest(alertRequests); Map<Document, Optional<String>> updates = buildAddAlertToMetaAlertUpdates(metaAlert, alerts); update(updates); } else { throw new IllegalStateException("Adding alerts to an INACTIVE meta alert is not allowed"); } try { solrClient.commit(METAALERTS_COLLECTION); } catch (SolrServerException e) { throw new IOException("Unable to commit alerts to metaalert: " + metaAlertGuid, e); } return metaAlert; } }
solrClient.commit(METAALERTS_COLLECTION); return metaAlert; } catch (IOException | SolrServerException e) {
public void close() throws IOException, SolrServerException { if (client != null) { client.commit(); client.close(); } } }
public JsonObjectBuilder deleteAllFromSolrAndResetIndexTimes() throws SolrServerException, IOException { JsonObjectBuilder response = Json.createObjectBuilder(); logger.info("attempting to delete all Solr documents before a complete re-index"); solrServer.deleteByQuery("*:*"); solrServer.commit(); int numRowsAffected = dvObjectService.clearAllIndexTimes(); response.add(numRowsClearedByClearAllIndexTimes, numRowsAffected); response.add(messageString, "Solr index and database index timestamps cleared."); return response; }
@After public void tearDown() throws Exception { if (server != null && server.ping() != null) { server.deleteByQuery("*:*"); server.commit(); server = null; } }
protected QueryResponse query(String query) { try { testServer.commitTransaction(); solrClient.commit(false, true, true); QueryResponse rsp = solrClient.query( new SolrQuery(query).setRows(Integer.MAX_VALUE).setSort(Fields.ID, SolrQuery.ORDER.asc)); return rsp; } catch (Exception e) { throw new RuntimeException(e); } }