Java Code Examples for org.apache.solr.client.solrj.io.Tuple#getMaps()

The following examples show how to use org.apache.solr.client.solrj.io.Tuple#getMaps() . 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: SelectWithEvaluatorsTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected boolean assertMapOrder(List<Tuple> tuples, int... ids) throws Exception {
  int i = 0;
  for(int val : ids) {
    Tuple t = tuples.get(i);
    @SuppressWarnings({"rawtypes"})
    List<Map> tip = t.getMaps("group");
    int id = (int)tip.get(0).get("id");
    if(id != val) {
      throw new Exception("Found value:"+id+" expecting:"+val);
    }
    ++i;
  }
  return true;
}
 
Example 2
Source File: StreamingTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testReducerStream() throws Exception {

  new UpdateRequest()
      .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1")
      .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2")
      .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")
      .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")
      .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5")
      .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6")
      .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7")
      .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8")
      .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9")
      .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10")
      .commit(cluster.getSolrClient(), COLLECTIONORALIAS);

  StreamContext streamContext = new StreamContext();
  SolrClientCache solrClientCache = new SolrClientCache();
  streamContext.setSolrClientCache(solrClientCache);

  try {
    //Test with spaces in the parameter lists.
    SolrParams sParamsA = mapParams("q", "*:*", "fl", "id,a_s, a_i,  a_f", "sort", "a_s asc  ,  a_f   asc");
    CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
    ReducerStream rstream = new ReducerStream(stream,
        new FieldEqualitor("a_s"),
        new GroupOperation(new FieldComparator("a_f", ComparatorOrder.ASCENDING), 5));

    rstream.setStreamContext(streamContext);
    List<Tuple> tuples = getTuples(rstream);

    assertEquals(3, tuples.size());

    Tuple t0 = tuples.get(0);
    @SuppressWarnings({"rawtypes"})
    List<Map> maps0 = t0.getMaps("group");
    assertMaps(maps0, 0, 2, 1, 9);

    Tuple t1 = tuples.get(1);
    @SuppressWarnings({"rawtypes"})
    List<Map> maps1 = t1.getMaps("group");
    assertMaps(maps1, 3, 5, 7, 8);

    Tuple t2 = tuples.get(2);
    @SuppressWarnings({"rawtypes"})
    List<Map> maps2 = t2.getMaps("group");
    assertMaps(maps2, 4, 6);

    //Test with spaces in the parameter lists using a comparator
    sParamsA = mapParams("q", "*:*", "fl", "id,a_s, a_i,  a_f", "sort", "a_s asc  ,  a_f   asc");
    stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
    rstream = new ReducerStream(stream,
        new FieldComparator("a_s", ComparatorOrder.ASCENDING),
        new GroupOperation(new FieldComparator("a_f", ComparatorOrder.DESCENDING), 5));
    rstream.setStreamContext(streamContext);
    tuples = getTuples(rstream);

    assertEquals(3, tuples.size());

    t0 = tuples.get(0);
    maps0 = t0.getMaps("group");
    assertMaps(maps0, 9, 1, 2, 0);

    t1 = tuples.get(1);
    maps1 = t1.getMaps("group");
    assertMaps(maps1, 8, 7, 5, 3);

    t2 = tuples.get(2);
    maps2 = t2.getMaps("group");
    assertMaps(maps2, 6, 4);
  } finally {
    solrClientCache.close();
  }
}
 
Example 3
Source File: StreamingTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testParallelReducerStream() throws Exception {

  new UpdateRequest()
      .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1")
      .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2")
      .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")
      .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")
      .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5")
      .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6")
      .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7")
      .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8")
      .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9")
      .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10")
      .commit(cluster.getSolrClient(), COLLECTIONORALIAS);

  StreamContext streamContext = new StreamContext();
  SolrClientCache solrClientCache = new SolrClientCache();
  streamContext.setSolrClientCache(solrClientCache);

  try {
    SolrParams sParamsA = mapParams("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_s asc,a_f asc", "partitionKeys", "a_s", "qt", "/export");
    CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);

    ReducerStream rstream = new ReducerStream(stream,
        new FieldEqualitor("a_s"),
        new GroupOperation(new FieldComparator("a_f", ComparatorOrder.DESCENDING), 5));
    ParallelStream pstream = parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));
    attachStreamFactory(pstream);
    pstream.setStreamContext(streamContext);
    List<Tuple> tuples = getTuples(pstream);

    assertEquals(3, tuples.size());

    Tuple t0 = tuples.get(0);
    @SuppressWarnings({"rawtypes"})
    List<Map> maps0 = t0.getMaps("group");
    assertMaps(maps0, 9, 1, 2, 0);

    Tuple t1 = tuples.get(1);
    @SuppressWarnings({"rawtypes"})
    List<Map> maps1 = t1.getMaps("group");
    assertMaps(maps1, 8, 7, 5, 3);

    Tuple t2 = tuples.get(2);
    @SuppressWarnings({"rawtypes"})
    List<Map> maps2 = t2.getMaps("group");
    assertMaps(maps2, 6, 4);

    //Test Descending with Ascending subsort

    sParamsA = mapParams("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_s desc,a_f asc", "partitionKeys", "a_s", "qt", "/export");
    stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);

    rstream = new ReducerStream(stream,
        new FieldEqualitor("a_s"),
        new GroupOperation(new FieldComparator("a_f", ComparatorOrder.ASCENDING), 3));
    pstream = parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.DESCENDING));
    attachStreamFactory(pstream);
    pstream.setStreamContext(streamContext);
    tuples = getTuples(pstream);

    assertEquals(3, tuples.size());

    t0 = tuples.get(0);
    maps0 = t0.getMaps("group");
    assertMaps(maps0, 4, 6);

    t1 = tuples.get(1);
    maps1 = t1.getMaps("group");
    assertMaps(maps1, 3, 5, 7);

    t2 = tuples.get(2);
    maps2 = t2.getMaps("group");
    assertMaps(maps2, 0, 2, 1);
  } finally {
    solrClientCache.close();
  }
}