Search in sources :

Example 6 with PivotField

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

the class DistributedFacetPivotLongTailTest method doTestDeepPivotStats.

public void doTestDeepPivotStats() throws Exception {
    // Deep checking of some Facet stats - no refinement involved here
    List<PivotField> pivots = query("q", "*:*", "shards", getShardsString(), "facet", "true", "rows", "0", "facet.pivot", "{!stats=s1}foo_s,bar_s", "stats", "true", "stats.field", "{!key=avg_price tag=s1}stat_i").getFacetPivot().get("foo_s,bar_s");
    PivotField aaa0PivotField = pivots.get(0);
    assertEquals("aaa0", aaa0PivotField.getValue());
    assertEquals(300, aaa0PivotField.getCount());
    FieldStatsInfo aaa0StatsInfo = aaa0PivotField.getFieldStatsInfo().get("avg_price");
    assertEquals("avg_price", aaa0StatsInfo.getName());
    assertEquals(-99.0, aaa0StatsInfo.getMin());
    assertEquals(693.0, aaa0StatsInfo.getMax());
    assertEquals(300, (long) aaa0StatsInfo.getCount());
    assertEquals(0, (long) aaa0StatsInfo.getMissing());
    assertEquals(34650.0, aaa0StatsInfo.getSum());
    assertEquals(1.674585E7, aaa0StatsInfo.getSumOfSquares(), 0.1E-7);
    assertEquals(115.5, (double) aaa0StatsInfo.getMean(), 0.1E-7);
    assertEquals(206.4493184076, aaa0StatsInfo.getStddev(), 0.1E-7);
    PivotField tailPivotField = pivots.get(5);
    assertEquals("tail", tailPivotField.getValue());
    assertEquals(135, tailPivotField.getCount());
    FieldStatsInfo tailPivotFieldStatsInfo = tailPivotField.getFieldStatsInfo().get("avg_price");
    assertEquals("avg_price", tailPivotFieldStatsInfo.getName());
    assertEquals(0.0, tailPivotFieldStatsInfo.getMin());
    assertEquals(44.0, tailPivotFieldStatsInfo.getMax());
    assertEquals(90, (long) tailPivotFieldStatsInfo.getCount());
    assertEquals(45, (long) tailPivotFieldStatsInfo.getMissing());
    assertEquals(1980.0, tailPivotFieldStatsInfo.getSum());
    assertEquals(22.0, (double) tailPivotFieldStatsInfo.getMean(), 0.1E-7);
    assertEquals(58740.0, tailPivotFieldStatsInfo.getSumOfSquares(), 0.1E-7);
    assertEquals(13.0599310011, tailPivotFieldStatsInfo.getStddev(), 0.1E-7);
    PivotField tailBPivotField = tailPivotField.getPivot().get(0);
    assertEquals("tailB", tailBPivotField.getValue());
    assertEquals(17, tailBPivotField.getCount());
    FieldStatsInfo tailBPivotFieldStatsInfo = tailBPivotField.getFieldStatsInfo().get("avg_price");
    assertEquals("avg_price", tailBPivotFieldStatsInfo.getName());
    assertEquals(35.0, tailBPivotFieldStatsInfo.getMin());
    assertEquals(40.0, tailBPivotFieldStatsInfo.getMax());
    assertEquals(12, (long) tailBPivotFieldStatsInfo.getCount());
    assertEquals(5, (long) tailBPivotFieldStatsInfo.getMissing());
    assertEquals(450.0, tailBPivotFieldStatsInfo.getSum());
    assertEquals(37.5, (double) tailBPivotFieldStatsInfo.getMean(), 0.1E-7);
    assertEquals(16910.0, tailBPivotFieldStatsInfo.getSumOfSquares(), 0.1E-7);
    assertEquals(1.78376517, tailBPivotFieldStatsInfo.getStddev(), 0.1E-7);
}
Also used : FieldStatsInfo(org.apache.solr.client.solrj.response.FieldStatsInfo) PivotField(org.apache.solr.client.solrj.response.PivotField)

Example 7 with PivotField

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

the class DistributedFacetPivotSmallAdvancedTest method doTestTopStatsWithRefinement.

/**
   * we need to ensure that stats never "overcount" the values from a single shard
   * even if we hit that shard with a refinement request 
   */
