Search in sources :

Example 6 with SearchQuery

use of org.alfresco.rest.api.search.model.SearchQuery in project alfresco-remote-api by Alfresco.

the class SearchQuerySerializerTests method testDeserializeQuery.

@Test
public void testDeserializeQuery() throws IOException {
    SearchQuery searchQuery = helper.searchQueryFromJson();
    assertEquals(SearchQuery.class, searchQuery.getClass());
    assertEquals("afts", searchQuery.getQuery().getLanguage());
    assertEquals("g*", searchQuery.getQuery().getQuery());
    assertEquals("great", searchQuery.getQuery().getUserQuery());
    assertEquals(99, searchQuery.getPaging().getMaxItems());
    assertEquals(4, searchQuery.getPaging().getSkipCount());
    assertEquals(2, searchQuery.getInclude().size());
    assertTrue(searchQuery.getInclude().contains("aspectNames"));
    assertTrue(searchQuery.getInclude().contains("properties"));
    assertEquals(1, searchQuery.getSort().size());
    assertEquals(2, searchQuery.getTemplates().size());
    Default defaults = searchQuery.getDefaults();
    assertEquals("namesp", defaults.getNamespace());
    assertEquals("myfield", defaults.getDefaultFieldName());
    assertEquals("AND", defaults.getDefaultFTSOperator());
    assertEquals(2, defaults.getTextAttributes().size());
    assertTrue(defaults.getTextAttributes().contains("roy"));
    assertTrue(defaults.getTextAttributes().contains("king"));
    assertEquals(2, searchQuery.getFilterQueries().size());
    assertEquals("myquery", searchQuery.getFilterQueries().get(0).getQuery());
    assertEquals(2, searchQuery.getFilterQueries().get(0).getTags().size());
    assertEquals("myquery2", searchQuery.getFilterQueries().get(1).getQuery());
    assertEquals(1, searchQuery.getFacetQueries().size());
    assertEquals("cm:created:bob", searchQuery.getFacetQueries().get(0).getQuery());
    assertEquals("small", searchQuery.getFacetQueries().get(0).getLabel());
    assertEquals("alfrezco", searchQuery.getSpellcheck().getQuery());
    assertEquals(1, searchQuery.getScope().getLocations().size());
    assertEquals(StoreMapper.LIVE_NODES, searchQuery.getScope().getLocations().get(0));
    assertEquals(3, searchQuery.getFacetFields().getFacets().size());
    FacetField ff = searchQuery.getFacetFields().getFacets().get(0);
    assertEquals("cm:creator", ff.getField());
    assertEquals("myquery2", ff.getPrefix());
    assertEquals("COUNT", ff.getSort());
    assertEquals(false, ff.getMissing());
    ff = searchQuery.getFacetFields().getFacets().get(1);
    assertEquals("modifier", ff.getField());
    assertEquals("mylabel", ff.getLabel());
    assertEquals("FC", ff.getMethod());
    assertEquals(Integer.valueOf(5), ff.getMincount());
    assertEquals(2000, searchQuery.getLimits().getPermissionEvaluationCount().intValue());
    assertEquals(5000, searchQuery.getLimits().getPermissionEvaluationTime().intValue());
    assertEquals(2, searchQuery.getFields().size());
    assertTrue(searchQuery.getFields().contains("id"));
    assertTrue(searchQuery.getFields().contains("name"));
    // Highlight
    assertEquals("]", searchQuery.getHighlight().getPostfix());
    assertEquals("[", searchQuery.getHighlight().getPrefix());
    assertEquals(20, searchQuery.getHighlight().getSnippetCount().intValue());
    assertEquals(10, searchQuery.getHighlight().getFragmentSize().intValue());
    assertEquals(true, searchQuery.getHighlight().getMergeContiguous());
    assertEquals(40, searchQuery.getHighlight().getMaxAnalyzedChars().intValue());
    assertEquals(true, searchQuery.getHighlight().getUsePhraseHighlighter());
    assertEquals(2, searchQuery.getHighlight().getFields().size());
    FieldHighlightParameters high1 = searchQuery.getHighlight().getFields().get(0);
    assertEquals("my", high1.getField());
    assertEquals("ยก", high1.getPostfix());
    assertEquals("?", high1.getPrefix());
    assertEquals(23, high1.getSnippetCount().intValue());
    assertEquals(5, high1.getFragmentSize().intValue());
    assertEquals(true, high1.getMergeContiguous());
    FieldHighlightParameters high2 = searchQuery.getHighlight().getFields().get(1);
    assertEquals("your", high2.getField());
    assertEquals(")", high2.getPostfix());
    assertEquals("(", high2.getPrefix());
    assertEquals(3, high2.getSnippetCount().intValue());
    assertEquals(15, high2.getFragmentSize().intValue());
    assertEquals(false, high2.getMergeContiguous());
    // Facet intervals
    IntervalParameters ip = searchQuery.getFacetIntervals();
    assertNotNull(ip);
    assertEquals(1, ip.getSets().size());
    IntervalSet expected = new IntervalSet("1", "2", "king", true, false);
    assertTrue(ip.getSets().contains(expected));
    assertEquals(2, ip.getIntervals().size());
    Interval interval = ip.getIntervals().get(0);
    assertEquals("creator", interval.getLabel());
    assertEquals("cm:creator", interval.getField());
    expected = new IntervalSet("a", "b", "last", false, true);
    assertTrue(interval.getSets().contains(expected));
    assertEquals(1, searchQuery.getPivots().size());
    assertEquals("mylabel", searchQuery.getPivots().get(0).getKey());
    assertEquals(1, searchQuery.getStats().size());
    assertEquals("cm:creator", searchQuery.getStats().get(0).getField());
    assertEquals("mylabel", searchQuery.getStats().get(0).getLabel());
    // Range Facet
    List<RangeParameters> ranges = searchQuery.getFacetRanges();
    assertNotNull(ranges);
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) IntervalParameters(org.alfresco.service.cmr.search.IntervalParameters) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) FacetField(org.alfresco.rest.api.search.model.FacetField) FieldHighlightParameters(org.alfresco.service.cmr.search.FieldHighlightParameters) RangeParameters(org.alfresco.service.cmr.search.RangeParameters) Default(org.alfresco.rest.api.search.model.Default) Interval(org.alfresco.service.cmr.search.Interval) Test(org.junit.Test)

