Search in sources :

Example 1 with StatsParameters

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);
    }
}
Also used : Locale(java.util.Locale) SolrJsonProcessor(org.alfresco.repo.search.impl.lucene.SolrJsonProcessor) RangeParameters(org.alfresco.service.cmr.search.RangeParameters) URIException(org.apache.commons.httpclient.URIException) StringUtils(org.apache.commons.lang3.StringUtils) Header(org.apache.commons.httpclient.Header) DefaultTypeConverter(org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter) JSONResult(org.alfresco.repo.search.impl.lucene.JSONResult) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) PermissionService(org.alfresco.service.cmr.security.PermissionService) RepositoryState(org.alfresco.repo.admin.RepositoryState) NodeDAO(org.alfresco.repo.domain.node.NodeDAO) Locale(java.util.Locale) Map(java.util.Map) NodeService(org.alfresco.service.cmr.repository.NodeService) HttpStatus(org.apache.commons.httpclient.HttpStatus) ResultSet(org.alfresco.service.cmr.search.ResultSet) StatsParameters(org.alfresco.service.cmr.search.StatsParameters) QueryParserUtils(org.alfresco.repo.search.impl.QueryParserUtils) Set(java.util.Set) ShardRegistry(org.alfresco.repo.index.shard.ShardRegistry) Reader(java.io.Reader) CMISStrictDictionaryService(org.alfresco.opencmis.dictionary.CMISStrictDictionaryService) GetMethod(org.apache.commons.httpclient.methods.GetMethod) List(java.util.List) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) I18NUtil(org.springframework.extensions.surf.util.I18NUtil) HttpClient(org.apache.commons.httpclient.HttpClient) Entry(java.util.Map.Entry) Optional(java.util.Optional) LogFactory(org.apache.commons.logging.LogFactory) URI(org.apache.commons.httpclient.URI) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LimitBy(org.alfresco.service.cmr.search.LimitBy) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) Interval(org.alfresco.service.cmr.search.Interval) FieldFacet(org.alfresco.service.cmr.search.SearchParameters.FieldFacet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FieldFacetSort(org.alfresco.service.cmr.search.SearchParameters.FieldFacetSort) NamespaceDAO(org.alfresco.repo.dictionary.NamespaceDAO) ParameterCheck(org.alfresco.util.ParameterCheck) StatsRequestParameters(org.alfresco.service.cmr.search.StatsRequestParameters) HttpException(org.apache.commons.httpclient.HttpException) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) StoreRef(org.alfresco.service.cmr.repository.StoreRef) Iterator(java.util.Iterator) FieldFacetMethod(org.alfresco.service.cmr.search.SearchParameters.FieldFacetMethod) SearchDateConversion.parseDateInterval(org.alfresco.util.SearchDateConversion.parseDateInterval) FieldHighlightParameters(org.alfresco.service.cmr.search.FieldHighlightParameters) HttpServletResponse(javax.servlet.http.HttpServletResponse) JSONTokener(org.json.JSONTokener) Pair(org.alfresco.util.Pair) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) BeansException(org.springframework.beans.BeansException) InputStreamReader(java.io.InputStreamReader) TenantService(org.alfresco.repo.tenant.TenantService) BasicSearchParameters(org.alfresco.service.cmr.search.BasicSearchParameters) PermissionEvaluationMode(org.alfresco.service.cmr.search.PermissionEvaluationMode) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) SortDefinition(org.alfresco.service.cmr.search.SearchParameters.SortDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) SolrStatsResult(org.alfresco.repo.search.impl.lucene.SolrStatsResult) URLCodec(org.apache.commons.codec.net.URLCodec) StringJoiner(java.util.StringJoiner) BeanFactory(org.springframework.beans.factory.BeanFactory) PropertyCheck(org.alfresco.util.PropertyCheck) Log(org.apache.commons.logging.Log) BufferedReader(java.io.BufferedReader) Floc(org.alfresco.repo.index.shard.Floc) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) JSONArray(org.json.JSONArray) StoreRef(org.alfresco.service.cmr.repository.StoreRef) SolrStatsResult(org.alfresco.repo.search.impl.lucene.SolrStatsResult) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONException(org.json.JSONException) IOException(java.io.IOException) JSONObject(org.json.JSONObject) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) HttpClient(org.apache.commons.httpclient.HttpClient) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) HttpException(org.apache.commons.httpclient.HttpException)

Example 2 with StatsParameters

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;
}
Also used : StatsParameters(org.alfresco.service.cmr.search.StatsParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SortDefinition(org.alfresco.service.cmr.search.SearchParameters.SortDefinition)

Example 3 with StatsParameters

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;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) StatsParameters(org.alfresco.service.cmr.search.StatsParameters) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) LocalDate(org.joda.time.LocalDate) StatsProcessor(org.alfresco.service.cmr.search.StatsProcessor) StatsResultSet(org.alfresco.service.cmr.search.StatsResultSet)

Example 4 with StatsParameters

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"));
}
Also used : StatsParameters(org.alfresco.service.cmr.search.StatsParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 5 with StatsParameters

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"));
}
Also used : StatsParameters(org.alfresco.service.cmr.search.StatsParameters) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

StatsParameters (org.alfresco.service.cmr.search.StatsParameters)5 HashMap (java.util.HashMap)2 SortDefinition (org.alfresco.service.cmr.search.SearchParameters.SortDefinition)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Set (java.util.Set)1 StringJoiner (java.util.StringJoiner)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1