List of usage examples for org.apache.solr.client.solrj.request UpdateRequest getDeleteById
public List<String> getDeleteById()
From source file:org.codelibs.elasticsearch.solr.solr.JavaBinUpdateRequestCodec.java
License:Apache License
/** * Converts an UpdateRequest to a NamedList which can be serialized to the * given OutputStream in the javabin format * * @param updateRequest/*from ww w. j av a 2s .c om*/ * the UpdateRequest to be written out * @param os * the OutputStream to which the request is to be written * * @throws IOException * in case of an exception during marshalling or writing to the * stream */ public void marshal(final UpdateRequest updateRequest, final OutputStream os) throws IOException { final NamedList nl = new NamedList(); final NamedList params = solrParamsToNamedList(updateRequest.getParams()); if (updateRequest.getCommitWithin() != -1) { params.add("commitWithin", updateRequest.getCommitWithin()); } Iterator<SolrInputDocument> docIter = null; if (updateRequest.getDocuments() != null) { docIter = updateRequest.getDocuments().iterator(); } if (updateRequest.getDocIterator() != null) { docIter = updateRequest.getDocIterator(); } nl.add("params", params);// 0: params nl.add("delById", updateRequest.getDeleteById()); nl.add("delByQ", updateRequest.getDeleteQuery()); nl.add("docs", docIter); final JavaBinCodec codec = new JavaBinCodec(); codec.marshal(nl, os); }
From source file:org.teiid.translator.solr.TestSolrUpdateExecution.java
License:Open Source License
@Test public void testSimpleDelete() throws Exception { String query = "Delete from example where name = 'teiid'"; SolrDocument doc = new SolrDocument(); doc.addField("price", 1.10f); doc.addField("weight", 2.23f); doc.addField("popularity", 5); doc.addField("name", "teiid"); doc.addField("nis", "any"); SolrDocumentList list = new SolrDocumentList(); list.add(doc);/* ww w . ja v a 2s. c o m*/ QueryResponse queryResponse = Mockito.mock(QueryResponse.class); Mockito.stub(queryResponse.getResults()).toReturn(list); QueryResponse queryResponse2 = Mockito.mock(QueryResponse.class); Mockito.stub(queryResponse2.getResults()).toReturn(new SolrDocumentList()); UpdateRequest request = helpUpdate(query, queryResponse, queryResponse2); List<SolrInputDocument> docs = request.getDocuments(); UpdateRequest expected = new UpdateRequest(); expected.deleteById("teiid"); assertEquals(expected.getDeleteById().toString(), request.getDeleteById().toString()); }
From source file:sk.datalan.solr.impl.ConcurrentUpdateSolrServer.java
License:Apache License
@Override public NamedList<Object> request(final SolrRequest request) throws SolrServerException, IOException { if (!(request instanceof UpdateRequest)) { return server.request(request); }/*from ww w .ja v a 2s .co m*/ UpdateRequest req = (UpdateRequest) request; // this happens for commit... if (streamDeletes) { if ((req.getDocuments() == null || req.getDocuments().isEmpty()) && (req.getDeleteById() == null || req.getDeleteById().isEmpty()) && (req.getDeleteByIdMap() == null || req.getDeleteByIdMap().isEmpty())) { if (req.getDeleteQuery() == null) { blockUntilFinished(); return server.request(request); } } } else { if ((req.getDocuments() == null || req.getDocuments().isEmpty())) { blockUntilFinished(); return server.request(request); } } SolrParams params = req.getParams(); if (params != null) { // check if it is waiting for the searcher if (params.getBool(UpdateParams.WAIT_SEARCHER, false)) { log.info("blocking for commit/optimize"); blockUntilFinished(); // empty the queue return server.request(request); } } try { CountDownLatch tmpLock = lock; if (tmpLock != null) { tmpLock.await(); } boolean success = queue.offer(req); for (;;) { synchronized (runners) { if (runners.isEmpty() || (queue.remainingCapacity() < queue.size() // queue // is // half // full // and // we // can // add // more // runners && runners.size() < threadCount)) { // We need more runners, so start a new one. Runner r = new Runner(); runners.add(r); scheduler.execute(r); } else { // break out of the retry loop if we added the element to the queue // successfully, *and* // while we are still holding the runners lock to prevent race // conditions. if (success) break; } } // Retry to add to the queue w/o the runners lock held (else we risk // temporary deadlock) // This retry could also fail because // 1) existing runners were not able to take off any new elements in the // queue // 2) the queue was filled back up since our last try // If we succeed, the queue may have been completely emptied, and all // runners stopped. // In all cases, we should loop back to the top to see if we need to // start more runners. // if (!success) { success = queue.offer(req, 100, TimeUnit.MILLISECONDS); } } } catch (InterruptedException e) { log.error("interrupted", e); throw new IOException(e.getLocalizedMessage()); } // RETURN A DUMMY result NamedList<Object> dummy = new NamedList<>(); dummy.add("NOTE", "the request is processed in a background stream"); return dummy; }