Search in sources :

Example 1 with Metric

use of org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric in project alfresco-remote-api by Alfresco.

the class ResultMapper method getFacetBucketsForFacetFieldsAsFacets.

protected List<GenericFacetResponse> getFacetBucketsForFacetFieldsAsFacets(Map<String, List<Pair<String, Integer>>> facetFields, SearchQuery searchQuery) {
    if (facetFields != null && !facetFields.isEmpty()) {
        List<GenericFacetResponse> ffcs = new ArrayList<>(facetFields.size());
        for (Entry<String, List<Pair<String, Integer>>> facet : facetFields.entrySet()) {
            if (facet.getValue() != null && !facet.getValue().isEmpty()) {
                List<GenericBucket> buckets = new ArrayList<>(facet.getValue().size());
                for (Pair<String, Integer> buck : facet.getValue()) {
                    Object display = null;
                    String filterQuery = null;
                    if (searchQuery != null && searchQuery.getFacetFields() != null && searchQuery.getFacetFields().getFacets() != null && !searchQuery.getFacetFields().getFacets().isEmpty()) {
                        Optional<FacetField> found = searchQuery.getFacetFields().getFacets().stream().filter(queryable -> facet.getKey().equals(queryable.getLabel() != null ? queryable.getLabel() : queryable.getField())).findFirst();
                        if (found.isPresent()) {
                            display = propertyLookup.lookup(found.get().getField(), buck.getFirst());
                            String fq = found.get().toFilterQuery(buck.getFirst());
                            if (fq != null) {
                                filterQuery = fq;
                            }
                        }
                    }
                    GenericBucket bucket = new GenericBucket(buck.getFirst(), filterQuery, display, new HashSet<Metric>(Arrays.asList(new SimpleMetric(METRIC_TYPE.count, String.valueOf(buck.getSecond())))), null, null);
                    buckets.add(bucket);
                }
                ffcs.add(new GenericFacetResponse(FACET_TYPE.field, facet.getKey(), buckets));
            }
        }
        return ffcs;
    }
    return Collections.emptyList();
}
Also used : Arrays(java.util.Arrays) SearchContext(org.alfresco.rest.api.search.context.SearchContext) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) LIVE_NODES(org.alfresco.rest.api.search.impl.StoreMapper.LIVE_NODES) Paging(org.alfresco.rest.framework.resource.parameters.Paging) FacetFormat(org.alfresco.service.cmr.search.FacetFormat) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Params(org.alfresco.rest.framework.resource.parameters.Params) Node(org.alfresco.rest.api.model.Node) Map(java.util.Map) HISTORY(org.alfresco.rest.api.search.impl.StoreMapper.HISTORY) METRIC_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE) ResultSet(org.alfresco.service.cmr.search.ResultSet) TupleEntry(org.alfresco.rest.api.search.model.TupleEntry) DeletedNodes(org.alfresco.rest.api.DeletedNodes) FacetQueryContext(org.alfresco.rest.api.search.context.FacetQueryContext) Set(java.util.Set) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) Version2Model(org.alfresco.repo.version.Version2Model) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext) Bucket(org.alfresco.rest.api.search.context.FacetFieldContext.Bucket) Entry(java.util.Map.Entry) Optional(java.util.Optional) Nodes(org.alfresco.rest.api.Nodes) LogFactory(org.apache.commons.logging.LogFactory) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) NodeVersionsRelation(org.alfresco.rest.api.nodes.NodeVersionsRelation) TupleList(org.alfresco.rest.api.search.model.TupleList) DELETED(org.alfresco.rest.api.search.impl.StoreMapper.DELETED) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) Interval(org.alfresco.service.cmr.search.Interval) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) UserInfo(org.alfresco.rest.api.model.UserInfo) HashMap(java.util.HashMap) SearchEntry(org.alfresco.rest.api.search.model.SearchEntry) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) FacetField(org.alfresco.rest.api.search.model.FacetField) QName(org.alfresco.service.namespace.QName) RangeResultMapper(org.alfresco.repo.search.impl.solr.facet.facetsresponse.RangeResultMapper) PropertyLookupRegistry(org.alfresco.rest.api.lookups.PropertyLookupRegistry) ServiceRegistry(org.alfresco.service.ServiceRegistry) Pair(org.alfresco.util.Pair) FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) FACET_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) VERSIONS(org.alfresco.rest.api.search.impl.StoreMapper.VERSIONS) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) Log(org.apache.commons.logging.Log) Collections(java.util.Collections) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SpellCheckResult(org.alfresco.service.cmr.search.SpellCheckResult) JSONArray(org.json.JSONArray) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) ArrayList(java.util.ArrayList) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) FacetField(org.alfresco.rest.api.search.model.FacetField) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) List(java.util.List) TupleList(org.alfresco.rest.api.search.model.TupleList) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric)

