Java Code Examples for org.apache.solr.client.solrj.impl.HttpSolrClient#setParser()
The following examples show how to use
org.apache.solr.client.solrj.impl.HttpSolrClient#setParser() .
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: SolrExampleBinaryTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public SolrClient createNewSolrClient() { try { // setup the server... String url = jetty.getBaseUrl().toString() + "/collection1"; HttpSolrClient client = getHttpSolrClient(url, DEFAULT_CONNECTION_TIMEOUT); client.setUseMultiPartPost(random().nextBoolean()); // where the magic happens client.setParser(new BinaryResponseParser()); client.setRequestWriter(new BinaryRequestWriter()); return client; } catch( Exception ex ) { throw new RuntimeException( ex ); } }
Example 2
Source File: SolrSchemalessExampleTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public SolrClient createNewSolrClient() { try { // setup the server... String url = jetty.getBaseUrl().toString() + "/collection1"; HttpSolrClient client = getHttpSolrClient(url, DEFAULT_CONNECTION_TIMEOUT); client.setUseMultiPartPost(random().nextBoolean()); if (random().nextBoolean()) { client.setParser(new BinaryResponseParser()); client.setRequestWriter(new BinaryRequestWriter()); } return client; } catch (Exception ex) { throw new RuntimeException(ex); } }
Example 3
Source File: AmbariInfraWithStormLogSearchTest.java From streamline with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { logSearch = new AmbariInfraWithStormLogSearch(); Map<String, Object> conf = new HashMap<>(); buildTestSolrApiUrl = "http://localhost:18886" + TEST_SOLR_API_PATH; conf.put(AmbariInfraWithStormLogSearch.SOLR_API_URL_KEY, buildTestSolrApiUrl); conf.put(AmbariInfraWithStormLogSearch.COLLECTION_NAME, TEST_COLLECTION_NAME); logSearch.init(conf); // we are doing some hack to change parser, since default wt (javabin) would be faster // but not good to construct custom result by ourselves HttpSolrClient solrClient = Deencapsulation.getField(logSearch, "solr"); solrClient.setParser(new XMLResponseParser()); }
Example 4
Source File: SolrConfigurationService.java From aem-solr-search with Apache License 2.0 | 6 votes |
private SolrClient getStandaloneIndexSolrClient() { if (StringUtils.isEmpty(solrMaster)) { try { throw new AEMSolrSearchException( "Initialization failed. The property 'solr-master' is missing for Standalone mode."); } catch (AEMSolrSearchException e) { LOG.error("Solr client initialization failed.", e); } } LOG.debug("Creating HttpSolrClient using solrMaster '{}'", solrMaster); HttpSolrClient client = new HttpSolrClient(solrMaster); client.setParser(new XMLResponseParser()); return client; }
Example 5
Source File: SolrExampleXMLTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public SolrClient createNewSolrClient() { try { String url = jetty.getBaseUrl().toString() + "/collection1"; HttpSolrClient client = getHttpSolrClient(url, DEFAULT_CONNECTION_TIMEOUT); client.setUseMultiPartPost(random().nextBoolean()); client.setParser(new XMLResponseParser()); client.setRequestWriter(new RequestWriter()); return client; } catch (Exception ex) { throw new RuntimeException(ex); } }
Example 6
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 7
Source File: SolrClientFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
public HttpSolrClient createStandaloneSolrClient(String solrHost) { NoOpResponseParser responseParser = new NoOpResponseParser(); responseParser.setWriterType("json"); HttpSolrClient.Builder standaloneBuilder = new HttpSolrClient.Builder(); standaloneBuilder.withBaseSolrUrl(solrHost); standaloneBuilder.withConnectionTimeout(settings.getHttpConnectionTimeout()) .withSocketTimeout(settings.getHttpReadTimeout()); HttpSolrClient httpSolrClient = standaloneBuilder.build(); httpSolrClient.setParser(responseParser); return httpSolrClient; }
Example 8
Source File: DistributedQueryElevationComponentTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test @ShardsFixed(num = 3) public void test() throws Exception { del("*:*"); indexr(id,"1", "int_i", "1", "text", "XXXX XXXX", "field_t", "anything"); indexr(id,"2", "int_i", "2", "text", "YYYY YYYY", "plow_t", "rake"); indexr(id,"3", "int_i", "3", "text", "ZZZZ ZZZZ"); indexr(id,"4", "int_i", "4", "text", "XXXX XXXX"); indexr(id,"5", "int_i", "5", "text", "ZZZZ ZZZZ ZZZZ"); indexr(id,"6", "int_i", "6", "text", "ZZZZ"); index_specific(2, id, "7", "int_i", "7", "text", "solr"); commit(); handle.put("explain", SKIPVAL); handle.put("debug", SKIPVAL); handle.put("maxScore", SKIPVAL); handle.put("timestamp", SKIPVAL); handle.put("score", SKIPVAL); handle.put("wt", SKIP); handle.put("distrib", SKIP); handle.put("shards.qt", SKIP); handle.put("shards", SKIP); handle.put("q", SKIP); handle.put("qt", SKIP); query("q", "*:*", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", "sort", "id desc", CommonParams.FL, "id, score, [elevated]"); query("q", "ZZZZ", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "*, [elevated]", "forceElevation", "true", "sort", "int_i desc"); query("q", "solr", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "*, [elevated]", "forceElevation", "true", "sort", "int_i asc"); query("q", "ZZZZ", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "*, [elevated]", "forceElevation", "true", "sort", "id desc"); // See SOLR-4854 for background on following test code // Uses XML response format by default QueryResponse response = query("q", "XXXX", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "id, [elevated]", "enableElevation", "true", "forceElevation", "true", "elevateIds", "6", "sort", "id desc"); assertTrue(response.getResults().getNumFound() > 0); SolrDocument document = response.getResults().get(0); assertEquals("6", document.getFieldValue("id")); assertEquals(true, document.getFieldValue("[elevated]")); // Force javabin format final String clientUrl = ((HttpSolrClient)clients.get(0)).getBaseURL(); HttpSolrClient client = getHttpSolrClient(clientUrl); client.setParser(new BinaryResponseParser()); SolrQuery solrQuery = new SolrQuery("XXXX").setParam("qt", "/elevate").setParam("shards.qt", "/elevate").setRows(500).setFields("id,[elevated]") .setParam("enableElevation", "true").setParam("forceElevation", "true").setParam("elevateIds", "6", "wt", "javabin") .setSort("id", SolrQuery.ORDER.desc); setDistributedParams(solrQuery); response = client.query(solrQuery); client.close(); assertTrue(response.getResults().getNumFound() > 0); document = response.getResults().get(0); assertEquals("6", document.getFieldValue("id")); assertEquals(true, document.getFieldValue("[elevated]")); }