use of org.alfresco.service.cmr.search.StatsProcessor in project alfresco-remote-api by Alfresco.
the class StatsGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>(2, 1.0f);
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
SiteInfo siteInfo = null;
String listFacets = req.getParameter("listFacets");
if (listFacets != null) {
model.put("facets", facets.keySet());
model.put("resultSize", 0);
return model;
}
if (templateVars != null && templateVars.containsKey("siteId")) {
siteInfo = siteService.getSite(templateVars.get("siteId"));
if (siteInfo == null) {
throw new AccessDeniedException("No such site: " + templateVars.get("siteId"));
}
}
String facetKey = req.getParameter("facet");
// default
if (facetKey == null)
facetKey = facets.entrySet().iterator().next().getKey();
String query;
QName propFacet = findFacet(facetKey);
Pair<LocalDate, LocalDate> startAndEnd = getStartAndEndDates(req.getParameter("startDate"), req.getParameter("endDate"));
query = buildQuery(siteInfo, facetKey, startAndEnd);
StatsParameters params = new StatsParameters(SearchService.LANGUAGE_SOLR_FTS_ALFRESCO, query, false);
// params.addSort(new SortDefinition(SortDefinition.SortType.FIELD, this.statsField, false));
params.addStatsParameter(StatsParameters.PARAM_FIELD, this.statsField);
params.addStatsParameter(StatsParameters.PARAM_FACET, StatsParameters.FACET_PREFIX + propFacet.toString());
StatsResultSet result = stats.query(params);
if (postProcessors.containsKey(facetKey)) {
StatsProcessor processor = postProcessors.get(facetKey);
result = processor.process(result);
}
model.put("result", result);
model.put("resultSize", result.getStats().size());
return model;
}
Aggregations