private void doTestTopStatsWithRefinement(final boolean allStats) throws Exception {
    String stat_param = allStats ? "{!tag=s1}foo_i" : "{!tag=s1 min=true max=true count=true missing=true}foo_i";
    ModifiableSolrParams coreParams = params("q", "*:*", "rows", "0", "stats", "true", "stats.field", stat_param);
    ModifiableSolrParams facetParams = new ModifiableSolrParams(coreParams);
    facetParams.add(params("facet", "true", "facet.limit", "1", "facet.pivot", "{!stats=s1}place_t,company_t"));
    ModifiableSolrParams facetForceRefineParams = new ModifiableSolrParams(facetParams);
    facetForceRefineParams.add(params(FacetParams.FACET_OVERREQUEST_COUNT, "0", FacetParams.FACET_OVERREQUEST_RATIO, "0"));
    for (ModifiableSolrParams params : new ModifiableSolrParams[] { coreParams, facetParams, facetForceRefineParams }) {
        // for all three sets of these params, the "top level" 
        // stats in the response of a distributed query should be the same
        ModifiableSolrParams q = new ModifiableSolrParams(params);
        q.set("shards", getShardsString());
        QueryResponse rsp = queryServer(q);
        FieldStatsInfo fieldStatsInfo = rsp.getFieldStatsInfo().get("foo_i");
        String msg = q.toString();
        assertEquals(msg, 3.0, fieldStatsInfo.getMin());
        assertEquals(msg, 91.0, fieldStatsInfo.getMax());
        assertEquals(msg, 10, (long) fieldStatsInfo.getCount());
        assertEquals(msg, 0, (long) fieldStatsInfo.getMissing());
        if (allStats) {
            assertEquals(msg, 248.0, fieldStatsInfo.getSum());
            assertEquals(msg, 15294.0, fieldStatsInfo.getSumOfSquares(), 0.1E-7);
            assertEquals(msg, 24.8, (double) fieldStatsInfo.getMean(), 0.1E-7);
            assertEquals(msg, 31.87405772027709, fieldStatsInfo.getStddev(), 0.1E-7);
        } else {
            assertNull(msg, fieldStatsInfo.getSum());
            assertNull(msg, fieldStatsInfo.getSumOfSquares());
            assertNull(msg, fieldStatsInfo.getMean());
            assertNull(msg, fieldStatsInfo.getStddev());
        }
        if (params.getBool("facet", false)) {
            // if this was a facet request, then the top pivot constraint and pivot 
            // stats should match what we expect - regardless of whether refine
            // was used, or if the query was initially satisfied by the default overrequest
            List<PivotField> placePivots = rsp.getFacetPivot().get("place_t,company_t");
            assertEquals(1, placePivots.size());
            PivotField dublinPivotField = placePivots.get(0);
            assertEquals("dublin", dublinPivotField.getValue());
            assertEquals(4, dublinPivotField.getCount());
            assertEquals(1, dublinPivotField.getPivot().size());
            PivotField microsoftPivotField = dublinPivotField.getPivot().get(0);
            assertEquals("microsoft", microsoftPivotField.getValue());
            assertEquals(4, microsoftPivotField.getCount());
            FieldStatsInfo dublinMicrosoftStatsInfo = microsoftPivotField.getFieldStatsInfo().get("foo_i");
            assertEquals(3.0D, dublinMicrosoftStatsInfo.getMin());
            assertEquals(91.0D, dublinMicrosoftStatsInfo.getMax());
            assertEquals(4, (long) dublinMicrosoftStatsInfo.getCount());
            assertEquals(0, (long) dublinMicrosoftStatsInfo.getMissing());
            if (!allStats) {
                assertNull(msg, dublinMicrosoftStatsInfo.getSum());
                assertNull(msg, dublinMicrosoftStatsInfo.getSumOfSquares());
                assertNull(msg, dublinMicrosoftStatsInfo.getMean());
                assertNull(msg, dublinMicrosoftStatsInfo.getStddev());
            }
        }
    }
    // sanity check that the top pivot from each shard is diff, to prove to 
    // ourselves that the above queries really must have involved refinement.
    Object s0pivValue = clients.get(0).query(facetParams).getFacetPivot().get("place_t,company_t").get(0).getValue();
    Object s1pivValue = clients.get(1).query(facetParams).getFacetPivot().get("place_t,company_t").get(0).getValue();
    assertFalse("both shards have same top constraint, test is invalid" + "(did someone change the test data?) ==> " + s0pivValue + "==" + s1pivValue, s0pivValue.equals(s1pivValue));
}
Also used : FieldStatsInfo(org.apache.solr.client.solrj.response.FieldStatsInfo) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) PivotField(org.apache.solr.client.solrj.response.PivotField) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 8 with PivotField

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

the class DistributedFacetPivotSmallTest method testFacetPivotRange.

