Search in sources :

Example 76 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class TestSQLHandler method testBasicGroupingFacets.

private void testBasicGroupingFacets() throws Exception {
    try {
        CloudJettyRunner jetty = this.cloudJettys.get(0);
        del("*:*");
        commit();
        indexr("id", "1", "text", "XXXX XXXX", "str_s", "a", "field_i", "7");
        indexr("id", "2", "text", "XXXX XXXX", "str_s", "b", "field_i", "8");
        indexr("id", "3", "text", "XXXX XXXX", "str_s", "a", "field_i", "20");
        indexr("id", "4", "text", "XXXX XXXX", "str_s", "b", "field_i", "11");
        indexr("id", "5", "text", "XXXX XXXX", "str_s", "c", "field_i", "30");
        indexr("id", "6", "text", "XXXX XXXX", "str_s", "c", "field_i", "40");
        indexr("id", "7", "text", "XXXX XXXX", "str_s", "c", "field_i", "50");
        indexr("id", "8", "text", "XXXX XXXX", "str_s", "c", "field_i", "60");
        indexr("id", "9", "text", "XXXX XXXY", "str_s", "d", "field_i", "70");
        commit();
        SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s " + "order by sum(field_i) asc limit 2");
        SolrStream solrStream = new SolrStream(jetty.url, sParams);
        List<Tuple> tuples = getTuples(solrStream);
        //Only two results because of the limit.
        assert (tuples.size() == 2);
        Tuple tuple;
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 9.5D);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("a"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 27);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 7);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 20);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 13.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s " + "order by sum(field_i) asc limit 2");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        //Only two results because of the limit.
        assert (tuples.size() == 2);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 10);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("a"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 27);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 7);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 20);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 14);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where (text='XXXX' AND NOT (text='XXXY')) " + "group by str_s order by str_s desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("c"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 4);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 180);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 30);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 60);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 45);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 9.5D);
        tuple = tuples.get(2);
        assert (tuple.get("str_s").equals("a"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 27);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 7);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 20);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 13.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s as myString, count(*), sum(field_i) as mySum, min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where (text='XXXX' AND NOT (text='XXXY')) " + "group by str_s order by myString desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        assert (tuple.get("myString").equals("c"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 4);
        assert (tuple.getDouble("mySum") == 180);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 30);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 60);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 45);
        tuple = tuples.get(1);
        assert (tuple.get("myString").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        assert (tuple.getDouble("mySum") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 9.5D);
        tuple = tuples.get(2);
        assert (tuple.get("myString").equals("a"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        assert (tuple.getDouble("mySum") == 27);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 7);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 20);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 13.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s having sum(field_i) = 19");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 9.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s " + "having ((sum(field_i) = 19) AND (min(field_i) = 8))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 9.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i) as mySum, min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s " + "having ((sum(field_i) = 19) AND (min(field_i) = 8))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        assert (tuple.getDouble("mySum") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 9.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s " + "having ((sum(field_i) = 19) AND (min(field_i) = 100))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 0);
    } finally {
        delete();
    }
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrStream(org.apache.solr.client.solrj.io.stream.SolrStream) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 77 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class TestSQLHandler method testBasicGrouping.

