Search in sources :

Example 16 with PivotField

use of org.apache.solr.client.solrj.response.PivotField in project lucene-solr by apache.

the class DistributedFacetPivotSmallAdvancedTest method doTestDeepPivotStatsOnString.

private void doTestDeepPivotStatsOnString() throws Exception {
    SolrParams params = params("q", "*:*", "rows", "0", "shards", getShardsString(), "facet", "true", "stats", "true", "facet.pivot", "{!stats=s1}place_t,company_t", "stats.field", "{!key=avg_price tag=s1}foo_s");
    QueryResponse rsp = queryServer(new ModifiableSolrParams(params));
    List<PivotField> placePivots = rsp.getFacetPivot().get("place_t,company_t");
    PivotField dublinPivotField = placePivots.get(0);
    assertEquals("dublin", dublinPivotField.getValue());
    assertEquals(4, dublinPivotField.getCount());
    PivotField microsoftPivotField = dublinPivotField.getPivot().get(0);
    assertEquals("microsoft", microsoftPivotField.getValue());
    assertEquals(4, microsoftPivotField.getCount());
    FieldStatsInfo dublinMicrosoftStatsInfo = microsoftPivotField.getFieldStatsInfo().get("avg_price");
    assertEquals("aaa", dublinMicrosoftStatsInfo.getMin());
    assertEquals("bbb", dublinMicrosoftStatsInfo.getMax());
    assertEquals(4, (long) dublinMicrosoftStatsInfo.getCount());
    assertEquals(0, (long) dublinMicrosoftStatsInfo.getMissing());
    PivotField cardiffPivotField = placePivots.get(2);
    assertEquals("cardiff", cardiffPivotField.getValue());
    assertEquals(3, cardiffPivotField.getCount());
    PivotField polecatPivotField = cardiffPivotField.getPivot().get(0);
    assertEquals("polecat", polecatPivotField.getValue());
    assertEquals(3, polecatPivotField.getCount());
    FieldStatsInfo cardiffPolecatStatsInfo = polecatPivotField.getFieldStatsInfo().get("avg_price");
    assertEquals("aaa", cardiffPolecatStatsInfo.getMin());
    assertEquals("bbb", cardiffPolecatStatsInfo.getMax());
    assertEquals(3, (long) cardiffPolecatStatsInfo.getCount());
    assertEquals(0, (long) cardiffPolecatStatsInfo.getMissing());
    PivotField krakowPivotField = placePivots.get(3);
    assertEquals("krakow", krakowPivotField.getValue());
    assertEquals(3, krakowPivotField.getCount());
    PivotField fujitsuPivotField = krakowPivotField.getPivot().get(3);
    assertEquals("fujitsu", fujitsuPivotField.getValue());
    assertEquals(1, fujitsuPivotField.getCount());
    FieldStatsInfo krakowFujitsuStatsInfo = fujitsuPivotField.getFieldStatsInfo().get("avg_price");
    assertEquals("aaa", krakowFujitsuStatsInfo.getMin());
    assertEquals("aaa", krakowFujitsuStatsInfo.getMax());
    assertEquals(1, (long) krakowFujitsuStatsInfo.getCount());
    assertEquals(0, (long) krakowFujitsuStatsInfo.getMissing());
}
Also used : FieldStatsInfo(org.apache.solr.client.solrj.response.FieldStatsInfo) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) PivotField(org.apache.solr.client.solrj.response.PivotField) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 17 with PivotField

use of org.apache.solr.client.solrj.response.PivotField in project lucene-solr by apache.

the class DistributedFacetPivotSmallTest method test.