Example 2 with Metric

use of org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric in project alfresco-remote-api by Alfresco.

the class ResultMapperTests method testFacetingGroupResponse.

@Test
public /**
 * Test facet group with out facet fields
 * @throws Exception
 */
void testFacetingGroupResponse() throws Exception {
    String jsonQuery = "{\"query\": {\"query\": \"alfresco\"}," + "\"facetQueries\": [" + "{\"query\": \"content.size:[o TO 102400]\", \"label\": \"small\",\"group\":\"foo\"}," + "{\"query\": \"content.size:[102400 TO 1048576]\", \"label\": \"medium\",\"group\":\"foo\"}," + "{\"query\": \"content.size:[1048576 TO 16777216]\", \"label\": \"large\",\"group\":\"foo\"}]" + "}";
    String expectedResponse = "{\"responseHeader\":{\"status\":0,\"QTime\":9},\"_original_parameters_\":\"org.apache.solr.common.params.DefaultSolrParams:{params(df=TEXT&alternativeDic=DEFAULT_DICTIONARY&fl=DBID,score&start=0&fq={!afts}AUTHORITY_FILTER_FROM_JSON&fq={!afts}TENANT_FILTER_FROM_JSON&rows=1000&locale=en_US&wt=json),defaults(carrot.url=id&spellcheck.collateExtendedResults=true&carrot.produceSummary=true&spellcheck.maxCollations=3&spellcheck.maxCollationTries=5&spellcheck.alternativeTermCount=2&spellcheck.extendedResults=false&defType=afts&spellcheck.maxResultsForSuggest=5&spellcheck=false&carrot.outputSubClusters=false&spellcheck.count=5&carrot.title=mltext@m___t@{http://www.alfresco.org/model/content/1.0}title&carrot.snippet=content@s___t@{http://www.alfresco.org/model/content/1.0}content&spellcheck.collate=true)}\",\"_field_mappings_\":{},\"_date_mappings_\":{},\"_range_mappings_\":{},\"_pivot_mappings_\":{},\"_interval_mappings_\":{},\"_stats_field_mappings_\":{},\"_stats_facet_mappings_\":{},\"_facet_function_mappings_\":{},\"response\":{\"numFound\":6,\"start\":0,\"maxScore\":0.7849362,\"docs\":[{\"DBID\":565,\"score\":0.7849362},{\"DBID\":566,\"score\":0.7849362},{\"DBID\":521,\"score\":0.3540957},{\"DBID\":514,\"score\":0.33025497},{\"DBID\":420,\"score\":0.32440513},{\"DBID\":415,\"score\":0.2780319}]}," + "\"spellcheck\":{\"searchInsteadFor\":\"alfresco\"}," + "\"facet_counts\":{\"facet_queries\": {\"small\": 52,\"large\": 0,\"medium\": 0}}," + "\"processedDenies\":true, \"lastIndexedTx\":34}";
    ResultSet results = mockResultset(expectedResponse);
    SearchQuery searchQuery = helper.extractFromJson(jsonQuery);
    SearchRequestContext searchRequest = SearchRequestContext.from(searchQuery);
    SearchContext searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchRequest, searchQuery, 0);
    assertEquals(34l, searchContext.getConsistency().getlastTxId());
    assertEquals(null, searchContext.getFacetQueries());
    assertEquals(1, searchContext.getFacets().size());
    assertEquals(3, searchContext.getFacets().get(0).getBuckets().size());
    assertEquals("small", searchContext.getFacets().get(0).getBuckets().get(0).getLabel());
    assertEquals("content.size:[o TO 102400]", searchContext.getFacets().get(0).getBuckets().get(0).getFilterQuery());
    assertFalse(searchContext.getFacets().get(0).getBuckets().get(0).getMetrics().isEmpty());
    Metric[] metrics = searchContext.getFacets().get(0).getBuckets().get(0).getMetrics().toArray(new Metric[searchContext.getFacets().get(0).getBuckets().get(0).getMetrics().size()]);
    assertEquals(METRIC_TYPE.count, metrics[0].getType());
    assertEquals("{count=52}", metrics[0].getValue().toString());
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SearchContext(org.alfresco.rest.api.search.context.SearchContext) PercentileMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) ListMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric) Mockito.anyString(org.mockito.Mockito.anyString) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) Test(org.junit.Test)