private void testBasicGrouping() throws Exception {
    try {
        CloudJettyRunner jetty = this.cloudJettys.get(0);
        del("*:*");
        commit();
        indexr("id", "1", "text", "XXXX XXXX", "str_s", "a", "field_i", "7");
        indexr("id", "2", "text", "XXXX XXXX", "str_s", "b", "field_i", "8");
        indexr("id", "3", "text", "XXXX XXXX", "str_s", "a", "field_i", "20");
        indexr("id", "4", "text", "XXXX XXXX", "str_s", "b", "field_i", "11");
        indexr("id", "5", "text", "XXXX XXXX", "str_s", "c", "field_i", "30");
        indexr("id", "6", "text", "XXXX XXXX", "str_s", "c", "field_i", "40");
        indexr("id", "7", "text", "XXXX XXXX", "str_s", "c", "field_i", "50");
        indexr("id", "8", "text", "XXXX XXXX", "str_s", "c", "field_i", "60");
        indexr("id", "9", "text", "XXXX XXXY", "str_s", "d", "field_i", "70");
        commit();
        SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), avg(field_i) from collection1 where text='XXXX' group by str_s order by sum(field_i) asc limit 2");
        SolrStream solrStream = new SolrStream(jetty.url, sParams);
        List<Tuple> tuples = getTuples(solrStream);
        //Only two results because of the limit.
        assert (tuples.size() == 2);
        Tuple tuple;
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 10);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("a"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 27);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 7);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 20);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 14);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), cast(avg(1.0 * field_i) as float) as blah from collection1 where text='XXXX' group by str_s order by sum(field_i) asc limit 2");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        //Only two results because of the limit.
        assert (tuples.size() == 2);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("blah") == 9.5);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("a"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 27);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 7);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 20);
        //avg(field_i)
        assert (tuple.getDouble("blah") == 13.5);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s as myString, count(*), sum(field_i) as mySum, min(field_i), max(field_i), avg(field_i)  from collection1 where text='XXXX' group by str_s order by mySum asc limit 2");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        //Only two results because of the limit.
        assert (tuples.size() == 2);
        tuple = tuples.get(0);
        assert (tuple.get("myString").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        assert (tuple.getDouble("mySum") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 10);
        tuple = tuples.get(1);
        assert (tuple.get("myString").equals("a"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        assert (tuple.getDouble("mySum") == 27);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 7);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 20);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 14);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "avg(field_i) from collection1 where (text='XXXX' AND NOT ((text='XXXY') AND (text='XXXY' OR text='XXXY'))) " + "group by str_s order by str_s desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("c"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 4);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 180);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 30);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 60);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 45);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 10D);
        tuple = tuples.get(2);
        assert (tuple.get("str_s").equals("a"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 27);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 7);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 20);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 14);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s as myString, count(*) as myCount, sum(field_i) as mySum, min(field_i) as myMin, " + "max(field_i) as myMax, avg(field_i) as myAvg from collection1 " + "where (text='XXXX' AND NOT (text='XXXY')) group by str_s order by str_s desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        assert (tuple.get("myString").equals("c"));
        assert (tuple.getDouble("myCount") == 4);
        assert (tuple.getDouble("mySum") == 180);
        assert (tuple.getDouble("myMin") == 30);
        assert (tuple.getDouble("myMax") == 60);
        assert (tuple.getDouble("myAvg") == 45);
        tuple = tuples.get(1);
        assert (tuple.get("myString").equals("b"));
        assert (tuple.getDouble("myCount") == 2);
        assert (tuple.getDouble("mySum") == 19);
        assert (tuple.getDouble("myMin") == 8);
        assert (tuple.getDouble("myMax") == 11);
        assert (tuple.getDouble("myAvg") == 10);
        tuple = tuples.get(2);
        assert (tuple.get("myString").equals("a"));
        assert (tuple.getDouble("myCount") == 2);
        assert (tuple.getDouble("mySum") == 27);
        assert (tuple.getDouble("myMin") == 7);
        assert (tuple.getDouble("myMax") == 20);
        assert (tuple.getDouble("myAvg") == 14);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), avg(field_i) " + "from collection1 where text='XXXX' group by str_s having sum(field_i) = 19");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 10);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), avg(field_i) " + "from collection1 where text='XXXX' group by str_s having ((sum(field_i) = 19) AND (min(field_i) = 8))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 10);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i) as mySum, min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s " + "having ((sum(field_i) = 19) AND (min(field_i) = 8))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        assert (tuple.getDouble("mySum") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 10);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s " + "having ((sum(field_i) = 19) AND (min(field_i) = 100))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 0);
    } finally {
        delete();
    }
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrStream(org.apache.solr.client.solrj.io.stream.SolrStream) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 78 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class TestSQLHandler method testAggregatesWithoutGrouping.