@Test
@ShardsFixed(num = 4)
public void test() throws Exception {
    del("*:*");
    // NOTE: we use the literal (4 character) string "null" as a company name
    // to help ensure there isn't any bugs where the literal string is treated as if it 
    // were a true NULL value.
    index(id, 19, "place_t", "cardiff dublin", "company_t", "microsoft polecat", "price_ti", "15");
    index(id, 20, "place_t", "dublin", "company_t", "polecat microsoft null", "price_ti", "19", // TODO: add enum field - blocked by SOLR-6682
    "solo_i", 42, "solo_s", "lonely", "solo_dt", "1976-03-06T01:23:45Z");
    index(id, 21, "place_t", "london la dublin", "company_t", "microsoft fujitsu null polecat", "price_ti", "29");
    index(id, 22, "place_t", "krakow london cardiff", "company_t", "polecat null bbc", "price_ti", "39");
    index(id, 23, "place_t", "london", "company_t", "", "price_ti", "29");
    index(id, 24, "place_t", "la", "company_t", "");
    index(id, 25, "company_t", "microsoft polecat null fujitsu null bbc", "price_ti", "59");
    index(id, 26, "place_t", "krakow", "company_t", "null");
    index(id, 27, "place_t", "krakow cardiff dublin london la", "company_t", "null microsoft polecat bbc fujitsu");
    index(id, 28, "place_t", "cork", "company_t", "fujitsu rte");
    commit();
    handle.clear();
    handle.put("QTime", SKIPVAL);
    handle.put("timestamp", SKIPVAL);
    handle.put("maxScore", SKIPVAL);
    final ModifiableSolrParams params = new ModifiableSolrParams();
    setDistributedParams(params);
    params.add("q", "*:*");
    params.add("facet", "true");
    params.add("facet.pivot", "place_t,company_t");
    QueryResponse rsp = queryServer(params);
    List<PivotField> expectedPlacePivots = new UnorderedEqualityArrayList<PivotField>();
    List<PivotField> expectedCardiffPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "null", 2, null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "bbc", 2, null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "polecat", 3, null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null));
    List<PivotField> expectedDublinPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots.add(new ComparablePivotField("company_t", "polecat", 4, null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "microsoft", 4, null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "null", 3, null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "bbc", 1, null));
    List<PivotField> expectedLondonPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "bbc", 2, null));
    List<PivotField> expectedLAPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLAPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "null", 2, null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "bbc", 1, null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "polecat", 2, null));
    List<PivotField> expectedKrakowPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "polecat", 2, null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "bbc", 2, null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "null", 3, null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "microsoft", 1, null));
    List<PivotField> expectedCorkPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCorkPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null));
    expectedCorkPivots.add(new ComparablePivotField("company_t", "rte", 1, null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "cardiff", 3, expectedCardiffPivots));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "london", 4, expectedLondonPivots));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "la", 3, expectedLAPivots));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "krakow", 3, expectedKrakowPivots));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "cork", 1, expectedCorkPivots));
    List<PivotField> placePivots = rsp.getFacetPivot().get("place_t,company_t");
    // Useful to check for errors, orders lists and does toString() equality
    // check
    testOrderedPivotsStringEquality(expectedPlacePivots, placePivots);
    assertEquals(expectedPlacePivots, placePivots);
    // Test sorting by count
    params.set(FacetParams.FACET_SORT, FacetParams.FACET_SORT_COUNT);
    rsp = queryServer(params);
    placePivots = rsp.getFacetPivot().get("place_t,company_t");
    testCountSorting(placePivots);
    // Test limit
    params.set(FacetParams.FACET_LIMIT, 2);
    rsp = queryServer(params);
    expectedPlacePivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots.add(new ComparablePivotField("company_t", "polecat", 4, null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "microsoft", 4, null));
    expectedLondonPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "london", 4, expectedLondonPivots));
    placePivots = rsp.getFacetPivot().get("place_t,company_t");
    assertEquals(expectedPlacePivots, placePivots);
    // Test individual facet.limit values
    params.remove(FacetParams.FACET_LIMIT);
    params.set("f.place_t." + FacetParams.FACET_LIMIT, 1);
    params.set("f.company_t." + FacetParams.FACET_LIMIT, 4);
    rsp = queryServer(params);
    expectedPlacePivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots.add(new ComparablePivotField("company_t", "microsoft", 4, null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "polecat", 4, null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "null", 3, null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null));
    expectedLondonPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "bbc", 2, null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null));
    expectedCardiffPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "polecat", 3, null));
    expectedKrakowPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "null", 3, null));
    expectedLAPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLAPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null));
    expectedCorkPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCorkPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots));
    placePivots = rsp.getFacetPivot().get("place_t,company_t");
    assertEquals(expectedPlacePivots, placePivots);
    params.remove("f.company_t." + FacetParams.FACET_LIMIT);
    params.remove("f.place_t." + FacetParams.FACET_LIMIT);
    params.set(FacetParams.FACET_LIMIT, 2);
    // Test facet.missing=true with diff sorts
    // NOTE: id=25 has no place as well
    index("id", 777);
    commit();
    SolrParams missingA = params("q", "*:*", "rows", "0", "facet", "true", "facet.pivot", "place_t,company_t", "f.place_t.facet.mincount", "2", // default facet.sort
    FacetParams.FACET_MISSING, "true");
    SolrParams missingB = SolrParams.wrapDefaults(missingA, params(FacetParams.FACET_LIMIT, "4", "facet.sort", "index"));
    for (SolrParams p : new SolrParams[] { missingA, missingB }) {
        // in either case, the last pivot option should be the same
        rsp = query(p);
        placePivots = rsp.getFacetPivot().get("place_t,company_t");
        assertTrue("not enough values for pivot: " + p + " => " + placePivots, 1 < placePivots.size());
        PivotField missing = placePivots.get(placePivots.size() - 1);
        assertNull("not the missing place value: " + p, missing.getValue());
        assertEquals("wrong missing place count: " + p, 2, missing.getCount());
        assertTrue("not enough sub-pivots for missing place: " + p + " => " + missing.getPivot(), 1 < missing.getPivot().size());
        missing = missing.getPivot().get(missing.getPivot().size() - 1);
        assertNull("not the missing company value: " + p, missing.getValue());
        assertEquals("wrong missing company count: " + p, 1, missing.getCount());
        assertNull("company shouldn't have sub-pivots: " + p, missing.getPivot());
    }
    // sort=index + mincount + limit
    for (SolrParams variableParams : new SolrParams[] { // we should get the same results regardless of overrequest
    params("facet.overrequest.count", "0", "facet.overrequest.ratio", "0"), params() }) {
        SolrParams p = SolrParams.wrapDefaults(params("q", "*:*", "rows", "0", "facet", "true", "facet.pivot", "company_t", "facet.sort", "index", "facet.pivot.mincount", "4", "facet.limit", "4"), variableParams);
        try {
            List<PivotField> pivots = query(p).getFacetPivot().get("company_t");
            assertEquals(4, pivots.size());
            assertEquals("fujitsu", pivots.get(0).getValue());
            assertEquals(4, pivots.get(0).getCount());
            assertEquals("microsoft", pivots.get(1).getValue());
            assertEquals(5, pivots.get(1).getCount());
            assertEquals("null", pivots.get(2).getValue());
            assertEquals(6, pivots.get(2).getCount());
            assertEquals("polecat", pivots.get(3).getValue());
            assertEquals(6, pivots.get(3).getCount());
        } catch (AssertionFailedError ae) {
            throw new AssertionError(ae.getMessage() + " <== " + p.toString(), ae);
        }
    }
    // sort=index + mincount + limit + offset
    for (SolrParams variableParams : new SolrParams[] { // we should get the same results regardless of overrequest
    params("facet.overrequest.count", "0", "facet.overrequest.ratio", "0"), params() }) {
        SolrParams p = SolrParams.wrapDefaults(params("q", "*:*", "rows", "0", "facet", "true", "facet.pivot", "company_t", "facet.sort", "index", "facet.pivot.mincount", "4", "facet.offset", "1", "facet.limit", "4"), variableParams);
        try {
            List<PivotField> pivots = query(p).getFacetPivot().get("company_t");
            // asked for 4, but not enough meet the mincount
            assertEquals(3, pivots.size());
            assertEquals("microsoft", pivots.get(0).getValue());
            assertEquals(5, pivots.get(0).getCount());
            assertEquals("null", pivots.get(1).getValue());
            assertEquals(6, pivots.get(1).getCount());
            assertEquals("polecat", pivots.get(2).getValue());
            assertEquals(6, pivots.get(2).getCount());
        } catch (AssertionFailedError ae) {
            throw new AssertionError(ae.getMessage() + " <== " + p.toString(), ae);
        }
    }
    // sort=index + mincount + limit + offset (more permutations)
    for (SolrParams variableParams : new SolrParams[] { // all of these combinations should result in the same first value
    params("facet.pivot.mincount", "4", "facet.offset", "2"), params("facet.pivot.mincount", "5", "facet.offset", "1"), params("facet.pivot.mincount", "6", "facet.offset", "0") }) {
        SolrParams p = SolrParams.wrapDefaults(params("q", "*:*", "rows", "0", "facet", "true", "facet.limit", "1", "facet.sort", "index", "facet.overrequest.ratio", "0", "facet.pivot", "company_t"), variableParams);
        try {
            List<PivotField> pivots = query(p).getFacetPivot().get("company_t");
            assertEquals(1, pivots.size());
            assertEquals(pivots.toString(), "null", pivots.get(0).getValue());
            assertEquals(pivots.toString(), 6, pivots.get(0).getCount());
        } catch (AssertionFailedError ae) {
            throw new AssertionError(ae.getMessage() + " <== " + p.toString(), ae);
        }
    }
    // all price stats
    doTestDeepPivotStats(false);
    // just the mean price stat
    doTestDeepPivotStats(true);
    doTestPivotStatsFromOneShard();
    testFacetPivotRange();
    testFacetPivotQuery();
    testNegativeFacetQuery();
    testNegativeRangeQuery();
    testPivotFacetRangeAndQuery();
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) PivotField(org.apache.solr.client.solrj.response.PivotField) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) AssertionFailedError(junit.framework.AssertionFailedError) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 18 with PivotField