Example 3 with Metric

use of org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric in project alfresco-repository by Alfresco.

the class SolrJSONResultSet method buildPivot.

protected List<GenericFacetResponse> buildPivot(JSONObject facet_pivot, String pivotName, List<RangeParameters> rangeParameters) throws JSONException {
    if (!facet_pivot.has(pivotName))
        return Collections.emptyList();
    JSONArray pivots = facet_pivot.getJSONArray(pivotName);
    Map<String, List<GenericBucket>> pivotBuckets = new HashMap<>(pivots.length());
    List<GenericFacetResponse> facetResponses = new ArrayList<>();
    for (int i = 0; i < pivots.length(); i++) {
        JSONObject piv = pivots.getJSONObject(i);
        Set<Metric> metrics = new HashSet<>(1);
        List<GenericFacetResponse> nested = new ArrayList<>();
        String field = piv.getString("field");
        String value = piv.getString("value");
        if (piv.has("stats")) {
            JSONObject stats = piv.getJSONObject("stats");
            Map<String, Map<String, Object>> pivotStats = buildStats(stats);
            pivotStats.forEach((pKey, pVal) -> {
                metrics.addAll(getMetrics(pVal));
            });
        }
        Integer count = Integer.valueOf(piv.getInt("count"));
        metrics.add(new SimpleMetric(METRIC_TYPE.count, count));
        nested.addAll(buildPivot(piv, "pivot", rangeParameters));
        if (piv.has("ranges")) {
            JSONObject ranges = piv.getJSONObject("ranges");
            Map<String, List<Map<String, String>>> builtRanges = buildRanges(ranges);
            List<GenericFacetResponse> rangefacets = RangeResultMapper.getGenericFacetsForRanges(builtRanges, rangeParameters);
            nested.addAll(rangefacets);
        }
        GenericBucket buck = new GenericBucket(value, field + ":\"" + value + "\"", null, metrics, nested);
        List<GenericBucket> listBucks = pivotBuckets.containsKey(field) ? pivotBuckets.get(field) : new ArrayList<>();
        listBucks.add(buck);
        pivotBuckets.put(field, listBucks);
    }
    for (Map.Entry<String, List<GenericBucket>> entry : pivotBuckets.entrySet()) {
        facetResponses.add(new GenericFacetResponse(FACET_TYPE.pivot, entry.getKey(), entry.getValue()));
    }
    if (!facetResponses.isEmpty())
        return facetResponses;
    return Collections.emptyList();
}
Also used : HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) ArrayList(java.util.ArrayList) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) JSONObject(org.json.JSONObject) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) ArrayList(java.util.ArrayList) List(java.util.List) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) PercentileMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric) ListMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with Metric

use of org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric in project alfresco-remote-api by Alfresco.

the class ResultMapper method getGenericFacetsForIntervals.

/**
 * Returns generic faceting responses for Intervals
 * @param facetFields
 * @param searchQuery
 * @return GenericFacetResponse
 */