private void testAggregatesWithoutGrouping() throws Exception {
    CloudJettyRunner jetty = this.cloudJettys.get(0);
    del("*:*");
    commit();
    indexr(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1");
    indexr(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2");
    indexr(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3");
    indexr(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4");
    indexr(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5");
    indexr(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6");
    indexr(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7");
    indexr(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8");
    indexr(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9");
    indexr(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10");
    commit();
    SolrParams sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select count(*), sum(a_i), min(a_i), max(a_i), cast(avg(1.0 * a_i) as float), sum(a_f), " + "min(a_f), max(a_f), avg(a_f) from collection1");
    SolrStream solrStream = new SolrStream(jetty.url, sParams);
    List<Tuple> tuples = getTuples(solrStream);
    assert (tuples.size() == 1);
    //Test Long and Double Sums
    Tuple tuple = tuples.get(0);
    //count(*)
    Double count = tuple.getDouble("EXPR$0");
    //sum(a_i)
    Double sumi = tuple.getDouble("EXPR$1");
    //min(a_i)
    Double mini = tuple.getDouble("EXPR$2");
    //max(a_i)
    Double maxi = tuple.getDouble("EXPR$3");
    //avg(a_i)
    Double avgi = tuple.getDouble("EXPR$4");
    //sum(a_f)
    Double sumf = tuple.getDouble("EXPR$5");
    //min(a_f)
    Double minf = tuple.getDouble("EXPR$6");
    //max(a_f)
    Double maxf = tuple.getDouble("EXPR$7");
    //avg(a_f)
    Double avgf = tuple.getDouble("EXPR$8");
    assertTrue(count == 10);
    assertTrue(sumi == 70);
    assertTrue(mini == 0.0D);
    assertTrue(maxi == 14.0D);
    assertTrue(avgi == 7.0D);
    assertTrue(sumf == 55.0D);
    assertTrue(minf == 1.0D);
    assertTrue(maxf == 10.0D);
    assertTrue(avgf == 5.5D);
    sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select count(*) as myCount, sum(a_i) as mySum, min(a_i) as myMin, max(a_i) as myMax, " + "cast(avg(1.0 * a_i) as float) as myAvg, sum(a_f), min(a_f), max(a_f), avg(a_f) from collection1");
    solrStream = new SolrStream(jetty.url, sParams);
    tuples = getTuples(solrStream);
    assert (tuples.size() == 1);
    //Test Long and Double Sums
    tuple = tuples.get(0);
    count = tuple.getDouble("myCount");
    sumi = tuple.getDouble("mySum");
    mini = tuple.getDouble("myMin");
    maxi = tuple.getDouble("myMax");
    avgi = tuple.getDouble("myAvg");
    //sum(a_f)
    sumf = tuple.getDouble("EXPR$5");
    //min(a_f)
    minf = tuple.getDouble("EXPR$6");
    //max(a_f)
    maxf = tuple.getDouble("EXPR$7");
    //avg(a_f)
    avgf = tuple.getDouble("EXPR$8");
    assertTrue(count == 10);
    assertTrue(mini == 0.0D);
    assertTrue(maxi == 14.0D);
    assertTrue(sumi == 70);
    assertTrue(avgi == 7.0D);
    assertTrue(sumf == 55.0D);
    assertTrue(minf == 1.0D);
    assertTrue(maxf == 10.0D);
    assertTrue(avgf == 5.5D);
    //Test without cast on average int field
    sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select count(*) as myCount, sum(a_i) as mySum, min(a_i) as myMin, max(a_i) as myMax, " + "avg(a_i) as myAvg, sum(a_f), min(a_f), max(a_f), avg(a_f) from collection1");
    solrStream = new SolrStream(jetty.url, sParams);
    tuples = getTuples(solrStream);
    assert (tuples.size() == 1);
    //Test Long and Double Sums
    tuple = tuples.get(0);
    count = tuple.getDouble("myCount");
    sumi = tuple.getDouble("mySum");
    mini = tuple.getDouble("myMin");
    maxi = tuple.getDouble("myMax");
    avgi = tuple.getDouble("myAvg");
    assertTrue(tuple.get("myAvg") instanceof Long);
    //sum(a_f)
    sumf = tuple.getDouble("EXPR$5");
    //min(a_f)
    minf = tuple.getDouble("EXPR$6");
    //max(a_f)
    maxf = tuple.getDouble("EXPR$7");
    //avg(a_f)
    avgf = tuple.getDouble("EXPR$8");
    assertTrue(count == 10);
    assertTrue(mini == 0.0D);
    assertTrue(maxi == 14.0D);
    assertTrue(sumi == 70);
    assertTrue(avgi == 7);
    assertTrue(sumf == 55.0D);
    assertTrue(minf == 1.0D);
    assertTrue(maxf == 10.0D);
    assertTrue(avgf == 5.5D);
    // Test where clause hits
    sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select count(*), sum(a_i), min(a_i), max(a_i), cast(avg(1.0 * a_i) as float), sum(a_f), " + "min(a_f), max(a_f), avg(a_f) from collection1 where id = 2");
    solrStream = new SolrStream(jetty.url, sParams);
    tuples = getTuples(solrStream);
    assert (tuples.size() == 1);
    tuple = tuples.get(0);
    //count(*)
    count = tuple.getDouble("EXPR$0");
    //sum(a_i)
    sumi = tuple.getDouble("EXPR$1");
    //min(a_i)
    mini = tuple.getDouble("EXPR$2");
    //max(a_i)
    maxi = tuple.getDouble("EXPR$3");
    //avg(a_i)
    avgi = tuple.getDouble("EXPR$4");
    //sum(a_f)
    sumf = tuple.getDouble("EXPR$5");
    //min(a_f)
    minf = tuple.getDouble("EXPR$6");
    //max(a_f)
    maxf = tuple.getDouble("EXPR$7");
    //avg(a_f)
    avgf = tuple.getDouble("EXPR$8");
    assertTrue(count == 1);
    assertTrue(sumi == 2);
    assertTrue(mini == 2);
    assertTrue(maxi == 2);
    assertTrue(avgi == 2.0D);
    assertTrue(sumf == 2.0D);
    assertTrue(minf == 2);
    assertTrue(maxf == 2);
    assertTrue(avgf == 2.0);
    // Test zero hits
    sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select count(*), sum(a_i), min(a_i), max(a_i), cast(avg(1.0 * a_i) as float), sum(a_f), " + "min(a_f), max(a_f), avg(a_f) from collection1 where a_s = 'blah'");
    solrStream = new SolrStream(jetty.url, sParams);
    tuples = getTuples(solrStream);
    assert (tuples.size() == 1);
    tuple = tuples.get(0);
    //count(*)
    count = tuple.getDouble("EXPR$0");
    //sum(a_i)
    sumi = tuple.getDouble("EXPR$1");
    //min(a_i)
    mini = tuple.getDouble("EXPR$2");
    //max(a_i)
    maxi = tuple.getDouble("EXPR$3");
    //avg(a_i)
    avgi = tuple.getDouble("EXPR$4");
    //sum(a_f)
    sumf = tuple.getDouble("EXPR$5");
    //min(a_f)
    minf = tuple.getDouble("EXPR$6");
    //max(a_f)
    maxf = tuple.getDouble("EXPR$7");
    //avg(a_f)
    avgf = tuple.getDouble("EXPR$8");
    assertTrue(count == 0);
    assertTrue(sumi == null);
    assertTrue(mini == null);
    assertTrue(maxi == null);
    assertTrue(avgi == null);
    assertTrue(sumf == null);
    assertTrue(minf == null);
    assertTrue(maxf == null);
    assertTrue(avgf == null);
    del("*:*");
    commit();
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrStream(org.apache.solr.client.solrj.io.stream.SolrStream) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 79 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class TestCollapseQParserPlugin method testCollapseQueries.

private void testCollapseQueries(String group, String hint, boolean numeric) throws Exception {
    String[] doc = { "id", "1", "term_s", "YYYY", group, "1", "test_i", "5", "test_l", "10", "test_f", "2000" };
    assertU(adoc(doc));
    assertU(commit());
    String[] doc1 = { "id", "2", "term_s", "YYYY", group, "1", "test_i", "50", "test_l", "100", "test_f", "200" };
    assertU(adoc(doc1));
    String[] doc2 = { "id", "3", "term_s", "YYYY", "test_i", "5000", "test_l", "100", "test_f", "200" };
    assertU(adoc(doc2));
    assertU(commit());
    String[] doc3 = { "id", "4", "term_s", "YYYY", "test_i", "500", "test_l", "1000", "test_f", "2000" };
    assertU(adoc(doc3));
    String[] doc4 = { "id", "5", "term_s", "YYYY", group, "2", "test_i", "4", "test_l", "10", "test_f", "2000" };
    assertU(adoc(doc4));
    assertU(commit());
    String[] doc5 = { "id", "6", "term_s", "YYYY", group, "2", "test_i", "10", "test_l", "100", "test_f", "200" };
    assertU(adoc(doc5));
    assertU(commit());
    String[] doc6 = { "id", "7", "term_s", "YYYY", group, "1", "test_i", "8", "test_l", "50", "test_f", "300" };
    assertU(adoc(doc6));
    assertU(commit());
    //Test collapse by score and following sort by score
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + "" + hint + "}");
    params.add("defType", "edismax");
    params.add("bf", "field(test_i)");
    assertQ(req(params, "indent", "on"), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']");
    // SOLR-5544 test ordering with empty sort param
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " nullPolicy=expand min=test_f" + hint + "}");
    params.add("defType", "edismax");
    params.add("bf", "field(test_i)");
    params.add("sort", "");
    assertQ(req(params), "*[count(//doc)=4]", "//result/doc[1]/float[@name='id'][.='3.0']", "//result/doc[2]/float[@name='id'][.='4.0']", "//result/doc[3]/float[@name='id'][.='2.0']", "//result/doc[4]/float[@name='id'][.='6.0']");
    // Test value source collapse criteria
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " nullPolicy=collapse min=field(test_i)" + hint + "}");
    params.add("sort", "test_i desc");
    assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='4.0']", "//result/doc[2]/float[@name='id'][.='1.0']", "//result/doc[3]/float[@name='id'][.='5.0']");
    // Test value source collapse criteria with cscore function
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " nullPolicy=collapse min=cscore()" + hint + "}");
    params.add("defType", "edismax");
    params.add("bf", "field(test_i)");
    assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='4.0']", "//result/doc[2]/float[@name='id'][.='1.0']", "//result/doc[3]/float[@name='id'][.='5.0']");
    // Test value source collapse criteria with cscore function but no top level score sort
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " nullPolicy=collapse min=cscore()" + hint + "}");
    params.add("defType", "edismax");
    params.add("bf", "field(test_i)");
    params.add("fl", "id");
    params.add("sort", "id desc");
    assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='4.0']", "//result/doc[3]/float[@name='id'][.='1.0']");
    // Test value source collapse criteria with compound cscore function
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " nullPolicy=collapse min=sum(cscore(),field(test_i))" + hint + "}");
    params.add("defType", "edismax");
    params.add("bf", "field(test_i)");
    assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='4.0']", "//result/doc[2]/float[@name='id'][.='1.0']", "//result/doc[3]/float[@name='id'][.='5.0']");
    //Test collapse by score with elevation
    params = new ModifiableSolrParams();
    params.add("q", "YYYY");
    params.add("fq", "{!collapse field=" + group + " nullPolicy=collapse" + hint + "}");
    params.add("defType", "edismax");
    params.add("bf", "field(test_i)");
    params.add("qf", "term_s");
    params.add("qt", "/elevate");
    assertQ(req(params), "*[count(//doc)=4]", "//result/doc[1]/float[@name='id'][.='1.0']", "//result/doc[2]/float[@name='id'][.='2.0']", "//result/doc[3]/float[@name='id'][.='3.0']", "//result/doc[4]/float[@name='id'][.='6.0']");
    // try both default & sort localparams as alternate ways to ask for max score
    for (String maxscore : new String[] { "  ", " sort='score desc' " }) {
        params = new ModifiableSolrParams();
        params.add("q", "YYYY");
        params.add("fq", "{!collapse field=" + group + maxscore + " nullPolicy=collapse" + hint + "}");
        params.add("defType", "edismax");
        params.add("bf", "field(test_i)");
        params.add("qf", "term_s");
        params.add("qt", "/elevate");
        params.add("elevateIds", "1,5");
        assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='1.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='3.0']");
    }
    // try both max & sort localparams as alternate ways to ask for max group head
    for (String max : new String[] { " max=test_i ", " sort='test_i desc' " }) {
        params = new ModifiableSolrParams();
        params.add("q", "YYYY");
        params.add("fq", "{!collapse field=" + group + max + "nullPolicy=collapse" + hint + "}");
        params.add("defType", "edismax");
        params.add("bf", "field(test_i)");
        params.add("qf", "term_s");
        params.add("qt", "/elevate");
        params.add("elevateIds", "1,5");
        assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='1.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='3.0']");
    }
    // try both min & sort localparams as alternate ways to ask for min group head
    for (String min : new String[] { " min=test_i ", " sort='test_i asc' " }) {
        params = new ModifiableSolrParams();
        params.add("q", "YYYY");
        params.add("fq", "{!collapse field=" + group + min + "nullPolicy=collapse" + hint + "}");
        params.add("defType", "edismax");
        params.add("bf", "field(test_i)");
        params.add("qf", "term_s");
        params.add("qt", "/elevate");
        params.add("elevateIds", "1,5");
        assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='1.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']");
    }
    //Test SOLR-5773 elevating documents with null group
    params = new ModifiableSolrParams();
    params.add("q", "YYYY");
    params.add("fq", "{!collapse field=" + group + "" + hint + "}");
    params.add("defType", "edismax");
    params.add("bf", "field(test_i)");
    params.add("qf", "term_s");
    params.add("qt", "/elevate");
    params.add("elevateIds", "3,4");
    assertQ(req(params), "*[count(//doc)=4]", "//result/doc[1]/float[@name='id'][.='3.0']", "//result/doc[2]/float[@name='id'][.='4.0']", "//result/doc[3]/float[@name='id'][.='2.0']", "//result/doc[4]/float[@name='id'][.='6.0']");
    // Non trivial sort local param for picking group head
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " nullPolicy=collapse sort='term_s asc, test_i asc' " + hint + "}");
    params.add("sort", "id desc");
    assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='4.0']", "//result/doc[3]/float[@name='id'][.='1.0']");
    // 
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " nullPolicy=collapse sort='term_s asc, test_i desc' " + hint + "}");
    params.add("sort", "id desc");
    assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='3.0']", "//result/doc[3]/float[@name='id'][.='2.0']");
    // try both min & sort localparams as alternate ways to ask for min group head
    for (String min : new String[] { " min=test_i ", " sort='test_i asc' " }) {
        params = new ModifiableSolrParams();
        params.add("q", "*:*");
        params.add("fq", "{!collapse field=" + group + min + hint + "}");
        params.add("sort", "id desc");
        assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='1.0']");
        params = new ModifiableSolrParams();
        params.add("q", "*:*");
        params.add("fq", "{!collapse field=" + group + min + hint + "}");
        params.add("sort", "id asc");
        assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='1.0']", "//result/doc[2]/float[@name='id'][.='5.0']");
        params = new ModifiableSolrParams();
        params.add("q", "*:*");
        params.add("fq", "{!collapse field=" + group + min + hint + "}");
        params.add("sort", "test_l asc,id desc");
        assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='1.0']");
        params = new ModifiableSolrParams();
        params.add("q", "*:*");
        params.add("fq", "{!collapse field=" + group + min + hint + "}");
        params.add("sort", "score desc,id asc");
        params.add("defType", "edismax");
        params.add("bf", "field(id)");
        assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='1.0']");
    }
    //Test collapse by max int field
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " max=test_i" + hint + "}");
    params.add("sort", "test_i asc");
    assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='2.0']");
    try {
        //Test collapse by min long field
        params = new ModifiableSolrParams();
        params.add("q", "*:*");
        params.add("fq", "{!collapse field=" + group + " min=test_l" + hint + "}");
        params.add("sort", "test_i desc");
        assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='1.0']", "//result/doc[2]/float[@name='id'][.='5.0']");
        //Test collapse by max long field
        params = new ModifiableSolrParams();
        params.add("q", "*:*");
        params.add("fq", "{!collapse field=" + group + " max=test_l" + hint + "}");
        params.add("sort", "test_i desc");
        assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']");
    } catch (Exception e) {
        if (!numeric) {
            throw e;
        }
    }
    //Test collapse by min float field
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " min=test_f" + hint + "}");
    params.add("sort", "test_i desc");
    assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']");
    //Test collapse by min float field
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " max=test_f" + hint + "}");
    params.add("sort", "test_i asc");
    assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='1.0']");
    //Test collapse by min float field sort by score
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " max=test_f" + hint + "}");
    params.add("defType", "edismax");
    params.add("bf", "field(id)");
    params.add("fl", "score, id");
    params.add("facet", "true");
    params.add("fq", "{!tag=test}term_s:YYYY");
    params.add("facet.field", "{!ex=test}term_s");
    assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='1.0']");
    // tie selector in all of these cases
    for (String selector : new String[] { " min=bogus_i ", " sort='bogus_i asc' ", " max=bogus_i ", " sort='bogus_i desc' ", " min=bogus_tf ", " sort='bogus_tf asc' ", " max=bogus_tf ", " sort='bogus_tf desc' ", " sort='bogus_td asc' ", " sort='bogus_td desc' ", " sort='bogus_s asc' ", " sort='bogus_s desc' " }) {
        params = new ModifiableSolrParams();
        params.add("q", "*:*");
        params.add("fq", "{!collapse field=" + group + selector + hint + "}");
        params.add("sort", group + " asc");
        assertQ(req(params), "*[count(//doc)=2]", // key assertion is that there is one doc from each group & groups are in order
        "//result/doc[1]/*[@name='" + group + "'][starts-with(.,'1')]", "//result/doc[2]/*[@name='" + group + "'][starts-with(.,'2')]");
    }
    // attempting to use cscore() in sort local param should fail
    assertQEx("expected error trying to sort on a function that includes cscore()", req(params("q", "{!func}sub(sub(test_l,1000),id)", "fq", "{!collapse field=" + group + " sort='abs(cscore()) asc, id asc'}", "sort", "score asc")), SolrException.ErrorCode.BAD_REQUEST);
    // multiple params for picking groupHead should all fail
    for (String bad : new String[] { "{!collapse field=" + group + " min=test_f max=test_f}", "{!collapse field=" + group + " min=test_f sort='test_f asc'}", "{!collapse field=" + group + " max=test_f sort='test_f asc'}" }) {
        assertQEx("Expected error: " + bad, req(params("q", "*:*", "fq", bad)), SolrException.ErrorCode.BAD_REQUEST);
    }
    // sort used
    for (SolrParams collapse : new SolrParams[] { // these should all be equivilently valid
    params("fq", "{!collapse field=" + group + " nullPolicy=collapse sort='test_i asc'" + hint + "}"), params("fq", "{!collapse field=" + group + " nullPolicy=collapse min='' sort='test_i asc'" + hint + "}"), params("fq", "{!collapse field=" + group + " nullPolicy=collapse max='' sort='test_i asc'" + hint + "}"), params("fq", "{!collapse field=" + group + " nullPolicy=collapse min=$x sort='test_i asc'" + hint + "}"), params("fq", "{!collapse field=" + group + " nullPolicy=collapse min=$x sort='test_i asc'" + hint + "}", "x", "") }) {
        assertQ(req(collapse, "q", "*:*", "sort", "test_i desc"), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='4.0']", "//result/doc[2]/float[@name='id'][.='1.0']", "//result/doc[3]/float[@name='id'][.='5.0']");
    }
    //Test nullPolicy expand
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " max=test_f nullPolicy=expand" + hint + "}");
    params.add("sort", "id desc");
    assertQ(req(params), "*[count(//doc)=4]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='4.0']", "//result/doc[3]/float[@name='id'][.='3.0']", "//result/doc[4]/float[@name='id'][.='1.0']");
    //Test nullPolicy collapse
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + " max=test_f nullPolicy=collapse" + hint + "}");
    params.add("sort", "id desc");
    assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='4.0']", "//result/doc[3]/float[@name='id'][.='1.0']");
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + hint + "}");
    params.add("defType", "edismax");
    params.add("bf", "field(test_i)");
    params.add("fq", "{!tag=test_i}id:5");
    params.add("facet", "true");
    params.add("facet.field", "{!ex=test_i}test_i");
    params.add("facet.mincount", "1");
    assertQ(req(params), "*[count(//doc)=1]", "*[count(//lst[@name='facet_fields']/lst[@name='test_i']/int)=2]");
    // SOLR-5230 - ensure CollapsingFieldValueCollector.finish() is called
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!collapse field=" + group + hint + "}");
    params.add("group", "true");
    params.add("group.field", "id");
    assertQ(req(params), "*[count(//doc)=2]");
    // delete the elevated docs, confirm collapsing still works
    assertU(delI("1"));
    assertU(delI("2"));
    assertU(commit());
    params = new ModifiableSolrParams();
    params.add("q", "YYYY");
    params.add("fq", "{!collapse field=" + group + hint + " nullPolicy=collapse}");
    params.add("defType", "edismax");
    params.add("bf", "field(test_i)");
    params.add("qf", "term_s");
    params.add("qt", "/elevate");
    assertQ(req(params), "*[count(//doc)=3]", "//result/doc[1]/float[@name='id'][.='3.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='7.0']");
}
Also used : ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException)

