mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
75000: Merged WAT2 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 69908: Initial version of Solr Stats service and webscript git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@75329 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Get solr statistics</shortname>
|
||||||
|
<description>Get some basic statics from solr</description>
|
||||||
|
<url>/api/solr/site/{siteId}/stats</url>
|
||||||
|
<url>/api/solr/stats</url>
|
||||||
|
<format default="json">argument</format>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction allow="readonly">required</transaction>
|
||||||
|
<family>SOLR</family>
|
||||||
|
</webscript>
|
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"resultset": [
|
||||||
|
<#list result.stats as item>
|
||||||
|
["${jsonUtils.encodeJSONString(item.name)}",${item.sum?c}, ${item.count?c}]
|
||||||
|
<#if item_has_next>,</#if>
|
||||||
|
</#list>
|
||||||
|
],
|
||||||
|
"queryInfo": {
|
||||||
|
"numberFound": "${result.numberFound?c}",
|
||||||
|
"totalRows": "${resultSize?c}",
|
||||||
|
"sum": "${result.sum?c}",
|
||||||
|
"max": "${result.max?c}",
|
||||||
|
"mean": "${result.mean?c}"
|
||||||
|
},
|
||||||
|
"metadata": [
|
||||||
|
{
|
||||||
|
"colIndex": 0,
|
||||||
|
"colType": "String",
|
||||||
|
"colName": "name"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"colIndex": 1,
|
||||||
|
"colType": "Numeric",
|
||||||
|
"colName": "sum"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"colIndex": 2,
|
||||||
|
"colType": "Numeric",
|
||||||
|
"colName": "count"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@@ -1548,6 +1548,12 @@
|
|||||||
<property name="solrTrackingComponent" ref="solrTrackingComponent"/>
|
<property name="solrTrackingComponent" ref="solrTrackingComponent"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="webscript.org.alfresco.repository.solr.stats.get"
|
||||||
|
class="org.alfresco.repo.web.scripts.solr.StatsGet" parent="webscript">
|
||||||
|
<property name="stats" ref="statsService"/>
|
||||||
|
<property name="siteService" ref="SiteService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean id="webscript.org.alfresco.repository.solr.nodes.post"
|
<bean id="webscript.org.alfresco.repository.solr.nodes.post"
|
||||||
class="org.alfresco.repo.web.scripts.solr.NodesGet"
|
class="org.alfresco.repo.web.scripts.solr.NodesGet"
|
||||||
parent="webscript">
|
parent="webscript">
|
||||||
|
89
source/java/org/alfresco/repo/web/scripts/solr/StatsGet.java
Normal file
89
source/java/org/alfresco/repo/web/scripts/solr/StatsGet.java
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package org.alfresco.repo.web.scripts.solr;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||||
|
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition;
|
||||||
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
|
import org.alfresco.service.cmr.search.StatsParameters;
|
||||||
|
import org.alfresco.service.cmr.search.StatsResultSet;
|
||||||
|
import org.alfresco.service.cmr.search.StatsService;
|
||||||
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
|
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets stats on Solr content
|
||||||
|
*
|
||||||
|
* @author Gethin James
|
||||||
|
*/
|
||||||
|
public class StatsGet extends DeclarativeWebScript
|
||||||
|
{
|
||||||
|
StatsService stats;
|
||||||
|
SiteService siteService;
|
||||||
|
|
||||||
|
public void setStats(StatsService stats)
|
||||||
|
{
|
||||||
|
this.stats = stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSiteService(SiteService siteService)
|
||||||
|
{
|
||||||
|
this.siteService = siteService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
|
{
|
||||||
|
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||||
|
SiteInfo siteInfo = null;
|
||||||
|
|
||||||
|
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 contentProp = req.getParameter("contentProp");
|
||||||
|
if (contentProp == null) contentProp = "created"; //default
|
||||||
|
|
||||||
|
QName prop = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, contentProp);
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
StatsResultSet result = stats.query(params);
|
||||||
|
|
||||||
|
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
|
||||||
|
model.put("result", result);
|
||||||
|
model.put("resultSize", result.getStats().size());
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String buildQuery(SiteInfo siteInfo)
|
||||||
|
{
|
||||||
|
StringBuilder luceneQuery = new StringBuilder();
|
||||||
|
luceneQuery.append("TYPE:\"" + ContentModel.TYPE_CONTENT + "\"");
|
||||||
|
|
||||||
|
if (siteInfo != null)
|
||||||
|
{
|
||||||
|
luceneQuery.append(" AND ANCESTOR:\""+siteInfo.getNodeRef().toString()+"\"");
|
||||||
|
}
|
||||||
|
return luceneQuery.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user