use of org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric in project alfresco-remote-api by Alfresco.
the class ResultMapper method getFacetBucketsForFacetFieldsAsFacets.
protected List<GenericFacetResponse> getFacetBucketsForFacetFieldsAsFacets(Map<String, List<Pair<String, Integer>>> facetFields, SearchQuery searchQuery) {
if (facetFields != null && !facetFields.isEmpty()) {
List<GenericFacetResponse> ffcs = new ArrayList<>(facetFields.size());
for (Entry<String, List<Pair<String, Integer>>> facet : facetFields.entrySet()) {
if (facet.getValue() != null && !facet.getValue().isEmpty()) {
List<GenericBucket> buckets = new ArrayList<>(facet.getValue().size());
for (Pair<String, Integer> buck : facet.getValue()) {
Object display = null;
String filterQuery = null;
if (searchQuery != null && searchQuery.getFacetFields() != null && searchQuery.getFacetFields().getFacets() != null && !searchQuery.getFacetFields().getFacets().isEmpty()) {
Optional<FacetField> found = searchQuery.getFacetFields().getFacets().stream().filter(queryable -> facet.getKey().equals(queryable.getLabel() != null ? queryable.getLabel() : queryable.getField())).findFirst();
if (found.isPresent()) {
display = propertyLookup.lookup(found.get().getField(), buck.getFirst());
String fq = found.get().toFilterQuery(buck.getFirst());
if (fq != null) {
filterQuery = fq;
}
}
}
GenericBucket bucket = new GenericBucket(buck.getFirst(), filterQuery, display, new HashSet<Metric>(Arrays.asList(new SimpleMetric(METRIC_TYPE.count, String.valueOf(buck.getSecond())))), null, null);
buckets.add(bucket);
}
ffcs.add(new GenericFacetResponse(FACET_TYPE.field, facet.getKey(), buckets));
}
}
return ffcs;
}
return Collections.emptyList();
}
use of org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric 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.repo.search.impl.solr.facet.facetsresponse.SimpleMetric in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method testRangeExclusiec.
@Test
public void testRangeExclusiec() throws Exception {
ResultSet results = mockResultset(Collections.emptyList(), Collections.emptyList());
String updatedJSON = helper.JSON.replace("lower", "upper");
SearchQuery searchQuery = helper.extractFromJson(updatedJSON);
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(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("false", facetInfo.get("startInclusive"));
assertEquals("true", facetInfo.get("endInclusive"));
}
use of org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric 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.repo.search.impl.solr.facet.facetsresponse.SimpleMetric in project alfresco-remote-api by Alfresco.
the class ResultMapper method getGenericFacetsForIntervals.
/**
* Returns generic faceting responses for Intervals
* @param facetFields
* @param searchQuery
* @return GenericFacetResponse
*/
protected static List<GenericFacetResponse> getGenericFacetsForIntervals(Map<String, List<Pair<String, Integer>>> facetFields, SearchQuery searchQuery) {
if (facetFields != null && !facetFields.isEmpty()) {
List<GenericFacetResponse> ffcs = new ArrayList<>(facetFields.size());
for (Entry<String, List<Pair<String, Integer>>> facet : facetFields.entrySet()) {
if (facet.getValue() != null && !facet.getValue().isEmpty()) {
List<GenericBucket> buckets = new ArrayList<>(facet.getValue().size());
for (Pair<String, Integer> buck : facet.getValue()) {
String filterQuery = null;
Map<String, String> bucketInfo = new HashMap<>();
if (searchQuery != null && searchQuery.getFacetIntervals() != null && searchQuery.getFacetIntervals().getIntervals() != null && !searchQuery.getFacetIntervals().getIntervals().isEmpty()) {
Optional<Interval> found = searchQuery.getFacetIntervals().getIntervals().stream().filter(interval -> facet.getKey().equals(interval.getLabel() != null ? interval.getLabel() : interval.getField())).findFirst();
if (found.isPresent()) {
if (found.get().getSets() != null) {
Optional<IntervalSet> foundSet = found.get().getSets().stream().filter(aSet -> buck.getFirst().equals(aSet.getLabel())).findFirst();
if (foundSet.isPresent()) {
filterQuery = found.get().getField() + ":" + foundSet.get().toAFTSQuery();
bucketInfo.put(GenericFacetResponse.START, foundSet.get().getStart());
bucketInfo.put(GenericFacetResponse.END, foundSet.get().getEnd());
bucketInfo.put(GenericFacetResponse.START_INC, String.valueOf(foundSet.get().isStartInclusive()));
bucketInfo.put(GenericFacetResponse.END_INC, String.valueOf(foundSet.get().isEndInclusive()));
}
}
}
}
GenericBucket bucket = new GenericBucket(buck.getFirst(), filterQuery, null, new HashSet<Metric>(Arrays.asList(new SimpleMetric(METRIC_TYPE.count, String.valueOf(buck.getSecond())))), null, bucketInfo);
buckets.add(bucket);
}
ffcs.add(new GenericFacetResponse(FACET_TYPE.interval, facet.getKey(), buckets));
}
}
return ffcs;
}
return Collections.emptyList();
}
Aggregations