/** * 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; }
client.commit(table); return checkStatus(writeResponse.getStatus()); } catch (IOException | SolrServerException e) { e.printStackTrace();
client.commit(table); return checkStatus(writeResponse.getStatus()); } catch (IOException | SolrServerException e) { e.printStackTrace();
client.commit(table); return checkStatus(response.getStatus());
client.commit(table); return checkStatus(response.getStatus());
getLogger().debug("Got {} response from Solr", new Object[]{response.getStatus()}); } catch (SolrException e) { error.set(e);
private void index(boolean isSolrCloud, String collection, Long commitWithin, String contentStreamPath, MultiMapSolrParams requestParams, List<SolrInputDocument> inputDocumentList) throws IOException, SolrServerException,SolrException { UpdateRequest request = new UpdateRequest(contentStreamPath); request.setParams(new ModifiableSolrParams()); // add the extra params, don't use 'set' in case of repeating params Iterator<String> paramNames = requestParams.getParameterNamesIterator(); while (paramNames.hasNext()) { String paramName = paramNames.next(); for (String paramValue : requestParams.getParams(paramName)) { request.getParams().add(paramName, paramValue); } } // specify the collection for SolrCloud if (isSolrCloud) { request.setParam(COLLECTION_PARAM_NAME, collection); } if (commitWithin != null && commitWithin > 0) { request.setParam(COMMIT_WITHIN_PARAM_NAME, commitWithin.toString()); } // if a username and password were provided then pass them for basic auth if (isBasicAuthEnabled()) { request.setBasicAuthCredentials(getUsername(), getPassword()); } request.add(inputDocumentList); UpdateResponse response = request.process(getSolrClient()); getLogger().debug("Got {} response from Solr", new Object[]{response.getStatus()}); inputDocumentList.clear(); }
protected Optional<SolrException> fromUpdateResponse(UpdateResponse response) { if(response != null && response.getStatus() > 0) { String message = "Solr Update response: " + Joiner.on(",").join(response.getResponse()); return Optional.of(new SolrException(SolrException.ErrorCode.BAD_REQUEST, message)); } return Optional.empty(); }
private void processTuples() { try { SolrServer solrServer = solrServerConnector.getSolrServer(); solrServer.add(docBuffer); UpdateResponse response = solrServer.commit(); if (response.getStatus() != 0) { throw new RuntimeException("Unable to add data to solr server"); } logger.debug("Submitted documents batch of size " + docBuffer.size() + " to Solr server."); docBuffer.clear(); } catch (SolrServerException ex) { throw new RuntimeException("Unable to insert documents during process", ex); } catch (SolrException ex) { throw new RuntimeException("Unable to insert documents during process", ex); } catch (IOException iox) { throw new RuntimeException("Unable to insert documents during process", iox); } }
@Override public boolean clearIndex() throws IndexException { UpdateResponse resp; try { resp = this._client.deleteByQuery(this._collection, "*:*"); resp = this._client.commit(this._collection); } catch (SolrServerException | IOException ex) { throw new IndexException("Failed to clear index", ex); } return resp.getStatus() == 0; }
@Override public boolean updateDocuments(DeleteRule rule, List<FlintDocument> documents) throws IndexException { // delete first if (rule != null) deleteDocuments(rule); // add then try { UpdateResponse resp = this._client.add(this._collection, SolrUtils.toDocuments(documents)); return resp.getStatus() == 0; } catch (SolrServerException | IOException ex) { throw new IndexException("Failed to add document(s)", ex); } }
public <T, M> void insertCatalogCollection(List<T> records, ComplexTypeConverter converter, String collectionName) throws IOException, CatalogException { List<M> solrModels = new ArrayList<>(); for (T record : records) { solrModels.add((M) converter.convertToStorageType(record)); } UpdateResponse updateResponse; try { updateResponse = solrManager.getSolrClient().addBeans(DATABASE_PREFIX + collectionName, solrModels); if (updateResponse.getStatus() == 0) { solrManager.getSolrClient().commit(DATABASE_PREFIX + collectionName); } } catch (SolrServerException e) { throw new CatalogException(e.getMessage(), e); } }
SolrServer server = new HttpSolrServer("http://localhost:8983/solr/CORE_NAME/"); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "1"); doc.addField("Name", "John"); doc.addField("RollNo", "101"); server.add(doc); UpdateResponse updateResponse = server.commit(); System.out.println(updateResponse.getStatus());
public boolean indexQuestion(int qid, String title, String content) throws IOException, SolrServerException { SolrInputDocument doc = new SolrInputDocument(); doc.setField("id", qid); doc.setField(QUESTION_TITLE_FIELD, title); doc.setField("QUESTION_CONTENT_FIELD", content); UpdateResponse response = client.add(doc, 1000); return response != null && response.getStatus() == 0; } }
private void delete(String collection, List<String> variants) throws IOException, SolrServerException { if (CollectionUtils.isNotEmpty(variants)) { UpdateResponse updateResponse = solrManager.getSolrClient().deleteById(collection, variants); if (updateResponse.getStatus() == 0) { solrManager.getSolrClient().commit(collection); } } }
@Override public boolean deleteDocuments(DeleteRule rule) throws IndexException { if (rule instanceof SolrDeleteRule) { SolrDeleteRule drule = (SolrDeleteRule) rule; try { UpdateResponse resp; if (drule.deleteByID()) { resp = this._client.deleteById(this._collection, drule.getDeleteID()); } else { resp = this._client.deleteByQuery(this._collection, drule.getDeleteQuery()); } return resp.getStatus() == 0; } catch (SolrServerException | IOException ex) { throw new IndexException("Failed to delete document(s)", ex); } } return false; }
@Test public void testSelectsEmbeddedSolrServerAndAddDocument() throws Exception { //Solr locator should select EmbeddedSolrServer only solrHome is specified SolrLocator solrLocator = new SolrLocator(new SolrMorphlineContext.Builder().build()); solrLocator.setSolrHomeDir(RESOURCES_DIR + "/solr"); solrLocator.setCollectionName("collection1"); SolrServerDocumentLoader documentLoader = (SolrServerDocumentLoader)solrLocator.getLoader(); SolrClient solrServer = documentLoader.getSolrServer(); assertTrue(solrServer instanceof EmbeddedSolrServer); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "myId"); doc.addField("text", "myValue"); solrServer.add(doc); solrServer.commit(); SolrDocument resultDoc = solrServer.getById("myId"); assertTrue(resultDoc.getFieldValues("text").contains("myValue")); UpdateResponse deleteResponse = solrServer.deleteById("myId"); assertEquals(0, deleteResponse.getStatus()); solrServer.commit(); solrServer.close(); }