From 650d91bead350d81a8e8816501059510c29b5909 Mon Sep 17 00:00:00 2001 From: Will Abson Date: Tue, 1 Jul 2014 14:58:46 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud) 75001: Merged WAT2 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 69930: Stats Get webscript now uses a configurable content model list git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@75330 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repository/solr/stats.get.json.ftl | 27 ++++++++- .../web-scripts-application-context.xml | 18 ++++++ .../repo/web/scripts/solr/StatsGet.java | 59 +++++++++++++++---- 3 files changed, 92 insertions(+), 12 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/stats.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/stats.get.json.ftl index 9f1f0d06d5..4ceb3abea9 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/stats.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/stats.get.json.ftl @@ -1,7 +1,14 @@ +<#if facets??> +[ + <#list facets as facet> + "${facet}"<#if facet_has_next>, + +] +<#else> { "resultset": [ <#list result.stats as item> - ["${jsonUtils.encodeJSONString(item.name)}",${item.sum?c}, ${item.count?c}] + ["${jsonUtils.encodeJSONString(item.name)}",${item.sum?c}, ${item.count?c}, ${item.min?c}, ${item.max?c}, ${item.mean?c}] <#if item_has_next>, ], @@ -27,6 +34,22 @@ "colIndex": 2, "colType": "Numeric", "colName": "count" + }, + { + "colIndex": 3, + "colType": "Numeric", + "colName": "min" + }, + { + "colIndex": 4, + "colType": "Numeric", + "colName": "max" + }, + { + "colIndex": 5, + "colType": "Numeric", + "colName": "mean" } ] -} \ No newline at end of file +} + \ No newline at end of file diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index f2447120cd..7e6ead6685 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1552,6 +1552,24 @@ class="org.alfresco.repo.web.scripts.solr.StatsGet" parent="webscript"> + + + + + + + + + + + + + + + + + + facets; + + public void setFacets(Map facets) + { + this.facets = facets; + } public void setStats(StatsService stats) { @@ -42,9 +48,18 @@ public class StatsGet extends DeclarativeWebScript @Override protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { + Map model = new HashMap(2, 1.0f); Map 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")); @@ -54,26 +69,39 @@ public class StatsGet extends DeclarativeWebScript } } - String contentProp = req.getParameter("contentProp"); - if (contentProp == null) contentProp = "created"; //default - - QName prop = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, contentProp); - + QName propFacet = findFacet(req.getParameter("facet")); String query = buildQuery(siteInfo); StatsParameters params = new StatsParameters(SearchService.LANGUAGE_SOLR_FTS_ALFRESCO, query); params.addSort(new SortDefinition(SortDefinition.SortType.FIELD, "contentsize", false)); params.addStatsParameter(StatsParameters.PARAM_FIELD, "contentsize"); - params.addStatsParameter(StatsParameters.PARAM_FACET, StatsParameters.FACET_PREFIX+prop.toString()); + params.addStatsParameter(StatsParameters.PARAM_FACET, StatsParameters.FACET_PREFIX+propFacet.toString()); StatsResultSet result = stats.query(params); - Map model = new HashMap(1, 1.0f); model.put("result", result); model.put("resultSize", result.getStats().size()); return model; } + /** + * Finds a facet based on its key + * @param facetKey + * @return QName facet + */ + private QName findFacet(String facetKey) + { + if (facetKey == null) facetKey = facets.entrySet().iterator().next().getKey(); //default + + if (!facets.containsKey(facetKey)) + { + throw new AccessDeniedException("Invalid facet key:"+facetKey); + } + + QName propFacet = QName.createQName(facets.get(facetKey)); + return propFacet; + } + protected String buildQuery(SiteInfo siteInfo) { StringBuilder luceneQuery = new StringBuilder(); @@ -85,5 +113,16 @@ public class StatsGet extends DeclarativeWebScript } return luceneQuery.toString(); } + + /** + * Allows you to add a facet to the list of available facets for Solr Statistics + * @param facetKey e.g. content.mimetype + * @param facetType e.g. @{http://www.alfresco.org/model/content/1.0}content.mimetype + */ + public void addFacet(String facetKey, String facetType) + { + facets.put(facetKey, facetType); + } + }