use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method mockResultset.
private ResultSet mockResultset(String json) throws Exception {
NodeService nodeService = mock(NodeService.class);
JSONObject jsonObj = new JSONObject(new JSONTokener(json));
SearchParameters sp = new SearchParameters();
sp.setBulkFetchEnabled(false);
ResultSet results = new SolrJSONResultSet(jsonObj, sp, nodeService, null, LimitBy.FINAL_SIZE, 10);
return results;
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method testInterval.
@Test
public void testInterval() throws Exception {
ResultSet results = mockResultset(Collections.emptyList(), Collections.emptyList());
SearchQuery searchQuery = helper.searchQueryFromJson();
SearchRequestContext searchRequest = SearchRequestContext.from(searchQuery);
SearchParameters searchParams = searchMapper.toSearchParameters(EMPTY_PARAMS, searchQuery, searchRequest);
SearchContext searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchRequest, searchQuery, 0);
// Facet intervals
List<GenericFacetResponse> intervalFacets = searchContext.getFacets().stream().filter(f -> f.getType().equals(FACET_TYPE.interval)).collect(Collectors.toList());
assertEquals(2, intervalFacets.size());
assertEquals("creator", intervalFacets.get(0).getLabel());
assertEquals("last", intervalFacets.get(0).getBuckets().get(0).getLabel());
assertEquals("cm:creator:<\"a\" TO \"b\"]", intervalFacets.get(0).getBuckets().get(0).getFilterQuery());
Object[] metrics = intervalFacets.get(0).getBuckets().get(0).getMetrics().toArray();
assertEquals(METRIC_TYPE.count, ((SimpleMetric) metrics[0]).getType());
assertEquals("4", ((SimpleMetric) metrics[0]).getValue().get("count"));
metrics = intervalFacets.get(1).getBuckets().get(0).getMetrics().toArray();
assertEquals("TheCreated", intervalFacets.get(1).getLabel());
assertEquals("earlier", intervalFacets.get(1).getBuckets().get(0).getLabel());
assertEquals("cm:created:[\"*\" TO \"2016\">", intervalFacets.get(1).getBuckets().get(0).getFilterQuery());
assertEquals(METRIC_TYPE.count, ((SimpleMetric) metrics[0]).getType());
assertEquals("5", ((SimpleMetric) metrics[0]).getValue().get("count"));
metrics = intervalFacets.get(1).getBuckets().get(1).getMetrics().toArray();
assertEquals("lastYear", intervalFacets.get(1).getBuckets().get(1).getLabel());
assertEquals("cm:created:[\"2016\" TO \"2017\">", intervalFacets.get(1).getBuckets().get(1).getFilterQuery());
assertEquals(METRIC_TYPE.count, ((SimpleMetric) metrics[0]).getType());
assertEquals("0", ((SimpleMetric) metrics[0]).getValue().get("count"));
metrics = intervalFacets.get(1).getBuckets().get(2).getMetrics().toArray();
assertEquals("currentYear", intervalFacets.get(1).getBuckets().get(2).getLabel());
assertEquals("cm:created:[\"NOW/YEAR\" TO \"NOW/YEAR+1YEAR\"]", intervalFacets.get(1).getBuckets().get(2).getFilterQuery());
assertEquals(METRIC_TYPE.count, ((SimpleMetric) metrics[0]).getType());
assertEquals("854", ((SimpleMetric) metrics[0]).getValue().get("count"));
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method mockResultset.
private ResultSet mockResultset(List<Long> archivedNodes, List<Long> versionNodes) throws JSONException {
NodeService nodeService = mock(NodeService.class);
when(nodeService.getNodeRef(any())).thenAnswer(new Answer<NodeRef>() {
@Override
public NodeRef answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
// If the DBID is in the list archivedNodes, instead of returning a noderef return achivestore noderef
if (archivedNodes.contains(args[0]))
return new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, GUID.generate());
if (versionNodes.contains(args[0]))
return new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate() + args[0]);
return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate());
}
});
SearchParameters sp = new SearchParameters();
sp.setBulkFetchEnabled(false);
JSONObject json = new JSONObject(new JSONTokener(JSON_REPONSE));
ResultSet results = new SolrJSONResultSet(json, sp, nodeService, null, LimitBy.FINAL_SIZE, 10);
return results;
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method testRange.
@Test
public void testRange() throws Exception {
ResultSet results = mockResultset(Collections.emptyList(), Collections.emptyList());
SearchQuery searchQuery = helper.searchQueryFromJson();
SearchRequestContext searchRequest = SearchRequestContext.from(searchQuery);
SearchParameters searchParams = searchMapper.toSearchParameters(EMPTY_PARAMS, searchQuery, searchRequest);
SearchContext searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchRequest, searchQuery, 0);
// Numeric facet range
List<GenericFacetResponse> rangeFacets = searchContext.getFacets().stream().filter(f -> f.getType().equals(FACET_TYPE.range)).collect(Collectors.toList());
assertEquals(2, rangeFacets.size());
assertEquals(4, rangeFacets.get(0).getBuckets().size());
assertEquals("created", rangeFacets.get(0).getLabel());
assertEquals("[2015-09-29T10:45:15.729Z - 2016-01-07T10:45:15.729Z)", rangeFacets.get(0).getBuckets().get(0).getLabel());
Object[] metrics1 = rangeFacets.get(0).getBuckets().get(0).getMetrics().toArray();
assertEquals("0", ((SimpleMetric) metrics1[0]).getValue().get("count"));
assertEquals("created:[\"2015-09-29T10:45:15.729Z\" TO \"2016-01-07T10:45:15.729Z\">", rangeFacets.get(0).getBuckets().get(0).getFilterQuery());
assertEquals(null, rangeFacets.get(0).getBuckets().get(0).getBucketInfo().get("count"));
assertEquals("false", rangeFacets.get(0).getBuckets().get(0).getBucketInfo().get("endInclusive"));
assertEquals("true", rangeFacets.get(0).getBuckets().get(0).getBucketInfo().get("startInclusive"));
assertEquals(3, rangeFacets.get(1).getBuckets().size());
assertEquals("content.size", rangeFacets.get(1).getLabel());
assertEquals("[0 - 100)", rangeFacets.get(1).getBuckets().get(0).getLabel());
Object[] metrics = rangeFacets.get(1).getBuckets().get(0).getMetrics().toArray();
assertEquals("4", ((SimpleMetric) metrics[0]).getValue().get("count"));
assertEquals("content.size:[\"0\" TO \"100\">", rangeFacets.get(1).getBuckets().get(0).getFilterQuery());
assertEquals(null, rangeFacets.get(1).getBuckets().get(0).getBucketInfo().get("count"));
Map<String, String> facetInfo = rangeFacets.get(1).getBuckets().get(0).getBucketInfo();
assertEquals("0", facetInfo.get("start"));
assertEquals("100", facetInfo.get("end"));
assertEquals("[100 - 200)", rangeFacets.get(1).getBuckets().get(1).getLabel());
metrics = rangeFacets.get(1).getBuckets().get(1).getMetrics().toArray();
assertEquals("6", ((SimpleMetric) metrics[0]).getValue().get("count"));
facetInfo = rangeFacets.get(1).getBuckets().get(1).getBucketInfo();
assertEquals("100", facetInfo.get("start"));
assertEquals("200", facetInfo.get("end"));
assertEquals("content.size:[\"100\" TO \"200\">", rangeFacets.get(1).getBuckets().get(1).getFilterQuery());
assertEquals(null, rangeFacets.get(1).getBuckets().get(1).getBucketInfo().get("count"));
assertEquals("false", rangeFacets.get(1).getBuckets().get(0).getBucketInfo().get("endInclusive"));
assertEquals("true", rangeFacets.get(1).getBuckets().get(0).getBucketInfo().get("startInclusive"));
assertEquals("[200 - 300)", rangeFacets.get(1).getBuckets().get(2).getLabel());
metrics = rangeFacets.get(1).getBuckets().get(2).getMetrics().toArray();
assertEquals("3", ((SimpleMetric) metrics[0]).getValue().get("count"));
facetInfo = rangeFacets.get(1).getBuckets().get(2).getBucketInfo();
assertEquals("200", facetInfo.get("start"));
assertEquals("300", facetInfo.get("end"));
assertEquals("content.size:[\"200\" TO \"300\">", rangeFacets.get(1).getBuckets().get(2).getFilterQuery());
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromInterval.
@Test
public void fromInterval() throws Exception {
SearchParameters searchParameters = new SearchParameters();
IntervalParameters intervalParameters = new IntervalParameters(null, null);
try {
searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
fail();
} catch (IllegalArgumentException iae) {
// intervals is required
assertNotNull(iae);
}
Set<IntervalSet> intervalSets = new HashSet(Arrays.asList(new IntervalSet(null, "1", null, null, null)));
List<Interval> intervalList = Arrays.asList(new Interval(null, "bob", null));
intervalParameters = new IntervalParameters(intervalSets, intervalList);
try {
searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
fail();
} catch (IllegalArgumentException iae) {
// facetIntervals intervals field is required
assertNotNull(iae);
}
intervalList = Arrays.asList(new Interval("aFileld", "bob", null));
intervalParameters = new IntervalParameters(intervalSets, intervalList);
try {
searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
fail();
} catch (IllegalArgumentException iae) {
// set start is required
assertNotNull(iae);
}
intervalSets = new HashSet(Arrays.asList(new IntervalSet("1", null, null, null, true)));
intervalParameters = new IntervalParameters(intervalSets, intervalList);
try {
searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
fail();
} catch (IllegalArgumentException iae) {
// set end is required
assertNotNull(iae);
}
intervalSets = new HashSet<>();
intervalSets.add(new IntervalSet("0", "3", "bob", null, null));
intervalSets.add(new IntervalSet("30", "50", "bill", true, true));
Set<IntervalSet> anIntervalSet = new HashSet<>();
anIntervalSet.add(new IntervalSet("1", "10", "bert", false, false));
intervalList = Arrays.asList(new Interval("cm:price", "Price", null), new Interval("cm:price", "Price", anIntervalSet));
intervalParameters = new IntervalParameters(intervalSets, intervalList);
try {
searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
fail();
} catch (InvalidArgumentException iae) {
// duplicate labels
assertNotNull(iae);
}
intervalList = Arrays.asList(new Interval("cm:price", "Prices", null), new Interval("cm:price", "Pricey", anIntervalSet));
intervalParameters = new IntervalParameters(intervalSets, intervalList);
searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
assertEquals(searchParameters.getInterval(), intervalParameters);
}
Aggregations