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

The following examples show how to use org.alfresco.service.cmr.search.SearchParameters#setRanges() . 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 testBuildRangeDate() throws UnsupportedEncodingException
{
    TimeZone defaultTimeZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

    SearchParameters params = new SearchParameters();
    params.setSearchTerm("A*");
    List<RangeParameters> ranges = new ArrayList<RangeParameters>();
    ranges.add(new RangeParameters("created", "2015", "2016", "+1MONTH", true, Collections.emptyList(), Collections.emptyList(), null, null));
    params.setRanges(ranges);
    StringBuilder urlBuilder = new StringBuilder();
    client.buildRangeParameters(params, encoder, urlBuilder);
    String url = urlBuilder.toString();
    assertNotNull(url);
    assertTrue(url.contains("&facet=true"));
    assertTrue(url.contains("&facet.range=created"));
    assertTrue(url.contains("&f.created.facet.range.start=2015-01-01T00%3A00%3A00.000Z"));
    assertTrue(url.contains("&f.created.facet.range.end=2016-12-31T23%3A59%3A59.999Z"));
    assertTrue(url.contains("&f.created.facet.range.gap=%2B1MONTH"));

    TimeZone.setDefault(defaultTimeZone);
}
 
Example 2
Source File: SearchMapper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Sets the Range Parameters object on search parameters
 * @param sp SearchParameters
 * @param rangeParams RangeParameters
 */
public void fromRange(SearchParameters sp, List<RangeParameters> ranges)
{
    if(ranges != null && !ranges.isEmpty())
    {
        for(RangeParameters rangeParams : ranges)
        {
            ParameterCheck.mandatory("ranges", rangeParams);
            ParameterCheck.mandatory("field", rangeParams.getField());
            ParameterCheck.mandatory("start", rangeParams.getStart());
            ParameterCheck.mandatory("end", rangeParams.getEnd());
            ParameterCheck.mandatory("gap", rangeParams.getGap());
        }
        sp.setRanges(ranges);
    }
    
}
 
Example 3
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 4
Source File: SolrQueryHTTPClientTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testBuildMulitRange() throws UnsupportedEncodingException
{
    SearchParameters params = new SearchParameters();
    params.setSearchTerm("A*");
    List<RangeParameters> ranges = new ArrayList<RangeParameters>();
    List<String>includes = new ArrayList<String>();
    includes.add("upper");
    includes.add("outer");
    List<String>includes2 = new ArrayList<String>();
    includes2.add("lower");
    List<String> other = new ArrayList<String>();
    other.add("before");
    ranges.add(new RangeParameters("content.size", "0", "1000000", "10000", true, other, includes, null, null));
    ranges.add(new RangeParameters("created", "2015-09-29T10:45:15.729Z", "2016-09-29T10:45:15.729Z", "+100DAY", true, other, includes2, null, null));
    params.setRanges(ranges);
    StringBuilder urlBuilder = new StringBuilder();
    client.buildRangeParameters(params, encoder, urlBuilder);
    String url = urlBuilder.toString();
    assertNotNull(url);
    assertTrue(url.contains("&facet=true"));
    assertTrue(url.contains("&facet.range=content.size"));
    assertTrue(url.contains("&f.content.size.facet.range.start=0"));
    assertTrue(url.contains("&f.content.size.facet.range.end=1000000"));
    assertTrue(url.contains("&f.content.size.facet.range.gap=10000"));
    assertTrue(url.contains("&f.content.size.facet.range.include=upper"));
    assertTrue(url.contains("&f.content.size.facet.range.include=outer"));
    assertTrue(url.contains("&f.content.size.facet.range.hardend=true"));
    assertTrue(url.contains("&facet.range=created"));
    assertTrue(url.contains("&f.created.facet.range.start=2015-09-29T10%3A45%3A15.729Z"));
    assertTrue(url.contains("&f.created.facet.range.end=2016-09-29T10%3A45%3A15.729Z"));
    assertTrue(url.contains("&f.created.facet.range.gap=%2B100DAY"));
    assertTrue(url.contains("&f.created.facet.range.other=before"));
    assertTrue(url.contains("&f.created.facet.range.include=lower"));
    assertTrue(url.contains("&f.created.facet.range.hardend=true"));
}
 
Example 5
Source File: SolrQueryHTTPClientTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void testBuildRange() throws UnsupportedEncodingException
{
    SearchParameters params = new SearchParameters();
    params.setSearchTerm("A*");
    List<RangeParameters> ranges = new ArrayList<RangeParameters>();
    List<String>includes = new ArrayList<String>();
    includes.add("upper");
    includes.add("outer");
    List<String> other = new ArrayList<String>();
    other.add("before");
    other.add("between");
    ranges.add(new RangeParameters("content.size", "0", "1000000", "10000", true, other, includes, null, null));
    params.setRanges(ranges);
    StringBuilder urlBuilder = new StringBuilder();
    client.buildRangeParameters(params, encoder, urlBuilder);
    String url = urlBuilder.toString();
    assertNotNull(url);
    assertTrue(url.contains("&facet=true"));
    assertTrue(url.contains("&facet.range=content.size"));
    assertTrue(url.contains("&f.content.size.facet.range.start=0"));
    assertTrue(url.contains("&f.content.size.facet.range.end=1000000"));
    assertTrue(url.contains("&f.content.size.facet.range.gap=10000"));
    assertTrue(url.contains("&f.content.size.facet.range.include=upper"));
    assertTrue(url.contains("&f.content.size.facet.range.include=outer"));
    assertTrue(url.contains("&f.content.size.facet.range.other=before"));
    assertTrue(url.contains("&f.content.size.facet.range.other=between"));
    assertTrue(url.contains("&f.content.size.facet.range.hardend=true"));

    List<String> filters = new ArrayList<String>();
    filters.add("ex1");

    ranges.clear();
    ranges.add(new RangeParameters("content.size", "0", "1000000", "10000", true, Collections.emptyList(), Collections.emptyList(), "doc", filters));
    params.setRanges(ranges);
    urlBuilder = new StringBuilder();
    client.buildRangeParameters(params, encoder, urlBuilder);
    String url2 = urlBuilder.toString();
    assertTrue(url2.contains("&facet=true"));
    assertTrue(url2.contains("&facet.range="+encoder.encode("{!tag=doc }", "UTF-8")+"content.size"));
    assertTrue(url2.contains("&f.content.size.facet.range.start=0"));
    assertTrue(url2.contains("&f.content.size.facet.range.end=1000000"));
    assertTrue(url2.contains("&f.content.size.facet.range.gap=10000"));
    assertFalse(url2.contains("&f.content.size.facet.range.include=upper"));
    assertFalse(url2.contains("&f.content.size.facet.range.include=outer"));
    assertFalse(url2.contains("&f.content.size.facet.range.other=before"));
    assertTrue(url2.contains("&f.content.size.facet.range.hardend=true"));
    assertTrue(url2.contains("&facet.range={!ex=ex1}content.size"));
}