Java Code Examples for org.apache.solr.client.solrj.SolrClient#queryAndStreamResponse()

The following examples show how to use org.apache.solr.client.solrj.SolrClient#queryAndStreamResponse() . 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: SolrStreamingService.java    From chronix.spark with Apache License 2.0 6 votes vote down vote up
private void initialStream(SolrQuery query, SolrClient connection) {
    try {
        SolrQuery solrQuery = query.getCopy();
        solrQuery.setRows(nrOfTimeSeriesPerBatch);
        solrQuery.setStart(currentDocumentCount);

        solrStreamingHandler.init(nrOfTimeSeriesPerBatch, currentDocumentCount);
        QueryResponse response = connection.queryAndStreamResponse(solrQuery, solrStreamingHandler);

        nrOfAvailableTimeSeries = response.getResults().getNumFound();
        queryStart = 0;//(long) response.getResponseHeader().get(ChronixSolrStorageConstants.QUERY_START_LONG);
        queryEnd = Long.MAX_VALUE;//(long) response.getResponseHeader().get(ChronixSolrStorageConstants.QUERY_END_LONG);

        needStream = false;
    } catch (SolrServerException | IOException e) {
        LOGGER.error("SolrServerException occurred while querying server.", e);
    }
}
 
Example 2
Source File: SolrStreamingService.java    From chronix.server with Apache License 2.0 6 votes vote down vote up
private void initialStream(SolrQuery query, SolrClient connection) {
    try {
        //Make a copy of the query
        SolrQuery solrQuery = query.getCopy();
        //We override the number of rows
        solrQuery.setRows(nrOfTimeSeriesPerBatch);
        //And the start
        solrQuery.setStart(currentDocumentCount);
        //init the streaming handler with
        solrStreamingHandler.init(nrOfTimeSeriesPerBatch, currentDocumentCount);
        QueryResponse response = connection.queryAndStreamResponse(solrQuery, solrStreamingHandler);
        //Set the global values
        nrOfAvailableTimeSeries = response.getResults().getNumFound();
        queryStart = (long) response.getResponseHeader().get(ChronixSolrStorageConstants.QUERY_START_LONG);
        queryEnd = (long) response.getResponseHeader().get(ChronixSolrStorageConstants.QUERY_END_LONG);
        //Data is filled. We need not stream until it is read out
        needStream = false;
    } catch (SolrServerException | IOException e) {
        LOGGER.error("SolrServerException occurred while querying server.", e);
    }
}
 
Example 3
Source File: SolrExampleStreamingBinaryHttp2Test.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testQueryAndStreamResponse() throws Exception {
  // index a simple document with one child
  SolrClient client = getSolrClient();
  client.deleteByQuery("*:*");

  SolrInputDocument child = new SolrInputDocument();
  child.addField("id", "child");
  child.addField("type_s", "child");
  child.addField("text_s", "text");

  SolrInputDocument parent = new SolrInputDocument();
  parent.addField("id", "parent");
  parent.addField("type_s", "parent");
  parent.addChildDocument(child);

  client.add(parent);
  client.commit();

  // create a query with child doc transformer
  SolrQuery query = new SolrQuery("{!parent which='type_s:parent'}text_s:text");
  query.addField("*,[child parentFilter='type_s:parent']");

  // test regular query
  QueryResponse response = client.query(query);
  assertEquals(1, response.getResults().size());
  SolrDocument parentDoc = response.getResults().get(0);
  assertEquals(1, parentDoc.getChildDocumentCount());

  // test streaming
  final List<SolrDocument> docs = new ArrayList<>();
  client.queryAndStreamResponse(query, new StreamingResponseCallback() {
    @Override
    public void streamSolrDocument(SolrDocument doc) {
      docs.add(doc);
    }

    @Override
    public void streamDocListInfo(long numFound, long start, Float maxScore) {
    }
  });

  assertEquals(1, docs.size());
  parentDoc = docs.get(0);
  assertEquals(1, parentDoc.getChildDocumentCount());
}
 
Example 4
Source File: SolrExampleStreamingBinaryTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testQueryAndStreamResponse() throws Exception {
  // index a simple document with one child
  SolrClient client = getSolrClient();
  client.deleteByQuery("*:*");

  SolrInputDocument child = new SolrInputDocument();
  child.addField("id", "child");
  child.addField("type_s", "child");
  child.addField("text_s", "text");

  SolrInputDocument parent = new SolrInputDocument();
  parent.addField("id", "parent");
  parent.addField("type_s", "parent");
  parent.addChildDocument(child);

  client.add(parent);
  client.commit();

  // create a query with child doc transformer
  SolrQuery query = new SolrQuery("{!parent which='type_s:parent'}text_s:text");
  query.addField("*,[child parentFilter='type_s:parent']");

  // test regular query
  QueryResponse response = client.query(query);
  assertEquals(1, response.getResults().size());
  SolrDocument parentDoc = response.getResults().get(0);
  assertEquals(1, parentDoc.getChildDocumentCount());

  // test streaming
  final List<SolrDocument> docs = new ArrayList<>();
  client.queryAndStreamResponse(query, new StreamingResponseCallback() {
    @Override
    public void streamSolrDocument(SolrDocument doc) {
      docs.add(doc);
    }

    @Override
    public void streamDocListInfo(long numFound, long start, Float maxScore) {
    }
  });

  assertEquals(1, docs.size());
  parentDoc = docs.get(0);
  assertEquals(1, parentDoc.getChildDocumentCount());
}