Java Code Examples for org.alfresco.service.cmr.search.SearchParameters#setStats()

The following examples show how to use org.alfresco.service.cmr.search.SearchParameters#setStats() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrQueryHTTPClientTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testBuildStats() throws UnsupportedEncodingException
{
    SearchParameters params = new SearchParameters();
    params.setSearchTerm("bob");
    params.setStats(Arrays.asList(
                new StatsRequestParameters("created", null, null, null, null,null, null, null, null,
                            null, null, null, null,null, null,  null),
                new StatsRequestParameters("cm:name", "statLabel",
                Arrays.asList(2.4f, 99.9f),null, null, false, null,false, null, false, null, true, true,
                true, 0.5f, Arrays.asList("excludeme"))));

    StringBuilder urlBuilder = new StringBuilder();
    client.buildStatsParameters(params, encoder, urlBuilder);
    String url = urlBuilder.toString();
    assertNotNull(url);
    assertTrue(url.contains("&stats=true"));
    assertTrue(url.contains("stats.field=" + encoder.encode(
               "{! countDistinct=false distinctValues=false min=true max=true sum=true count=true missing=true sumOfSquares=true mean=true stddev=true}created", "UTF-8")));
    assertTrue(url.contains("stats.field=" + encoder.encode(
               "{! ex=excludeme tag=statLabel key=statLabel percentiles='2.4,99.9' cardinality=0.5 countDistinct=true distinctValues=true min=true max=true sum=false count=true missing=false sumOfSquares=true mean=false stddev=true}cm:name", "UTF-8")));

}
 
Example 2
Source File: SolrQueryHTTPClientTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testBuildPivots() throws UnsupportedEncodingException
{
    SearchParameters params = new SearchParameters();
    params.setSearchTerm("bob");
    params.addPivots(Arrays.asList("creator"));
    params.setStats(Arrays.asList(
                new StatsRequestParameters("created", "piv1", null, null, null,null, null, null, null,
                            null, null, null, null,null, null,  null)
                ));
    List<RangeParameters> ranges = new ArrayList<RangeParameters>();
    ranges.add(new RangeParameters("content.size","0","1000000", "10000", true, Collections.emptyList(), Collections.emptyList(), "csize",null));
    params.setRanges(ranges);

    StringBuilder urlBuilder = new StringBuilder();

    client.buildPivotParameters(params, encoder, urlBuilder);
    String url = urlBuilder.toString();
    assertNotNull(url);
    assertTrue(url.contains("&facet=true"));
    assertTrue(url.contains("facet.pivot=creator"));

    params.addPivots(Arrays.asList("cm:name", "piv1", "csize"));

    urlBuilder = new StringBuilder();
    client.buildPivotParameters(params, encoder, urlBuilder);
    url = urlBuilder.toString();
    assertNotNull(url);
    assertTrue(url.contains("&facet=true"));
    assertTrue(url.contains("facet.pivot="+ encoder.encode("creator", "UTF-8")));
    assertTrue(url.contains("facet.pivot="+ encoder.encode("{! stats=piv1 range=csize}cm:name", "UTF-8")));
}
 
Example 3
Source File: SearchMapper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void fromStats(SearchParameters sp, List<StatsRequestParameters> stats)
{
    if (stats != null && !stats.isEmpty())
    {
        for (StatsRequestParameters aStat:stats)
        {
            ParameterCheck.mandatory("stats field", aStat.getField());

            List<Float> perc = aStat.getPercentiles();
            if (perc != null && !perc.isEmpty())
            {
                for (Float percentile:perc)
                {
                    if (percentile == null || percentile < 0 || percentile > 100)
                    {
                        throw new IllegalArgumentException("Invalid percentile "+percentile);
                    }
                }
            }

            if (aStat.getCardinality() && (aStat.getCardinalityAccuracy() < 0 || aStat.getCardinalityAccuracy() > 1))
            {
                throw new IllegalArgumentException("Invalid cardinality accuracy "+aStat.getCardinalityAccuracy() + " It must be between 0 and 1.");
            }
        }

        sp.setStats(stats);
    }

}