Example 80 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class SpellCheckCollatorTest method testEstimatedHitCounts.

@Test
public void testEstimatedHitCounts() throws Exception {
    final String xpathPrefix = "//lst[@name='spellcheck']/lst[@name='collations']/lst[@name='collation']/";
    final SolrParams reusedParams = params(SpellCheckComponent.COMPONENT_NAME, "true", SpellCheckComponent.SPELLCHECK_DICT, "direct", SpellingParams.SPELLCHECK_COUNT, "1", SpellingParams.SPELLCHECK_COLLATE, "true", SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "1", SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1", SpellingParams.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "true", "qt", "spellCheckCompRH");
    // default case, no SPELLCHECK_COLLATE_MAX_COLLECT_DOCS should be exact num hits
    assertQ(req(reusedParams, CommonParams.Q, "teststop:metnoia"), xpathPrefix + "str[@name='collationQuery']='teststop:metanoia'", xpathPrefix + "int[@name='hits']=6");
    // "estimating" and getting exact number as well.
    for (String val : new String[] { "0", "30", "100", "10000" }) {
        assertQ(req(reusedParams, CommonParams.Q, "teststop:metnoia", SpellingParams.SPELLCHECK_COLLATE_MAX_COLLECT_DOCS, val), xpathPrefix + "str[@name='collationQuery']='teststop:metanoia'", xpathPrefix + "int[@name='hits']=6");
    }
    // values between 0 and the num docs in the index should not error, and should 
    // produce an estimate no more then the total number of docs
    final int iters = atLeast(10);
    for (int iter = 0; iter < iters; iter++) {
        final int val = TestUtil.nextInt(random(), 1, 17);
        assertQ(req(reusedParams, CommonParams.Q, "teststop:metnoia", SpellingParams.SPELLCHECK_COLLATE_MAX_COLLECT_DOCS, "" + val), xpathPrefix + "str[@name='collationQuery']='teststop:metanoia'", xpathPrefix + "int[@name='hits' and . <= 17 and 0 < .]");
    }
    // since we're dealing with a fairly small index here)
    for (int val = 5; val <= 20; val++) {
        int max = MAX_DOC_ID * val / (val + MIN_DOC_ID_WITH_EVERYOTHER + 1);
        int min = MAX_DOC_ID * val / (val + MAX_DOC_ID_WITH_EVERYOTHER + 1);
        assertQ(req(reusedParams, CommonParams.Q, "teststop:everother", SpellingParams.SPELLCHECK_COLLATE_MAX_COLLECT_DOCS, "" + val), xpathPrefix + "str[@name='collationQuery']='teststop:everyother'", xpathPrefix + "int[@name='hits' and " + min + " <= . and . <= " + max + "]");
    }
}
Also used : ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) Test(org.junit.Test)

Aggregations

SolrParams (org.apache.solr.common.params.SolrParams)310 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)179 SolrException (org.apache.solr.common.SolrException)78 Test (org.junit.Test)45 Tuple (org.apache.solr.client.solrj.io.Tuple)43 SolrDocument (org.apache.solr.common.SolrDocument)42 ArrayList (java.util.ArrayList)41 NamedList (org.apache.solr.common.util.NamedList)40 MapSolrParams (org.apache.solr.common.params.MapSolrParams)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)37 IOException (java.io.IOException)35 SolrDocumentList (org.apache.solr.common.SolrDocumentList)34 HashMap (java.util.HashMap)33 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)30 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)27 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)26 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)24 Map (java.util.Map)22 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)22 SolrCore (org.apache.solr.core.SolrCore)20