protected static List<GenericFacetResponse> getGenericFacetsForIntervals(Map<String, List<Pair<String, Integer>>> facetFields, SearchQuery searchQuery) {
    if (facetFields != null && !facetFields.isEmpty()) {
        List<GenericFacetResponse> ffcs = new ArrayList<>(facetFields.size());
        for (Entry<String, List<Pair<String, Integer>>> facet : facetFields.entrySet()) {
            if (facet.getValue() != null && !facet.getValue().isEmpty()) {
                List<GenericBucket> buckets = new ArrayList<>(facet.getValue().size());
                for (Pair<String, Integer> buck : facet.getValue()) {
                    String filterQuery = null;
                    Map<String, String> bucketInfo = new HashMap<>();
                    if (searchQuery != null && searchQuery.getFacetIntervals() != null && searchQuery.getFacetIntervals().getIntervals() != null && !searchQuery.getFacetIntervals().getIntervals().isEmpty()) {
                        Optional<Interval> found = searchQuery.getFacetIntervals().getIntervals().stream().filter(interval -> facet.getKey().equals(interval.getLabel() != null ? interval.getLabel() : interval.getField())).findFirst();
                        if (found.isPresent()) {
                            if (found.get().getSets() != null) {
                                Optional<IntervalSet> foundSet = found.get().getSets().stream().filter(aSet -> buck.getFirst().equals(aSet.getLabel())).findFirst();
                                if (foundSet.isPresent()) {
                                    filterQuery = found.get().getField() + ":" + foundSet.get().toAFTSQuery();
                                    bucketInfo.put(GenericFacetResponse.START, foundSet.get().getStart());
                                    bucketInfo.put(GenericFacetResponse.END, foundSet.get().getEnd());
                                    bucketInfo.put(GenericFacetResponse.START_INC, String.valueOf(foundSet.get().isStartInclusive()));
                                    bucketInfo.put(GenericFacetResponse.END_INC, String.valueOf(foundSet.get().isEndInclusive()));
                                }
                            }
                        }
                    }
                    GenericBucket bucket = new GenericBucket(buck.getFirst(), filterQuery, null, new HashSet<Metric>(Arrays.asList(new SimpleMetric(METRIC_TYPE.count, String.valueOf(buck.getSecond())))), null, bucketInfo);
                    buckets.add(bucket);
                }
                ffcs.add(new GenericFacetResponse(FACET_TYPE.interval, facet.getKey(), buckets));
            }
        }
        return ffcs;
    }
    return Collections.emptyList();
}
Also used : Arrays(java.util.Arrays) SearchContext(org.alfresco.rest.api.search.context.SearchContext) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) LIVE_NODES(org.alfresco.rest.api.search.impl.StoreMapper.LIVE_NODES) Paging(org.alfresco.rest.framework.resource.parameters.Paging) FacetFormat(org.alfresco.service.cmr.search.FacetFormat) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Params(org.alfresco.rest.framework.resource.parameters.Params) Node(org.alfresco.rest.api.model.Node) Map(java.util.Map) HISTORY(org.alfresco.rest.api.search.impl.StoreMapper.HISTORY) METRIC_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE) ResultSet(org.alfresco.service.cmr.search.ResultSet) TupleEntry(org.alfresco.rest.api.search.model.TupleEntry) DeletedNodes(org.alfresco.rest.api.DeletedNodes) FacetQueryContext(org.alfresco.rest.api.search.context.FacetQueryContext) Set(java.util.Set) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) Version2Model(org.alfresco.repo.version.Version2Model) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext) Bucket(org.alfresco.rest.api.search.context.FacetFieldContext.Bucket) Entry(java.util.Map.Entry) Optional(java.util.Optional) Nodes(org.alfresco.rest.api.Nodes) LogFactory(org.apache.commons.logging.LogFactory) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) NodeVersionsRelation(org.alfresco.rest.api.nodes.NodeVersionsRelation) TupleList(org.alfresco.rest.api.search.model.TupleList) DELETED(org.alfresco.rest.api.search.impl.StoreMapper.DELETED) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) Interval(org.alfresco.service.cmr.search.Interval) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) UserInfo(org.alfresco.rest.api.model.UserInfo) HashMap(java.util.HashMap) SearchEntry(org.alfresco.rest.api.search.model.SearchEntry) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) FacetField(org.alfresco.rest.api.search.model.FacetField) QName(org.alfresco.service.namespace.QName) RangeResultMapper(org.alfresco.repo.search.impl.solr.facet.facetsresponse.RangeResultMapper) PropertyLookupRegistry(org.alfresco.rest.api.lookups.PropertyLookupRegistry) ServiceRegistry(org.alfresco.service.ServiceRegistry) Pair(org.alfresco.util.Pair) FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) FACET_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) VERSIONS(org.alfresco.rest.api.search.impl.StoreMapper.VERSIONS) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) Log(org.apache.commons.logging.Log) Collections(java.util.Collections) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SpellCheckResult(org.alfresco.service.cmr.search.SpellCheckResult) JSONArray(org.json.JSONArray) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) HashMap(java.util.HashMap) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) ArrayList(java.util.ArrayList) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) List(java.util.List) TupleList(org.alfresco.rest.api.search.model.TupleList) ArrayList(java.util.ArrayList) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) Interval(org.alfresco.service.cmr.search.Interval)

Example 5 with Metric

use of org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric in project alfresco-remote-api by Alfresco.

the class ResultMapper method getFacetBucketsFromFacetQueries.

/**
 * Builds a facet field from facet queries.
 * @param facetQueries
 * @return
 */