Example 7 with SearchQuery

use of org.alfresco.rest.api.search.model.SearchQuery 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 8 with SearchQuery

use of org.alfresco.rest.api.search.model.SearchQuery in project alfresco-remote-api by Alfresco.

the class SearchApiWebscript method execute.

@Override
public void execute(WebScriptRequest webScriptRequest, WebScriptResponse webScriptResponse) throws IOException {
    try {
        // Turn JSON into a Java object respresentation
        SearchQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchQuery.class);
        // Parse the parameters
        Params params = getParams(webScriptRequest, searchQuery.getFields(), searchQuery.getInclude(), searchQuery.getPaging());
        // Make a copy of the request
        SearchRequestContext searchRequestContext = SearchRequestContext.from(searchQuery);
        // Turn the SearchQuery json into the Java SearchParameters object
        SearchParameters searchParams = searchMapper.toSearchParameters(params, searchQuery, searchRequestContext);
        // Call searchService
        ResultSet results = searchService.query(searchParams);
        // Turn solr results into JSON
        CollectionWithPagingInfo<Node> resultJson = resultMapper.toCollectionWithPagingInfo(params, searchRequestContext, searchQuery, results);
        // Post-process the request and pass in params, eg. params.getFilter()
        Object toRender = helper.processAdditionsToTheResponse(null, null, null, params, resultJson);
        // Write response
        setResponse(webScriptResponse, DEFAULT_SUCCESS);
        renderJsonResponse(webScriptResponse, toRender, assistant.getJsonHelper());
    } catch (Exception exception) {
        renderException(exception, webScriptResponse, assistant);
    }
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Node(org.alfresco.rest.api.model.Node) ResultSet(org.alfresco.service.cmr.search.ResultSet) Params(org.alfresco.rest.framework.resource.parameters.Params) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) IOException(java.io.IOException)

Example 9 with SearchQuery

use of org.alfresco.rest.api.search.model.SearchQuery 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 10 with SearchQuery

use of org.alfresco.rest.api.search.model.SearchQuery in project alfresco-remote-api by Alfresco.

the class ResultMapper method getFacetBucketsForFacetFields.

protected List<FacetFieldContext> getFacetBucketsForFacetFields(Map<String, List<Pair<String, Integer>>> facetFields, SearchQuery searchQuery) {
    if (facetFields != null && !facetFields.isEmpty()) {
        List<FacetFieldContext> ffcs = new ArrayList<>(facetFields.size());
        for (Entry<String, List<Pair<String, Integer>>> facet : facetFields.entrySet()) {
            if (facet.getValue() != null && !facet.getValue().isEmpty()) {
                List<Bucket> 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;
                            }
                        }
                    }
                    buckets.add(new Bucket(buck.getFirst(), filterQuery, buck.getSecond(), display));
                }
                ffcs.add(new FacetFieldContext(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) FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) ArrayList(java.util.ArrayList) FacetField(org.alfresco.rest.api.search.model.FacetField) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) Bucket(org.alfresco.rest.api.search.context.FacetFieldContext.Bucket) List(java.util.List) TupleList(org.alfresco.rest.api.search.model.TupleList) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject)

Aggregations

SearchQuery (org.alfresco.rest.api.search.model.SearchQuery)19 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)16 ResultSet (org.alfresco.service.cmr.search.ResultSet)15 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)14 SearchContext (org.alfresco.rest.api.search.context.SearchContext)14 Metric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric)13 SimpleMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric)13 Test (org.junit.Test)12 Node (org.alfresco.rest.api.model.Node)10 Params (org.alfresco.rest.framework.resource.parameters.Params)10 Serializable (java.io.Serializable)9 ArrayList (java.util.ArrayList)9 Arrays (java.util.Arrays)9 Collections (java.util.Collections)9 HashMap (java.util.HashMap)9 List (java.util.List)9 Map (java.util.Map)9 Set (java.util.Set)9 Collectors (java.util.stream.Collectors)9 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)9