use of org.alfresco.service.cmr.search.StatsParameters in project alfresco-repository by Alfresco.
the class SolrQueryHTTPClient method executeStatsQuery.
/**
* Executes a solr query for statistics
*
* @param searchParameters StatsParameters
* @return SolrStatsResult
*/
public SolrStatsResult executeStatsQuery(final StatsParameters searchParameters) {
if (repositoryState.isBootstrapping()) {
throw new AlfrescoRuntimeException("SOLR stats queries can not be executed while the repository is bootstrapping");
}
try {
StoreRef store = SolrClientUtil.extractStoreRef(searchParameters);
SolrStoreMappingWrapper mapping = SolrClientUtil.extractMapping(store, mappingLookup, shardRegistry, useDynamicShardRegistration, beanFactory);
Locale locale = SolrClientUtil.extractLocale(searchParameters);
Pair<HttpClient, String> httpClientAndBaseUrl = mapping.getHttpClientAndBaseUrl();
HttpClient httpClient = httpClientAndBaseUrl.getFirst();
String url = buildStatsUrl(searchParameters, httpClientAndBaseUrl.getSecond(), locale, mapping);
JSONObject body = buildStatsBody(searchParameters, tenantService.getCurrentUserDomain(), locale);
if (httpClient == null) {
throw new AlfrescoRuntimeException("No http client for store " + store.toString());
}
return (SolrStatsResult) postSolrQuery(httpClient, url, body, json -> {
return new SolrStatsResult(json, searchParameters.isDateSearch());
});
} catch (UnsupportedEncodingException e) {
throw new LuceneQueryParserException("stats", e);
} catch (HttpException e) {
throw new LuceneQueryParserException("stats", e);
} catch (IOException e) {
throw new LuceneQueryParserException("stats", e);
} catch (JSONException e) {
throw new LuceneQueryParserException("stats", e);
}
}
use of org.alfresco.service.cmr.search.StatsParameters in project alfresco-repository by Alfresco.
the class SolrQueryHTTPClientTest method getParameters.
private StatsParameters getParameters() {
StringBuilder luceneQuery = new StringBuilder();
luceneQuery.append(" +TYPE:\"" + ContentModel.TYPE_CONTENT + "\"");
String filterQuery = "ANCESTOR:\"workspace://SpacesStore/a1c1a0a1-9d68-4912-b853-b3b277f31288\"";
StatsParameters params = new StatsParameters(SearchService.LANGUAGE_SOLR_FTS_ALFRESCO, luceneQuery.toString(), filterQuery, false);
params.addSort(new SortDefinition(SortDefinition.SortType.FIELD, "contentsize", false));
params.addStatsParameter(StatsParameters.PARAM_FIELD, "contentsize");
params.addStatsParameter(StatsParameters.PARAM_FACET, StatsParameters.FACET_PREFIX + ContentModel.PROP_CREATED.toString());
params.addStatsParameter("Test1", StatsParameters.FACET_PREFIX + "author. .u");
params.addStatsParameter("Test2", StatsParameters.FACET_PREFIX + "creator. .u");
return params;
}
use of org.alfresco.service.cmr.search.StatsParameters 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;
}
use of org.alfresco.service.cmr.search.StatsParameters in project alfresco-repository by Alfresco.
the class SolrQueryHTTPClientTest method testBuildStatsUrl.
@Test
public void testBuildStatsUrl() throws UnsupportedEncodingException {
StatsParameters params = getParameters();
String url = client.buildStatsUrl(params, "http://localhost:8080/solr/alfresco/select", Locale.CANADA_FRENCH, null);
assertNotNull(url);
assertTrue(url.contains("locale=fr_CA"));
assertTrue(url.contains("sort=contentsize"));
assertTrue(url.contains("fq=ANCESTOR"));
}
use of org.alfresco.service.cmr.search.StatsParameters in project alfresco-repository by Alfresco.
the class SolrQueryHTTPClientTest method testBuildStatsBody.
@Test
public void testBuildStatsBody() throws JSONException {
StatsParameters params = getParameters();
JSONObject body = client.buildStatsBody(params, "myTenant", Locale.US);
assertNotNull(body);
JSONArray tenant = body.getJSONArray("tenants");
assertEquals("myTenant", tenant.get(0).toString());
JSONArray locale = body.getJSONArray("locales");
assertEquals("en_US", locale.get(0).toString());
String query = body.getString("query");
assertTrue(query.contains("TYPE:"));
assertTrue(query.contains("{http://www.alfresco.org/model/content/1.0}content"));
}
Aggregations