Java Code Examples for org.apache.solr.client.solrj.impl.HttpSolrClient#setRequestWriter()

The following examples show how to use org.apache.solr.client.solrj.impl.HttpSolrClient#setRequestWriter() . 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 vote down vote up
@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 vote down vote up
@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: SolrExampleXMLTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: TestBatchUpdate.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 vote down vote up
@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 vote down vote up
@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: TestSolrJErrorHandling.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithXml() throws Exception {
  HttpSolrClient client = (HttpSolrClient) getSolrClient();
  client.setRequestWriter(new RequestWriter());
  client.deleteByQuery("*:*"); // delete everything!
  doIt(client);
}
 
Example 8
Source File: TestSolrJErrorHandling.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithBinary() throws Exception {
  HttpSolrClient client = (HttpSolrClient) getSolrClient();
  client.setRequestWriter(new BinaryRequestWriter());
  client.deleteByQuery("*:*"); // delete everything!
  doIt(client);
}
 
Example 9
Source File: ChronixSolrCloudStorage.java    From chronix.spark with Apache License 2.0 5 votes vote down vote up
/**
 * Fetches a stream of time series only from a single node with HttpSolrClient.
 *
 * @param shardUrl
 * @param query
 * @param converter
 * @return
 */
private Stream<MetricTimeSeries> streamWithHttpSolrClient(String shardUrl,
                                                          SolrQuery query,
                                                          TimeSeriesConverter<MetricTimeSeries> converter) {
    HttpSolrClient solrClient = getSingleNodeSolrClient(shardUrl);
    solrClient.setRequestWriter(new BinaryRequestWriter());
    query.set("distrib", false);
    LoggerFactory.getLogger(ChronixSolrCloudStorage.class).debug("Streaming data from solr using converter {}, Solr Client {}, and Solr Query {}", converter, solrClient, query);
    SolrStreamingService<MetricTimeSeries> solrStreamingService = new SolrStreamingService<>(converter, query, solrClient, nrOfDocumentPerBatch);
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(solrStreamingService, Spliterator.SIZED), false);
}