@Override public void cleanup() { if (solrClient != null) { try { solrClient.close(); } catch (IOException e) { LOG.error("Error while closing solrClient", e); } } }
private boolean causedByIOException(SolrServerException e) { boolean foundIOException = false; Throwable cause = e.getCause(); while (cause != null) { if (cause instanceof IOException) { foundIOException = true; break; } cause = cause.getCause(); } return foundIOException; }
private void commitDeletes(String collectionName, List<String> deleteIds) throws SolrServerException, IOException { if (deleteIds.size() == 0) return; solrClient.request(newUpdateRequest().deleteById(deleteIds), collectionName); }
/** * 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; }
@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 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 addDocuments(Collection<SolrInputDocument> documents) throws IOException, SolrServerException { solrConfiguration.getServer().add(documents); logDocuments(documents); }
private void commitDocumentChanges(String collectionName, Collection<SolrInputDocument> documents) throws SolrServerException, IOException { if (documents.size() == 0) return; try { solrClient.request(newUpdateRequest().add(documents), collectionName); } catch (HttpSolrClient.RemoteSolrException rse) { logger.error("Unable to save documents to Solr as one of the shape objects stored were not compatible with Solr.", rse); logger.error("Details in failed document batch: "); for (SolrInputDocument d : documents) { Collection<String> fieldNames = d.getFieldNames(); for (String name : fieldNames) { logger.error(name + ":" + d.getFieldValue(name).toString()); } } throw rse; } }
/** * Sets up the sorting criteria. This will support sorting by multiple fields at a time * * @param query * @param searchCriteria */ protected void attachSortClause(SolrQuery query, SearchCriteria searchCriteria, String defaultSort) { shs.attachSortClause(query, searchCriteria, defaultSort); query.addSort("score", SolrQuery.ORDER.desc); }
@Override public void deleteByQuery(String deleteQuery) throws SolrServerException, IOException { String productFilter = shs.getTypeFieldName() + ":" + shs.getPrimaryDocumentType(); // transform the deleteQuery to include the productFilter, this is necessary to ensure that we don't delete non-product documents accidentally deleteQuery = productFilter + " AND (" + deleteQuery + ")"; String childDeleteQuery = "{!child of=" + productFilter + "} " + deleteQuery; solrConfiguration.getServer().deleteByQuery(childDeleteQuery); solrConfiguration.getServer().deleteByQuery(deleteQuery); logDeleteQuery(childDeleteQuery); logDeleteQuery(deleteQuery); }
@Override protected void process(Tuple tuple) { try { SolrRequest request = solrMapper.toSolrRequest(tuple); solrClient.request(request, solrMapper.getCollection()); ack(tuple); } catch (Exception e) { fail(tuple, e); } }
@Override public void optimizeIndex(SolrClient server) throws ServiceException, IOException { try { if (LOG.isDebugEnabled()) { LOG.debug("Optimizing the index..."); } if (isSolrConfigured) { server.optimize(); } } catch (SolrServerException e) { throw new ServiceException("Could not optimize index", e); } }
/** * 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; }
@Override public void cleanup() throws DBException { try { client.close(); } catch (IOException e) { throw new DBException(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(); } } }
private boolean causedByIOException(SolrServerException e) { boolean foundIOException = false; Throwable cause = e.getCause(); while (cause != null) { if (cause instanceof IOException) { foundIOException = true; break; } cause = cause.getCause(); } return foundIOException; } }
@Override public void cleanup() throws DBException { try { client.close(); } catch (IOException e) { throw new DBException(e); } }
@Override public void close() throws BackendException { logger.trace("Shutting down connection to Solr", solrClient); try { solrClient.close(); } catch (IOException e) { throw new TemporaryBackendException(e); } }
public void destroy() throws Exception { //Make sure we shut down each of the SolrClient references (these is really the Solr clients despite the name) try { if (getServer() != null) { getServer().close();; } } catch (Exception e) { LOG.error("Error shutting down primary SolrClient (client).", e); } try { if (getReindexServer() != null && getReindexServer() != getServer()) { getReindexServer().close(); } } catch (Exception e) { LOG.error("Error shutting down reindex SolrClient (client).", e); } try { if (getAdminServer() != null && getAdminServer() != getServer() && getAdminServer() != getReindexServer()) { getAdminServer().close(); } } catch (Exception e) { LOG.error("Error shutting down admin SolrClient (client).", e); } } }