use of org.apache.solr.client.solrj.response.PivotField in project lucene-solr by apache.

the class DistributedFacetPivotSmallTest method testOrderedPivotsStringEquality.

// Useful to check for errors, orders lists and does toString() equality check
private void testOrderedPivotsStringEquality(List<PivotField> expectedPlacePivots, List<PivotField> placePivots) {
    Collections.sort(expectedPlacePivots, new PivotFieldComparator());
    for (PivotField expectedPivot : expectedPlacePivots) {
        if (expectedPivot.getPivot() != null) {
            Collections.sort(expectedPivot.getPivot(), new PivotFieldComparator());
        }
    }
    Collections.sort(placePivots, new PivotFieldComparator());
    for (PivotField pivot : placePivots) {
        if (pivot.getPivot() != null) {
            Collections.sort(pivot.getPivot(), new PivotFieldComparator());
        }
    }
    assertEquals(expectedPlacePivots.toString(), placePivots.toString());
}
Also used : PivotField(org.apache.solr.client.solrj.response.PivotField)

Example 19 with PivotField

use of org.apache.solr.client.solrj.response.PivotField in project lucene-solr by apache.

the class DistributedFacetPivotSmallTest method testFacetPivotQuery.

private void testFacetPivotQuery() throws Exception {
    final ModifiableSolrParams params = new ModifiableSolrParams();
    setDistributedParams(params);
    params.add("q", "*:*");
    params.add("facet", "true");
    params.add("facet.pivot", "{!query=s1}place_t,company_t");
    params.add("facet.query", "{!tag=s1 key=highPrice}price_ti:[25 TO 100]");
    QueryResponse rsp = queryServer(params);
    List<PivotField> expectedPlacePivots = new UnorderedEqualityArrayList<PivotField>();
    List<PivotField> expectedCardiffPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 0 }), null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "null", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 0 }), null));
    List<PivotField> expectedDublinPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots.add(new ComparablePivotField("company_t", "polecat", 4, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "microsoft", 4, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "bbc", 1, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 0 }), null));
    List<PivotField> expectedLondonPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 2 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 2 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    List<PivotField> expectedLAPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLAPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "null", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "bbc", 1, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 0 }), null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "polecat", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    List<PivotField> expectedKrakowPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "polecat", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 0 }), null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "microsoft", 1, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 0 }), null));
    List<PivotField> expectedCorkPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCorkPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 0 }), null));
    expectedCorkPivots.add(new ComparablePivotField("company_t", "rte", 1, null, createExpectedQCount(new String[] { "highPrice" }, new int[] { 0 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "cardiff", 3, expectedCardiffPivots, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "london", 4, expectedLondonPivots, createExpectedQCount(new String[] { "highPrice" }, new int[] { 3 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "la", 3, expectedLAPivots, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "krakow", 3, expectedKrakowPivots, createExpectedQCount(new String[] { "highPrice" }, new int[] { 1 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "cork", 1, expectedCorkPivots, createExpectedQCount(new String[] { "highPrice" }, new int[] { 0 }), null));
    List<PivotField> placePivots = rsp.getFacetPivot().get("place_t,company_t");
    // Useful to check for errors, orders lists and does toString() equality
    // check
    testOrderedPivotsStringEquality(expectedPlacePivots, placePivots);
    assertEquals(expectedPlacePivots, placePivots);
    // Add second query for low price
    params.add("facet.query", "{!tag=s1 key=lowPrice}price_ti:[0 TO 20]");
    expectedPlacePivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCardiffPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 0, 1 }), null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "null", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 1 }), null));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 0, 0 }), null));
    expectedDublinPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots.add(new ComparablePivotField("company_t", "polecat", 4, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "microsoft", 4, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 1 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "bbc", 1, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 0, 0 }), null));
    expectedLondonPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 2, 0 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 2, 0 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedLAPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLAPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "null", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "bbc", 1, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 0, 0 }), null));
    expectedLAPivots.add(new ComparablePivotField("company_t", "polecat", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedKrakowPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "polecat", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 0, 0 }), null));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "microsoft", 1, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 0, 0 }), null));
    expectedCorkPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCorkPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 0, 0 }), null));
    expectedCorkPivots.add(new ComparablePivotField("company_t", "rte", 1, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 0, 0 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "cardiff", 3, expectedCardiffPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 1 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "london", 4, expectedLondonPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 3, 0 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "la", 3, expectedLAPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "krakow", 3, expectedKrakowPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "cork", 1, expectedCorkPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 0, 0 }), null));
    rsp = queryServer(params);
    placePivots = rsp.getFacetPivot().get("place_t,company_t");
    // Useful to check for errors, orders lists and does toString() equality
    // check
    testOrderedPivotsStringEquality(expectedPlacePivots, placePivots);
    assertEquals(expectedPlacePivots, placePivots);
    // Test sorting by count
    params.set(FacetParams.FACET_SORT, FacetParams.FACET_SORT_COUNT);
    rsp = queryServer(params);
    placePivots = rsp.getFacetPivot().get("place_t,company_t");
    testCountSorting(placePivots);
    // Test limit
    params.set(FacetParams.FACET_LIMIT, 2);
    rsp = queryServer(params);
    expectedPlacePivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots.add(new ComparablePivotField("company_t", "polecat", 4, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "microsoft", 4, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), null));
    expectedLondonPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 2, 0 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 2, 0 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "london", 4, expectedLondonPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 3, 0 }), null));
    placePivots = rsp.getFacetPivot().get("place_t,company_t");
    assertEquals(expectedPlacePivots, placePivots);
    // Test individual facet.limit values
    params.remove(FacetParams.FACET_LIMIT);
    params.set("f.place_t." + FacetParams.FACET_LIMIT, 1);
    params.set("f.company_t." + FacetParams.FACET_LIMIT, 4);
    rsp = queryServer(params);
    expectedPlacePivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots.add(new ComparablePivotField("company_t", "microsoft", 4, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "polecat", 4, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 1 }), null));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedLondonPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 2, 0 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 2, 0 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedCardiffPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 1 }), null));
    expectedKrakowPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedLAPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLAPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 0 }), null));
    expectedCorkPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCorkPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 0, 0 }), null));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), null));
    placePivots = rsp.getFacetPivot().get("place_t,company_t");
    assertEquals(expectedPlacePivots, placePivots);
    params.remove("f.company_t." + FacetParams.FACET_LIMIT);
    params.remove("f.place_t." + FacetParams.FACET_LIMIT);
    params.set(FacetParams.FACET_LIMIT, 2);
    // Test facet.missing=true with diff sorts
    // NOTE: id=25 has no place as well
    index("id", 777);
    commit();
    SolrParams missingA = params("q", "*:*", "rows", "0", "facet", "true", "facet.pivot", "place_t,company_t", // default facet.sort
    FacetParams.FACET_MISSING, "true");
    SolrParams missingB = SolrParams.wrapDefaults(missingA, params(FacetParams.FACET_LIMIT, "4", "facet.sort", "index"));
    for (SolrParams p : new SolrParams[] { missingA, missingB }) {
        // in either case, the last pivot option should be the same
        rsp = query(p);
        placePivots = rsp.getFacetPivot().get("place_t,company_t");
        assertTrue("not enough values for pivot: " + p + " => " + placePivots, 1 < placePivots.size());
        PivotField missing = placePivots.get(placePivots.size() - 1);
        assertNull("not the missing place value: " + p, missing.getValue());
        assertEquals("wrong missing place count: " + p, 2, missing.getCount());
        assertTrue("not enough sub-pivots for missing place: " + p + " => " + missing.getPivot(), 1 < missing.getPivot().size());
        missing = missing.getPivot().get(missing.getPivot().size() - 1);
        assertNull("not the missing company value: " + p, missing.getValue());
        assertEquals("wrong missing company count: " + p, 1, missing.getCount());
        assertNull("company shouldn't have sub-pivots: " + p, missing.getPivot());
    }
    // sort=index + mincount + limit
    for (SolrParams variableParams : new SolrParams[] { // we should get the same results regardless of overrequest
    params("facet.overrequest.count", "0", "facet.overrequest.ratio", "0"), params() }) {
        SolrParams p = SolrParams.wrapDefaults(params("q", "*:*", "rows", "0", "facet", "true", "facet.pivot", "company_t", "facet.sort", "index", "facet.pivot.mincount", "4", "facet.limit", "4"), variableParams);
        try {
            List<PivotField> pivots = query(p).getFacetPivot().get("company_t");
            assertEquals(4, pivots.size());
            assertEquals("fujitsu", pivots.get(0).getValue());
            assertEquals(4, pivots.get(0).getCount());
            assertEquals("microsoft", pivots.get(1).getValue());
            assertEquals(5, pivots.get(1).getCount());
            assertEquals("null", pivots.get(2).getValue());
            assertEquals(6, pivots.get(2).getCount());
            assertEquals("polecat", pivots.get(3).getValue());
            assertEquals(6, pivots.get(3).getCount());
        } catch (AssertionFailedError ae) {
            throw new AssertionError(ae.getMessage() + " <== " + p.toString(), ae);
        }
    }
    // sort=index + mincount + limit + offset
    for (SolrParams variableParams : new SolrParams[] { // we should get the same results regardless of overrequest
    params("facet.overrequest.count", "0", "facet.overrequest.ratio", "0"), params() }) {
        SolrParams p = SolrParams.wrapDefaults(params("q", "*:*", "rows", "0", "facet", "true", "facet.pivot", "company_t", "facet.sort", "index", "facet.pivot.mincount", "4", "facet.offset", "1", "facet.limit", "4"), variableParams);
        try {
            List<PivotField> pivots = query(p).getFacetPivot().get("company_t");
            // asked for 4, but not enough meet the
            assertEquals(3, pivots.size());
            // mincount
            assertEquals("microsoft", pivots.get(0).getValue());
            assertEquals(5, pivots.get(0).getCount());
            assertEquals("null", pivots.get(1).getValue());
            assertEquals(6, pivots.get(1).getCount());
            assertEquals("polecat", pivots.get(2).getValue());
            assertEquals(6, pivots.get(2).getCount());
        } catch (AssertionFailedError ae) {
            throw new AssertionError(ae.getMessage() + " <== " + p.toString(), ae);
        }
    }
    // sort=index + mincount + limit + offset (more permutations)
    for (SolrParams variableParams : new SolrParams[] { // all of these combinations should result in the same first value
    params("facet.pivot.mincount", "4", "facet.offset", "2"), params("facet.pivot.mincount", "5", "facet.offset", "1"), params("facet.pivot.mincount", "6", "facet.offset", "0") }) {
        SolrParams p = SolrParams.wrapDefaults(params("q", "*:*", "rows", "0", "facet", "true", "facet.limit", "1", "facet.sort", "index", "facet.overrequest.ratio", "0", "facet.pivot", "company_t"), variableParams);
        try {
            List<PivotField> pivots = query(p).getFacetPivot().get("company_t");
            assertEquals(1, pivots.size());
            assertEquals(pivots.toString(), "null", pivots.get(0).getValue());
            assertEquals(pivots.toString(), 6, pivots.get(0).getCount());
        } catch (AssertionFailedError ae) {
            throw new AssertionError(ae.getMessage() + " <== " + p.toString(), ae);
        }
    }
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) PivotField(org.apache.solr.client.solrj.response.PivotField) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) AssertionFailedError(junit.framework.AssertionFailedError) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 20 with PivotField

