List of usage examples for org.apache.solr.client.solrj.response UpdateResponse getRequestUrl
public String getRequestUrl()
From source file:com.nridge.ds.solr.SolrDS.java
License:Open Source License
/** * Adds the field values captured in the <i>Document</i> to * the content source. The fields must be derived from the * same collection defined in the schema definition. * <p>/*from w w w . ja va2s . c o m*/ * <b>Note:</b> Depending on the data source and its ability * to support transactions, you may need to apply * <code>commit()</code> and <code>rollback()</code> * logic around this method. * </p> * * @param aDocument Document to store. * * @throws com.nridge.core.base.ds.DSException Data source related exception. */ @Override public void add(Document aDocument) throws DSException { UpdateResponse updateResponse; Logger appLogger = mAppMgr.getLogger(this, "add"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); if (aDocument == null) throw new DSException("Document is null."); initialize(); ArrayList<SolrInputDocument> solrInputDocuments = new ArrayList<SolrInputDocument>(); try { solrInputDocuments.add(toSolrInputDocument(aDocument)); updateResponse = mSolrClient.add(solrInputDocuments); } catch (Exception e) { appLogger.error(e.getMessage(), e); throw new DSException(e.getMessage()); } if (updateResponse.getStatus() != Solr.RESPONSE_STATUS_SUCCESS) { String msgStr = String.format("%s: Response contained non success status code of %d.", updateResponse.getRequestUrl(), updateResponse.getStatus()); appLogger.error(msgStr); throw new DSException(msgStr); } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.nridge.ds.solr.SolrDS.java
License:Open Source License
/** * Adds the field values captured in the array of <i>Document</i> * to the content source. The fields must be derived from the * same collection defined in the schema definition. * <p>/* w w w. j a v a 2 s.c om*/ * <b>Note:</b> Depending on the data source and its ability * to support transactions, you may need to apply * <code>commit()</code> and <code>rollback()</code> * logic around this method. * </p> * * @param aDocuments An array of Documents to store. * * @throws com.nridge.core.base.ds.DSException Data source related exception. */ @Override public void add(ArrayList<Document> aDocuments) throws DSException { UpdateResponse updateResponse; Logger appLogger = mAppMgr.getLogger(this, "add"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); if (aDocuments == null) throw new DSException("Document list is null."); initialize(); ArrayList<SolrInputDocument> solrInputDocuments = new ArrayList<SolrInputDocument>(); try { for (Document document : aDocuments) solrInputDocuments.add(toSolrInputDocument(document)); updateResponse = mSolrClient.add(solrInputDocuments); } catch (Exception e) { appLogger.error(e.getMessage(), e); throw new DSException(e.getMessage()); } if (updateResponse.getStatus() != Solr.RESPONSE_STATUS_SUCCESS) { String msgStr = String.format("%s: Response contained non success status code of %d.", updateResponse.getRequestUrl(), updateResponse.getStatus()); appLogger.error(msgStr); throw new DSException(msgStr); } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.nridge.ds.solr.SolrDS.java
License:Open Source License
/** * Deletes the document identified by the <i>Document</i> from * the content source. The fields must be derived from the * same collection defined in the schema definition. * <p>/*from www.j a va 2s . c o m*/ * <b>Note:</b> The document must designate a field as a primary * key and that value must be assigned prior to using this * method. Also, depending on the data source and its ability * to support transactions, you may need to apply * <code>commit()</code> and <code>rollback()</code> * logic around this method. * </p> * * @param aDocument Document where the primary key field value is * assigned. * * @throws com.nridge.core.base.ds.DSException Data source related exception. */ @Override public void delete(Document aDocument) throws DSException { UpdateResponse updateResponse; Logger appLogger = mAppMgr.getLogger(this, "delete"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); initialize(); ArrayList<String> docIds = new ArrayList<String>(); delSingleDocument(docIds, aDocument); try { updateResponse = mSolrClient.deleteById(docIds); } catch (Exception e) { appLogger.error(e.getMessage(), e); throw new DSException(e.getMessage()); } if (updateResponse.getStatus() != Solr.RESPONSE_STATUS_SUCCESS) { String msgStr = String.format("%s: Response contained non success status code of %d.", updateResponse.getRequestUrl(), updateResponse.getStatus()); appLogger.error(msgStr); throw new DSException(msgStr); } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.nridge.ds.solr.SolrDS.java
License:Open Source License
/** * Deletes the documents identified by the array of <i>Document</i> * from the content source. The fields must be derived from the * same collection defined in the schema definition. * <p>/*from w w w . j a va2 s.c o m*/ * <b>Note:</b> The bag must designate a field as a primary * key and that value must be assigned prior to using this * method. * </p> * * @param aDocuments An array of documents where the primary key * field value is assigned. * * @throws com.nridge.core.base.ds.DSException Data source related exception. */ @Override public void delete(ArrayList<Document> aDocuments) throws DSException { UpdateResponse updateResponse; Logger appLogger = mAppMgr.getLogger(this, "delete"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); initialize(); ArrayList<String> docIds = new ArrayList<String>(); for (Document document : aDocuments) delSingleDocument(docIds, document); try { updateResponse = mSolrClient.deleteById(docIds); } catch (Exception e) { appLogger.error(e.getMessage(), e); throw new DSException(e.getMessage()); } if (updateResponse.getStatus() != Solr.RESPONSE_STATUS_SUCCESS) { String msgStr = String.format("%s: Response contained non success status code of %d.", updateResponse.getRequestUrl(), updateResponse.getStatus()); appLogger.error(msgStr); throw new DSException(msgStr); } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.nridge.ds.solr.SolrDS.java
License:Open Source License
/** * Deletes the documents based on the {@link com.nridge.core.base.ds.DSCriteria}. * The fields must be derived from the same collection defined in the schema * definition.//from w w w . j a va2 s . c o m * <p> * <b>Note:</b> Depending on the data source and its ability * to support transactions, you may need to apply * <code>commit()</code> and <code>rollback()</code> * logic around this method. * </p> * * @param aDSCriteria Data source criteria. * * @throws com.nridge.core.base.ds.DSException Data source related exception. */ public void delete(DSCriteria aDSCriteria) throws DSException { UpdateResponse updateResponse; Logger appLogger = mAppMgr.getLogger(this, "delete"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); initialize(); String solrQuery = mSolrQueryBuilder.createAsQueryString(aDSCriteria); try { updateResponse = mSolrClient.deleteByQuery(solrQuery); } catch (Exception e) { appLogger.error(e.getMessage(), e); throw new DSException(e.getMessage()); } if (updateResponse.getStatus() != Solr.RESPONSE_STATUS_SUCCESS) { String msgStr = String.format("%s: Response contained non success status code of %d.", updateResponse.getRequestUrl(), updateResponse.getStatus()); appLogger.error(msgStr); throw new DSException(msgStr); } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:ddf.catalog.cache.solr.impl.UninitializedSolrClientAdaptorTest.java
License:Open Source License
@Test public void deleteByQuery() throws Exception { UpdateResponse response = uninitializedSolrClientAdaptor.deleteByQuery("test-delete-by-query-string"); assertThat(response.getElapsedTime(), is(equalTo(0L))); assertThat(response.getRequestUrl(), is(equalTo(""))); assertThat(response.getResponse().size(), is(equalTo(0))); }
From source file:nl.minbzk.dwr.zoeken.enricher.uploader.SolrResultUploader.java
License:Open Source License
/** * {@inheritDoc}//w w w . ja v a2s . co m */ @Override public void upload(final EnricherJob job, final GeneratorResult result) throws Exception { try { SolrServer server = getInstance(job.getDatabaseName(), job.getGeneratorTypes()); // Create a new update request UpdateRequest request = createRequest(); request.add(((MultiGeneratorResult<SolrInputDocument>) result).getDocuments()); // Set a collection in case of a (resolvable) composite database name if (StringUtils.hasText(job.getDatabaseNameComposition())) { String compositeDatabaseName = determineAlternateDatabaseName(job.getDatabaseName(), job.getDatabaseNameComposition(), job.getDatabaseNamePrerequisitesExpression(), ((MultiGeneratorResult<SolrInputDocument>) result).getDocuments()); if (compositeDatabaseName != null) { if (logger.isDebugEnabled()) logger.debug(String.format("Composite database name resolved to collection '%s'", compositeDatabaseName)); request.setParam("collection", compositeDatabaseName); } else { if (logger.isDebugEnabled()) logger.debug(String.format( "Composite database name could not be (completely) resolved - will use default collection '%s'", job.getDatabaseName())); } } // Now perform the request UpdateResponse response = request.process(server); if (response.getStatus() != 0) logger.error("Failed to add documents to Solr, status = " + response.getStatus()); else logger.info(String.format("Successfully added document to Solr, using request URL %s", response.getRequestUrl())); // Perform direct notification now that the document has been uploaded notifier.process(result); } catch (SolrServerException e) { logger.error("Failed to add documents to Solr", e); } }