private void testFacetPivotRange() throws Exception {
    final ModifiableSolrParams params = new ModifiableSolrParams();
    setDistributedParams(params);
    params.add("q", "*:*");
    params.add("facet", "true");
    params.add("facet.pivot", "{!range=s1}place_t,company_t");
    params.add("facet.range", "{!tag=s1 key=price}price_ti");
    params.add("facet.range.start", "0");
    params.add("facet.range.end", "100");
    params.add("facet.range.gap", "20");
    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, null, createExpectedRange("price", 0, 100, 20, 1, 0, 0, 0, 0)));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "null", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, null, createExpectedRange("price", 0, 100, 20, 1, 1, 0, 0, 0)));
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, null, createExpectedRange("price", 0, 100, 20, 0, 0, 0, 0, 0)));
    List<PivotField> expectedDublinPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedDublinPivots.add(new ComparablePivotField("company_t", "polecat", 4, null, null, createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "microsoft", 4, null, null, createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "null", 3, null, null, createExpectedRange("price", 0, 100, 20, 1, 1, 0, 0, 0)));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "bbc", 1, null, null, createExpectedRange("price", 0, 100, 20, 0, 0, 0, 0, 0)));
    List<PivotField> expectedLondonPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, null, createExpectedRange("price", 0, 100, 20, 0, 2, 0, 0, 0)));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null, null, createExpectedRange("price", 0, 100, 20, 0, 2, 0, 0, 0)));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    List<PivotField> expectedLAPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLAPivots.add(new ComparablePivotField("company_t", "microsoft", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedLAPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedLAPivots.add(new ComparablePivotField("company_t", "null", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedLAPivots.add(new ComparablePivotField("company_t", "bbc", 1, null, null, createExpectedRange("price", 0, 100, 20, 0, 0, 0, 0, 0)));
    expectedLAPivots.add(new ComparablePivotField("company_t", "polecat", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    List<PivotField> expectedKrakowPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "polecat", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "null", 3, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, null, createExpectedRange("price", 0, 100, 20, 0, 0, 0, 0, 0)));
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "microsoft", 1, null, null, createExpectedRange("price", 0, 100, 20, 0, 0, 0, 0, 0)));
    List<PivotField> expectedCorkPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCorkPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, null, createExpectedRange("price", 0, 100, 20, 0, 0, 0, 0, 0)));
    expectedCorkPivots.add(new ComparablePivotField("company_t", "rte", 1, null, null, createExpectedRange("price", 0, 100, 20, 0, 0, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots, null, createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "cardiff", 3, expectedCardiffPivots, null, createExpectedRange("price", 0, 100, 20, 1, 1, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "london", 4, expectedLondonPivots, null, createExpectedRange("price", 0, 100, 20, 0, 3, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "la", 3, expectedLAPivots, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "krakow", 3, expectedKrakowPivots, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "cork", 1, expectedCorkPivots, null, createExpectedRange("price", 0, 100, 20, 0, 0, 0, 0, 0)));
    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, null, createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "microsoft", 4, null, null, createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    expectedLondonPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null, null, createExpectedRange("price", 0, 100, 20, 0, 2, 0, 0, 0)));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, null, createExpectedRange("price", 0, 100, 20, 0, 2, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots, null, createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "london", 4, expectedLondonPivots, null, createExpectedRange("price", 0, 100, 20, 0, 3, 0, 0, 0)));
    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, null, createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "polecat", 4, null, null, createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "null", 3, null, null, createExpectedRange("price", 0, 100, 20, 1, 1, 0, 0, 0)));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedLondonPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null, null, createExpectedRange("price", 0, 100, 20, 0, 2, 0, 0, 0)));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, null, createExpectedRange("price", 0, 100, 20, 0, 2, 0, 0, 0)));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "bbc", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedCardiffPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCardiffPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, null, createExpectedRange("price", 0, 100, 20, 1, 1, 0, 0, 0)));
    expectedKrakowPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedKrakowPivots.add(new ComparablePivotField("company_t", "null", 3, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedLAPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedLAPivots.add(new ComparablePivotField("company_t", "fujitsu", 2, null, null, createExpectedRange("price", 0, 100, 20, 0, 1, 0, 0, 0)));
    expectedCorkPivots = new UnorderedEqualityArrayList<PivotField>();
    expectedCorkPivots.add(new ComparablePivotField("company_t", "fujitsu", 1, null, null, createExpectedRange("price", 0, 100, 20, 0, 0, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots, null, createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    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 9 with PivotField

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

the class DistributedFacetPivotSmallTest method doTestPivotStatsFromOneShard.

/**
   * sanity check the stat values nested under a pivot when at least one shard
   * has nothing but missing values for the stat
   */
private void doTestPivotStatsFromOneShard() throws Exception {
    SolrParams params = params("q", "*:*", "rows", "0", "facet", "true", "stats", "true", "facet.pivot", "{!stats=s1}place_t,company_t", "stats.field", "{!tag=s1}solo_i", "stats.field", "{!tag=s1}solo_s", "stats.field", "{!tag=s1}solo_dt");
    QueryResponse rsp = query(params);
    List<PivotField> placePivots = rsp.getFacetPivot().get("place_t,company_t");
    PivotField placePivot = placePivots.get(0);
    assertEquals("dublin", placePivot.getValue());
    assertEquals(4, placePivot.getCount());
    PivotField companyPivot = placePivot.getPivot().get(2);
    assertEquals("null", companyPivot.getValue());
    assertEquals(3, companyPivot.getCount());
    for (PivotField pf : new PivotField[] { placePivot, companyPivot }) {
        assertThereCanBeOnlyOne(pf, pf.getFieldStatsInfo().get("solo_s"), "lonely");
        assertThereCanBeOnlyOne(pf, pf.getFieldStatsInfo().get("solo_i"), 42.0D);
        assertEquals(pf.getField() + ":" + pf.getValue() + ": int mean", 42.0D, pf.getFieldStatsInfo().get("solo_i").getMean());
        // 1976-03-06T01:23:45Z
        Object expected = new Date(194923425000L);
        assertThereCanBeOnlyOne(pf, pf.getFieldStatsInfo().get("solo_dt"), expected);
        assertEquals(pf.getField() + ":" + pf.getValue() + ": date mean", expected, pf.getFieldStatsInfo().get("solo_dt").getMean());
    // TODO: add enum field asserts - blocked by SOLR-6682
    }
}
Also used : 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) Date(java.util.Date)

Example 10 with PivotField

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

the class DistributedFacetPivotSmallTest method testPivotFacetRangeAndQuery.

private void testPivotFacetRangeAndQuery() throws Exception {
    SolrParams params = params("q", "*:*", "rows", "0", "facet", "true", "stats", "true", "facet.pivot", "{!range=s1 query=s2 stats=s3}place_t,company_t", "facet.range", "{!tag=s1 key=price}price_ti", "facet.query", "{!tag=s2 key=highPrice}price_ti:[25 TO 100]", "facet.query", "{!tag=s2 key=lowPrice}price_ti:[0 TO 20]", "stats.field", ("{!tag=s3 key=avg_price}price_ti"), "facet.range.start", "0", "facet.range.end", "100", "facet.range.gap", "20", FacetParams.FACET_SORT, FacetParams.FACET_SORT_COUNT, FacetParams.FACET_LIMIT, "2");
    UnorderedEqualityArrayList<PivotField> expectedPlacePivots = new UnorderedEqualityArrayList<>();
    UnorderedEqualityArrayList<PivotField> expectedDublinPivots = new UnorderedEqualityArrayList<>();
    expectedDublinPivots.add(new ComparablePivotField("company_t", "polecat", 4, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    expectedDublinPivots.add(new ComparablePivotField("company_t", "microsoft", 4, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    UnorderedEqualityArrayList<PivotField> expectedLondonPivots = new UnorderedEqualityArrayList<>();
    expectedLondonPivots.add(new ComparablePivotField("company_t", "null", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 2, 0 }), createExpectedRange("price", 0, 100, 20, 0, 2, 0, 0, 0)));
    expectedLondonPivots.add(new ComparablePivotField("company_t", "polecat", 3, null, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 2, 0 }), createExpectedRange("price", 0, 100, 20, 0, 2, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "dublin", 4, expectedDublinPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 1, 2 }), createExpectedRange("price", 0, 100, 20, 2, 1, 0, 0, 0)));
    expectedPlacePivots.add(new ComparablePivotField("place_t", "london", 4, expectedLondonPivots, createExpectedQCount(new String[] { "highPrice", "lowPrice" }, new int[] { 3, 0 }), createExpectedRange("price", 0, 100, 20, 0, 3, 0, 0, 0)));
    QueryResponse rsp = query(params);
    List<PivotField> placePivots = rsp.getFacetPivot().get("place_t,company_t");
    assertEquals(expectedPlacePivots, placePivots);
    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(21.0, (double) dublinMicrosoftStatsInfo.getMean(), 0.1E-7);
    assertEquals(15.0, dublinMicrosoftStatsInfo.getMin());
    assertEquals(29.0, dublinMicrosoftStatsInfo.getMax());
    assertEquals(3, (long) dublinMicrosoftStatsInfo.getCount());
    assertEquals(1, (long) dublinMicrosoftStatsInfo.getMissing());
    assertEquals(63.0, dublinMicrosoftStatsInfo.getSum());
    assertEquals(1427.0, dublinMicrosoftStatsInfo.getSumOfSquares(), 0.1E-7);
    assertEquals(7.211102550927978, dublinMicrosoftStatsInfo.getStddev(), 0.1E-7);
}
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)

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