protected List<GenericFacetResponse> getFacetBucketsFromFacetQueries(Map<String, Integer> facetQueries, SearchQuery searchQuery) {
    List<GenericFacetResponse> facetResults = new ArrayList<GenericFacetResponse>();
    Map<String, List<GenericBucket>> groups = new HashMap<>();
    for (Entry<String, Integer> fq : facetQueries.entrySet()) {
        String group = null;
        String filterQuery = null;
        if (searchQuery != null && searchQuery.getFacetQueries() != null) {
            Optional<FacetQuery> found = searchQuery.getFacetQueries().stream().filter(facetQuery -> fq.getKey().equals(facetQuery.getLabel())).findFirst();
            filterQuery = found.isPresent() ? found.get().getQuery() : fq.getKey();
            if (found.isPresent() && found.get().getGroup() != null) {
                group = found.get().getGroup();
            }
        }
        // {
        if (groups.containsKey(group)) {
            Set<Metric> metrics = new HashSet<>(1);
            metrics.add(new SimpleMetric(METRIC_TYPE.count, fq.getValue()));
            groups.get(group).add(new GenericBucket(fq.getKey(), filterQuery, null, metrics, null));
        } else {
            List<GenericBucket> l = new ArrayList<GenericBucket>();
            Set<Metric> metrics = new HashSet<>(1);
            metrics.add(new SimpleMetric(METRIC_TYPE.count, fq.getValue()));
            l.add(new GenericBucket(fq.getKey(), filterQuery, null, metrics, null));
            groups.put(group, l);
        }
    }
    // }
    if (!groups.isEmpty()) {
        groups.forEach((a, v) -> facetResults.add(new GenericFacetResponse(FACET_TYPE.query, a, v)));
    }
    return facetResults;
}
Also used : Arrays(java.util.Arrays) SearchContext(org.alfresco.rest.api.search.context.SearchContext) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) LIVE_NODES(org.alfresco.rest.api.search.impl.StoreMapper.LIVE_NODES) Paging(org.alfresco.rest.framework.resource.parameters.Paging) FacetFormat(org.alfresco.service.cmr.search.FacetFormat) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Params(org.alfresco.rest.framework.resource.parameters.Params) Node(org.alfresco.rest.api.model.Node) Map(java.util.Map) HISTORY(org.alfresco.rest.api.search.impl.StoreMapper.HISTORY) METRIC_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE) ResultSet(org.alfresco.service.cmr.search.ResultSet) TupleEntry(org.alfresco.rest.api.search.model.TupleEntry) DeletedNodes(org.alfresco.rest.api.DeletedNodes) FacetQueryContext(org.alfresco.rest.api.search.context.FacetQueryContext) Set(java.util.Set) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) Version2Model(org.alfresco.repo.version.Version2Model) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext) Bucket(org.alfresco.rest.api.search.context.FacetFieldContext.Bucket) Entry(java.util.Map.Entry) Optional(java.util.Optional) Nodes(org.alfresco.rest.api.Nodes) LogFactory(org.apache.commons.logging.LogFactory) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) NodeVersionsRelation(org.alfresco.rest.api.nodes.NodeVersionsRelation) TupleList(org.alfresco.rest.api.search.model.TupleList) DELETED(org.alfresco.rest.api.search.impl.StoreMapper.DELETED) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) Interval(org.alfresco.service.cmr.search.Interval) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) UserInfo(org.alfresco.rest.api.model.UserInfo) HashMap(java.util.HashMap) SearchEntry(org.alfresco.rest.api.search.model.SearchEntry) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) FacetField(org.alfresco.rest.api.search.model.FacetField) QName(org.alfresco.service.namespace.QName) RangeResultMapper(org.alfresco.repo.search.impl.solr.facet.facetsresponse.RangeResultMapper) PropertyLookupRegistry(org.alfresco.rest.api.lookups.PropertyLookupRegistry) ServiceRegistry(org.alfresco.service.ServiceRegistry) Pair(org.alfresco.util.Pair) FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) FACET_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) VERSIONS(org.alfresco.rest.api.search.impl.StoreMapper.VERSIONS) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) Log(org.apache.commons.logging.Log) Collections(java.util.Collections) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SpellCheckResult(org.alfresco.service.cmr.search.SpellCheckResult) JSONArray(org.json.JSONArray) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) HashMap(java.util.HashMap) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) ArrayList(java.util.ArrayList) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) List(java.util.List) TupleList(org.alfresco.rest.api.search.model.TupleList) ArrayList(java.util.ArrayList) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) HashSet(java.util.HashSet)

Aggregations

Metric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric)10 SimpleMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric)10 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)8 SearchContext (org.alfresco.rest.api.search.context.SearchContext)8 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)8 SearchQuery (org.alfresco.rest.api.search.model.SearchQuery)8 ResultSet (org.alfresco.service.cmr.search.ResultSet)8 GenericBucket (org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket)6 ListMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric)6 PercentileMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)5 GenericFacetResponse (org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse)5 Serializable (java.io.Serializable)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4