Java Code Examples for org.apache.solr.client.solrj.impl.HttpSolrClient#deleteByQuery()
The following examples show how to use
org.apache.solr.client.solrj.impl.HttpSolrClient#deleteByQuery() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrProductSearch.java From scipio-erp with Apache License 2.0 | 6 votes |
private static Map<String, Object> updateToSolrCoreMultiRemove(DispatchContext dctx, Map<String, Object> context, Collection<String> productIdList, HttpSolrClient client) { Map<String, Object> result; // NOTE: log this as info because it's the only log line try { StringBuilder query = new StringBuilder(); for(String productId : productIdList) { query.append(' '); query.append(SolrExprUtil.escapeTermFull(productId)); } if (Debug.infoOn()) { Debug.logInfo("Solr: updateToSolr: Removing " + productIdList.size() + " products from index: " + makeLogIdList(productIdList), module); } client.deleteByQuery("productId:(" + StringUtils.join(productIdList, ' ') + ")"); client.commit(); result = ServiceUtil.returnSuccess(); result.put("numRemoved", productIdList.size()); result.put("numFailures", 0); } catch (Exception e) { Debug.logError(e, "Solr: updateToSolr: Error removing " + productIdList.size() + " products (" + makeLogIdList(productIdList) + ") from solr index: " + e.getMessage(), module); result = ServiceUtil.returnError("Error removing " + productIdList.size() + " products (" + makeLogIdList(productIdList) + ") from solr index: " + e.toString()); } return result; }
Example 2
Source File: SolrSchemalessExampleTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testArbitraryJsonIndexing() throws Exception { HttpSolrClient client = (HttpSolrClient) getSolrClient(); client.deleteByQuery("*:*"); client.commit(); assertNumFound("*:*", 0); // make sure it got in // two docs, one with uniqueKey, another without it String json = "{\"id\":\"abc1\", \"name\": \"name1\"} {\"name\" : \"name2\"}"; HttpClient httpClient = client.getHttpClient(); HttpPost post = new HttpPost(client.getBaseURL() + "/update/json/docs"); post.setHeader("Content-Type", "application/json"); post.setEntity(new InputStreamEntity( new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), -1)); HttpResponse response = httpClient.execute(post, HttpClientUtil.createNewHttpClientRequestContext()); Utils.consumeFully(response.getEntity()); assertEquals(200, response.getStatusLine().getStatusCode()); client.commit(); assertNumFound("*:*", 2); }
Example 3
Source File: SolrProductSearch.java From scipio-erp with Apache License 2.0 | 5 votes |
private static Map<String, Object> removeFromSolrCore(DispatchContext dctx, Map<String, Object> context, String productId) { Map<String, Object> result; // NOTE: log this as info because it's the only log line Debug.logInfo("Solr: removeFromSolr: Removing productId '" + productId + "' from index", module); try { HttpSolrClient client = SolrUtil.getUpdateHttpSolrClient((String) context.get("core")); client.deleteByQuery("productId:" + SolrExprUtil.escapeTermFull(productId)); client.commit(); result = ServiceUtil.returnSuccess(); } catch (Exception e) { Debug.logError(e, "Solr: removeFromSolr: Error removing product '" + productId + "' from solr index: " + e.getMessage(), module); result = ServiceUtil.returnError("Error removing product '" + productId + "' from solr index: " + e.toString()); } return result; }
Example 4
Source File: TestBatchUpdate.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testWithXml() throws Exception { HttpSolrClient client = (HttpSolrClient) getSolrClient(); client.setRequestWriter(new RequestWriter()); client.deleteByQuery("*:*"); // delete everything! doIt(client); }
Example 5
Source File: TestBatchUpdate.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testWithBinary()throws Exception{ HttpSolrClient client = (HttpSolrClient) getSolrClient(); client.setRequestWriter(new BinaryRequestWriter()); client.deleteByQuery("*:*"); // delete everything! doIt(client); }
Example 6
Source File: TestBatchUpdate.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testWithBinaryBean()throws Exception{ HttpSolrClient client = (HttpSolrClient) getSolrClient(); client.setRequestWriter(new BinaryRequestWriter()); client.deleteByQuery("*:*"); // delete everything! final int[] counter = new int[1]; counter[0] = 0; client.addBeans(new Iterator<Bean>() { @Override public boolean hasNext() { return counter[0] < numdocs; } @Override public Bean next() { Bean bean = new Bean(); bean.id = "" + (++counter[0]); bean.cat = "foocat"; return bean; } @Override public void remove() { //do nothing } }); client.commit(); SolrQuery query = new SolrQuery("*:*"); QueryResponse response = client.query(query); assertEquals(0, response.getStatus()); assertEquals(numdocs, response.getResults().getNumFound()); }
Example 7
Source File: SolrExampleTests.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @Monster("Only useful to verify the performance of serialization+ deserialization") // ant -Dtestcase=SolrExampleBinaryTest -Dtests.method=testQueryPerf -Dtests.monster=true test public void testQueryPerf() throws Exception { HttpSolrClient client = (HttpSolrClient) getSolrClient(); client.deleteByQuery("*:*"); client.commit(); ArrayList<SolrInputDocument> docs = new ArrayList<>(); int id = 0; docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "apple", "cat", "a", "inStock", true, "popularity", 12, "price", .017)); docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "lg", "cat", "a", "inStock", false, "popularity", 13, "price", 16.04)); docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "samsung", "cat", "a", "inStock", true, "popularity", 14, "price", 12.34)); docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "lg", "cat", "b", "inStock", false, "popularity", 24, "price", 51.39)); docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "nokia", "cat", "b", "inStock", true, "popularity", 28, "price", 131.39)); docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "ztc", "cat", "a", "inStock", false, "popularity", 32)); docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "htc", "cat", "a", "inStock", true, "popularity", 31, "price", 131.39)); docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "apple", "cat", "b", "inStock", false, "popularity", 36)); docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "lg", "cat", "b", "inStock", true, "popularity", 37, "price", 1.39)); docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "ztc", "cat", "b", "inStock", false, "popularity", 38, "price", 47.98)); docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "ztc", "cat", "b", "inStock", true, "popularity", -38)); docs.add(makeTestDoc("id", id++, "cat", "b")); // something not matching all fields client.add(docs); client.commit(); //this sets the cache QueryResponse rsp = getSolrClient().query(new SolrQuery("*:*").setRows(20)); RTimer timer = new RTimer(); int count = 10000; log.info("Started perf test...."); for(int i=0;i< count; i++){ rsp = getSolrClient().query(new SolrQuery("*:*").setRows(20)); } if (log.isInfoEnabled()) { log.info("time taken to execute {} queries is {} ms", count, timer.getTime()); } }
Example 8
Source File: TestSolrJErrorHandling.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testWithXml() throws Exception { HttpSolrClient client = (HttpSolrClient) getSolrClient(); client.setRequestWriter(new RequestWriter()); client.deleteByQuery("*:*"); // delete everything! doIt(client); }
Example 9
Source File: TestSolrJErrorHandling.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testWithBinary() throws Exception { HttpSolrClient client = (HttpSolrClient) getSolrClient(); client.setRequestWriter(new BinaryRequestWriter()); client.deleteByQuery("*:*"); // delete everything! doIt(client); }
Example 10
Source File: SolrExampleJettyTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Ignore public void testUtf8QueryPerf() throws Exception { HttpSolrClient client = (HttpSolrClient) getSolrClient(); client.deleteByQuery("*:*"); client.commit(); List<SolrInputDocument> docs = new ArrayList<>(); for (int i = 0; i < 10; i++) { SolrInputDocument doc2 = new SolrInputDocument(); doc2.addField("id", "" + i); doc2.addField("fld1_s", "1 value 1 value 1 value 1 value 1 value 1 value 1 value "); doc2.addField("fld2_s", "2 value 2 value 2 value 2 value 2 value 2 value 2 value 2 value 2 value 2 value "); doc2.addField("fld3_s", "3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value 3 value "); doc2.addField("fld4_s", "4 value 4 value 4 value 4 value 4 value 4 value 4 value 4 value 4 value "); doc2.addField("fld5_s", "5 value 5 value 5 value 5 value 5 value 5 value 5 value 5 value 5 value 5 value 5 value 5 value "); docs.add(doc2); } client.add(docs); client.commit(); QueryResponse rsp = client.query(new SolrQuery("*:*")); assertEquals(10, rsp.getResults().getNumFound()); client.setParser(new BinaryResponseParser() { @Override public NamedList<Object> processResponse(InputStream body, String encoding) { try { IOUtils.skip(body, 1024 * 1000); } catch (IOException e) { e.printStackTrace(); } return rsp.getResponse(); } }); runQueries(client, 1000, true); /*BinaryResponseWriter.useUtf8CharSeq = false; System.out.println("BinaryResponseWriter.useUtf8CharSeq = " + BinaryResponseWriter.useUtf8CharSeq); runQueries(client, 10000, false); BinaryResponseWriter.useUtf8CharSeq = true; System.out.println("BinaryResponseWriter.useUtf8CharSeq = " + BinaryResponseWriter.useUtf8CharSeq);*/ runQueries(client, 10000, false); }
Example 11
Source File: SolrSchemalessExampleTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings({"unchecked"}) public void testFieldMutating() throws Exception { HttpSolrClient client = (HttpSolrClient) getSolrClient(); client.deleteByQuery("*:*"); client.commit(); assertNumFound("*:*", 0); // make sure it got in // two docs, one with uniqueKey, another without it String json = "{\"name one\": \"name\"} " + "{\"name two\" : \"name\"}" + "{\"first-second\" : \"name\"}" + "{\"x+y\" : \"name\"}" + "{\"p%q\" : \"name\"}" + "{\"p.q\" : \"name\"}" + "{\"a&b\" : \"name\"}" ; HttpClient httpClient = client.getHttpClient(); HttpPost post = new HttpPost(client.getBaseURL() + "/update/json/docs"); post.setHeader("Content-Type", "application/json"); post.setEntity(new InputStreamEntity( new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), -1)); HttpResponse response = httpClient.execute(post); assertEquals(200, response.getStatusLine().getStatusCode()); client.commit(); List<String> expected = Arrays.asList( "name_one", "name__two", "first-second", "a_b", "p_q", "p.q", "x_y"); @SuppressWarnings({"rawtypes"}) HashSet set = new HashSet(); QueryResponse rsp = assertNumFound("*:*", expected.size()); for (SolrDocument doc : rsp.getResults()) set.addAll(doc.getFieldNames()); for (String s : expected) { assertTrue(s+" not created "+ rsp ,set.contains(s) ); } }
Example 12
Source File: TestSolrJErrorHandling.java From lucene-solr with Apache License 2.0 | 4 votes |
void doIt(HttpSolrClient client) throws Exception { client.deleteByQuery("*:*"); doThreads(client,10,100); // doSingle(client, 1); }
Example 13
Source File: CaseController.java From skywalking with Apache License 2.0 | 4 votes |
public String deleteByQuery(HttpSolrClient client) throws SolrServerException, IOException { client.deleteByQuery(collection, "*:*"); // return "Success"; }