use of org.apache.solr.client.solrj.response.PivotField in project lucene-solr by apache.

the class SolrExampleTests method testPivotFacetsStats.

@Test
public void testPivotFacetsStats() throws Exception {
    SolrClient client = getSolrClient();
    // Empty the database...
    // delete everything!
    client.deleteByQuery("*:*");
    client.commit();
    // make sure it got in
    assertNumFound("*:*", 0);
    int id = 1;
    ArrayList<SolrInputDocument> docs = new ArrayList<>();
    docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "apple", "cat", "a", "inStock", true, "popularity", 12, "price", .017));
    docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "lg", "cat", "a", "inStock", false, "popularity", 13, "price", 16.04));
    docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "samsung", "cat", "a", "inStock", true, "popularity", 14, "price", 12.34));
    docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "lg", "cat", "b", "inStock", false, "popularity", 24, "price", 51.39));
    docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "nokia", "cat", "b", "inStock", true, "popularity", 28, "price", 131.39));
    docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "ztc", "cat", "a", "inStock", false, "popularity", 32));
    docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "htc", "cat", "a", "inStock", true, "popularity", 31, "price", 131.39));
    docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "apple", "cat", "b", "inStock", false, "popularity", 36));
    docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "lg", "cat", "b", "inStock", true, "popularity", 37, "price", 1.39));
    docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "ztc", "cat", "b", "inStock", false, "popularity", 38, "price", 47.98));
    docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "ztc", "cat", "b", "inStock", true, "popularity", -38));
    // something not matching all fields
    docs.add(makeTestDoc("id", id++, "cat", "b"));
    client.add(docs);
    client.commit();
    for (String pivot : new String[] { "{!key=pivot_key stats=s1}features,manu", "{!key=pivot_key stats=s1}features,manu,cat", "{!key=pivot_key stats=s1}features,manu,cat,inStock" }) {
        // for any of these pivot params, the assertions we check should be teh same
        // (we stop asserting at the "manu" level)
        SolrQuery query = new SolrQuery("*:*");
        query.addFacetPivotField(pivot);
        query.setFacetLimit(1);
        query.addGetFieldStatistics("{!key=foo_price tag=s1}price", "{!tag=s1}popularity");
        query.setFacetMinCount(0);
        query.setRows(0);
        QueryResponse rsp = client.query(query);
        // check top (ie: non-pivot) stats
        Map<String, FieldStatsInfo> map = rsp.getFieldStatsInfo();
        FieldStatsInfo intValueStatsInfo = map.get("popularity");
        assertEquals(-38.0d, intValueStatsInfo.getMin());
        assertEquals(38.0d, intValueStatsInfo.getMax());
        assertEquals(11l, intValueStatsInfo.getCount().longValue());
        assertEquals(1l, intValueStatsInfo.getMissing().longValue());
        assertEquals(227.0d, intValueStatsInfo.getSum());
        assertEquals(20.636363636363637d, intValueStatsInfo.getMean());
        FieldStatsInfo doubleValueStatsInfo = map.get("foo_price");
        assertEquals(.017d, (double) doubleValueStatsInfo.getMin(), .01d);
        assertEquals(131.39d, (double) doubleValueStatsInfo.getMax(), .01d);
        assertEquals(8l, doubleValueStatsInfo.getCount().longValue());
        assertEquals(4l, doubleValueStatsInfo.getMissing().longValue());
        assertEquals(391.93d, (double) doubleValueStatsInfo.getSum(), .01d);
        assertEquals(48.99d, (double) doubleValueStatsInfo.getMean(), .01d);
        // now get deeper and look at the pivots...
        NamedList<List<PivotField>> pivots = rsp.getFacetPivot();
        assertTrue(!pivots.get("pivot_key").isEmpty());
        List<PivotField> list = pivots.get("pivot_key");
        PivotField featuresBBBPivot = list.get(0);
        assertEquals("features", featuresBBBPivot.getField());
        assertEquals("bbb", featuresBBBPivot.getValue());
        assertNotNull(featuresBBBPivot.getFieldStatsInfo());
        assertEquals(2, featuresBBBPivot.getFieldStatsInfo().size());
        FieldStatsInfo featuresBBBPivotStats1 = featuresBBBPivot.getFieldStatsInfo().get("foo_price");
        assertEquals("foo_price", featuresBBBPivotStats1.getName());
        assertEquals(131.39d, (double) featuresBBBPivotStats1.getMax(), .01d);
        assertEquals(1.38d, (double) featuresBBBPivotStats1.getMin(), .01d);
        assertEquals(180.75d, (double) featuresBBBPivotStats1.getSum(), .01d);
        assertEquals(3, (long) featuresBBBPivotStats1.getCount());
        assertEquals(3, (long) featuresBBBPivotStats1.getMissing());
        assertEquals(60.25d, (double) featuresBBBPivotStats1.getMean(), .01d);
        assertEquals(65.86d, featuresBBBPivotStats1.getStddev(), .01d);
        assertEquals(19567.34d, featuresBBBPivotStats1.getSumOfSquares(), .01d);
        FieldStatsInfo featuresBBBPivotStats2 = featuresBBBPivot.getFieldStatsInfo().get("popularity");
        assertEquals("popularity", featuresBBBPivotStats2.getName());
        assertEquals(38.0d, (double) featuresBBBPivotStats2.getMax(), .01d);
        assertEquals(-38.0d, (double) featuresBBBPivotStats2.getMin(), .01d);
        assertEquals(136.0d, (double) featuresBBBPivotStats2.getSum(), .01d);
        assertEquals(6, (long) featuresBBBPivotStats2.getCount());
        assertEquals(0, (long) featuresBBBPivotStats2.getMissing());
        assertEquals(22.66d, (double) featuresBBBPivotStats2.getMean(), .01d);
        assertEquals(29.85d, featuresBBBPivotStats2.getStddev(), .01d);
        assertEquals(7538.0d, featuresBBBPivotStats2.getSumOfSquares(), .01d);
        List<PivotField> nestedPivotList = featuresBBBPivot.getPivot();
        PivotField featuresBBBPivotPivot = nestedPivotList.get(0);
        assertEquals("manu", featuresBBBPivotPivot.getField());
        assertEquals("ztc", featuresBBBPivotPivot.getValue());
        assertNotNull(featuresBBBPivotPivot.getFieldStatsInfo());
        assertEquals(2, featuresBBBPivotPivot.getFieldStatsInfo().size());
        FieldStatsInfo featuresBBBManuZtcPivotStats1 = featuresBBBPivotPivot.getFieldStatsInfo().get("foo_price");
        assertEquals("foo_price", featuresBBBManuZtcPivotStats1.getName());
        assertEquals(47.97d, (double) featuresBBBManuZtcPivotStats1.getMax(), .01d);
        assertEquals(47.97d, (double) featuresBBBManuZtcPivotStats1.getMin(), .01d);
        assertEquals(47.97d, (double) featuresBBBManuZtcPivotStats1.getSum(), .01d);
        assertEquals(1, (long) featuresBBBManuZtcPivotStats1.getCount());
        assertEquals(2, (long) featuresBBBManuZtcPivotStats1.getMissing());
        assertEquals(47.97d, (double) featuresBBBManuZtcPivotStats1.getMean(), .01d);
        assertEquals(0.0d, featuresBBBManuZtcPivotStats1.getStddev(), .01d);
        assertEquals(2302.08d, featuresBBBManuZtcPivotStats1.getSumOfSquares(), .01d);
        FieldStatsInfo featuresBBBManuZtcPivotStats2 = featuresBBBPivotPivot.getFieldStatsInfo().get("popularity");
        assertEquals("popularity", featuresBBBManuZtcPivotStats2.getName());
        assertEquals(38.0d, (double) featuresBBBManuZtcPivotStats2.getMax(), .01d);
        assertEquals(-38.0d, (double) featuresBBBManuZtcPivotStats2.getMin(), .01d);
        assertEquals(32.0, (double) featuresBBBManuZtcPivotStats2.getSum(), .01d);
        assertEquals(3, (long) featuresBBBManuZtcPivotStats2.getCount());
        assertEquals(0, (long) featuresBBBManuZtcPivotStats2.getMissing());
        assertEquals(10.66d, (double) featuresBBBManuZtcPivotStats2.getMean(), .01d);
        assertEquals(42.25d, featuresBBBManuZtcPivotStats2.getStddev(), .01d);
        assertEquals(3912.0d, featuresBBBManuZtcPivotStats2.getSumOfSquares(), .01d);
    }
}
Also used : ArrayList(java.util.ArrayList) StringContains.containsString(org.junit.internal.matchers.StringContains.containsString) FieldStatsInfo(org.apache.solr.client.solrj.response.FieldStatsInfo) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ErrorTrackingConcurrentUpdateSolrClient(org.apache.solr.client.solrj.embedded.SolrExampleStreamingTest.ErrorTrackingConcurrentUpdateSolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) PivotField(org.apache.solr.client.solrj.response.PivotField) SolrDocumentList(org.apache.solr.common.SolrDocumentList) List(java.util.List) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) Test(org.junit.Test)

Aggregations

PivotField (org.apache.solr.client.solrj.response.PivotField)24 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)19 SolrParams (org.apache.solr.common.params.SolrParams)14 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)13 FieldStatsInfo (org.apache.solr.client.solrj.response.FieldStatsInfo)8 List (java.util.List)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 SolrDocumentList (org.apache.solr.common.SolrDocumentList)5 NamedList (org.apache.solr.common.util.NamedList)5 AssertionFailedError (junit.framework.AssertionFailedError)4 ErrorTrackingConcurrentUpdateSolrClient (org.apache.solr.client.solrj.embedded.SolrExampleStreamingTest.ErrorTrackingConcurrentUpdateSolrClient)4 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)4 SolrInputDocument (org.apache.solr.common.SolrInputDocument)4 IOException (java.io.IOException)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 Date (java.util.Date)2 Map (java.util.Map)2 RangeFacet (org.apache.solr.client.solrj.response.RangeFacet)2 StringContains.containsString (org.junit.internal.matchers.StringContains.containsString)2