Search in sources :

Example 1 with GenericFacetResponse

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

the class ResultMapperTests method testRangeExclusiec.

@Test
public void testRangeExclusiec() throws Exception {
    ResultSet results = mockResultset(Collections.emptyList(), Collections.emptyList());
    String updatedJSON = helper.JSON.replace("lower", "upper");
    SearchQuery searchQuery = helper.extractFromJson(updatedJSON);
    SearchRequestContext searchRequest = SearchRequestContext.from(searchQuery);
    SearchParameters searchParams = searchMapper.toSearchParameters(EMPTY_PARAMS, searchQuery, searchRequest);
    SearchContext searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchRequest, searchQuery, 0);
    // Numeric facet range
    List<GenericFacetResponse> rangeFacets = searchContext.getFacets().stream().filter(f -> f.getType().equals(FACET_TYPE.range)).collect(Collectors.toList());
    assertEquals(2, rangeFacets.size());
    assertEquals(4, rangeFacets.get(0).getBuckets().size());
    assertEquals(3, rangeFacets.get(1).getBuckets().size());
    assertEquals("content.size", rangeFacets.get(1).getLabel());
    assertEquals("(0 - 100]", rangeFacets.get(1).getBuckets().get(0).getLabel());
    Object[] metrics = rangeFacets.get(1).getBuckets().get(0).getMetrics().toArray();
    assertEquals("4", ((SimpleMetric) metrics[0]).getValue().get("count"));
    assertEquals("content.size:<\"0\" TO \"100\"]", rangeFacets.get(1).getBuckets().get(0).getFilterQuery());
    assertEquals(null, rangeFacets.get(1).getBuckets().get(0).getBucketInfo().get("count"));
    Map<String, String> facetInfo = rangeFacets.get(1).getBuckets().get(0).getBucketInfo();
    assertEquals("0", facetInfo.get("start"));
    assertEquals("100", facetInfo.get("end"));
    assertEquals("false", facetInfo.get("startInclusive"));
    assertEquals("true", facetInfo.get("endInclusive"));
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) Arrays(java.util.Arrays) SearchContext(org.alfresco.rest.api.search.context.SearchContext) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) VersionService(org.alfresco.service.cmr.version.VersionService) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) JSONException(org.json.JSONException) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) JSONObject(org.json.JSONObject) PercentileMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric) Params(org.alfresco.rest.framework.resource.parameters.Params) Node(org.alfresco.rest.api.model.Node) Map(java.util.Map) METRIC_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE) SearchMapper(org.alfresco.rest.api.search.impl.SearchMapper) NodeService(org.alfresco.service.cmr.repository.NodeService) TestCase.assertFalse(junit.framework.TestCase.assertFalse) ResultSet(org.alfresco.service.cmr.search.ResultSet) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) DeletedNodes(org.alfresco.rest.api.DeletedNodes) FacetQueryContext(org.alfresco.rest.api.search.context.FacetQueryContext) Set(java.util.Set) TestCase.assertNull(junit.framework.TestCase.assertNull) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Version2Model(org.alfresco.repo.version.Version2Model) VersionImpl(org.alfresco.repo.version.common.VersionImpl) Stream(java.util.stream.Stream) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) TestCase.assertTrue(junit.framework.TestCase.assertTrue) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Mockito.mock(org.mockito.Mockito.mock) NodeVersionsRelation(org.alfresco.rest.api.nodes.NodeVersionsRelation) LimitBy(org.alfresco.service.cmr.search.LimitBy) TupleList(org.alfresco.rest.api.search.model.TupleList) StoreMapper(org.alfresco.rest.api.search.impl.StoreMapper) BeforeClass(org.junit.BeforeClass) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) 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) GeneralHighlightParameters(org.alfresco.service.cmr.search.GeneralHighlightParameters) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResultMapper(org.alfresco.rest.api.search.impl.ResultMapper) GUID(org.alfresco.util.GUID) QName(org.alfresco.service.namespace.QName) PropertyLookupRegistry(org.alfresco.rest.api.lookups.PropertyLookupRegistry) StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodesImpl(org.alfresco.rest.api.impl.NodesImpl) FieldHighlightParameters(org.alfresco.service.cmr.search.FieldHighlightParameters) JSONTokener(org.json.JSONTokener) Matchers.notNull(org.mockito.Matchers.notNull) ServiceRegistry(org.alfresco.service.ServiceRegistry) IOException(java.io.IOException) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) PersonPropertyLookup(org.alfresco.rest.api.lookups.PersonPropertyLookup) FACET_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) ListMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Collections(java.util.Collections) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) JSONArray(org.json.JSONArray) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) SearchContext(org.alfresco.rest.api.search.context.SearchContext) Matchers.anyString(org.mockito.Matchers.anyString) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Example 2 with GenericFacetResponse

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

the class ResultMapperTests method testIsNullContext.

@Test
public void testIsNullContext() throws Exception {
    assertTrue(mapper.isNullContext(new SearchContext(0l, null, null, null, null, null)));
    assertFalse(mapper.isNullContext(new SearchContext(1l, null, null, null, null, null)));
    assertFalse(mapper.isNullContext(new SearchContext(0l, null, null, null, new SpellCheckContext(null, null), null)));
    assertFalse(mapper.isNullContext(new SearchContext(0l, null, Arrays.asList(new FacetQueryContext(null, null, 0)), null, null, null)));
    assertFalse(mapper.isNullContext(new SearchContext(0l, null, null, Arrays.asList(new FacetFieldContext(null, null)), null, null)));
    assertFalse(mapper.isNullContext(new SearchContext(0l, Arrays.asList(new GenericFacetResponse(null, null, null)), null, null, null, null)));
}
Also used : FacetQueryContext(org.alfresco.rest.api.search.context.FacetQueryContext) FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) SearchContext(org.alfresco.rest.api.search.context.SearchContext) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext) Test(org.junit.Test)

Example 3 with GenericFacetResponse

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

the class ResultMapperTests method testInterval.

@Test
public void testInterval() throws Exception {
    ResultSet results = mockResultset(Collections.emptyList(), Collections.emptyList());
    SearchQuery searchQuery = helper.searchQueryFromJson();
    SearchRequestContext searchRequest = SearchRequestContext.from(searchQuery);
    SearchParameters searchParams = searchMapper.toSearchParameters(EMPTY_PARAMS, searchQuery, searchRequest);
    SearchContext searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchRequest, searchQuery, 0);
    // Facet intervals
    List<GenericFacetResponse> intervalFacets = searchContext.getFacets().stream().filter(f -> f.getType().equals(FACET_TYPE.interval)).collect(Collectors.toList());
    assertEquals(2, intervalFacets.size());
    assertEquals("creator", intervalFacets.get(0).getLabel());
    assertEquals("last", intervalFacets.get(0).getBuckets().get(0).getLabel());
    assertEquals("cm:creator:<\"a\" TO \"b\"]", intervalFacets.get(0).getBuckets().get(0).getFilterQuery());
    Object[] metrics = intervalFacets.get(0).getBuckets().get(0).getMetrics().toArray();
    assertEquals(METRIC_TYPE.count, ((SimpleMetric) metrics[0]).getType());
    assertEquals("4", ((SimpleMetric) metrics[0]).getValue().get("count"));
    metrics = intervalFacets.get(1).getBuckets().get(0).getMetrics().toArray();
    assertEquals("TheCreated", intervalFacets.get(1).getLabel());
    assertEquals("earlier", intervalFacets.get(1).getBuckets().get(0).getLabel());
    assertEquals("cm:created:[\"*\" TO \"2016\">", intervalFacets.get(1).getBuckets().get(0).getFilterQuery());
    assertEquals(METRIC_TYPE.count, ((SimpleMetric) metrics[0]).getType());
    assertEquals("5", ((SimpleMetric) metrics[0]).getValue().get("count"));
    metrics = intervalFacets.get(1).getBuckets().get(1).getMetrics().toArray();
    assertEquals("lastYear", intervalFacets.get(1).getBuckets().get(1).getLabel());
    assertEquals("cm:created:[\"2016\" TO \"2017\">", intervalFacets.get(1).getBuckets().get(1).getFilterQuery());
    assertEquals(METRIC_TYPE.count, ((SimpleMetric) metrics[0]).getType());
    assertEquals("0", ((SimpleMetric) metrics[0]).getValue().get("count"));
    metrics = intervalFacets.get(1).getBuckets().get(2).getMetrics().toArray();
    assertEquals("currentYear", intervalFacets.get(1).getBuckets().get(2).getLabel());
    assertEquals("cm:created:[\"NOW/YEAR\" TO \"NOW/YEAR+1YEAR\"]", intervalFacets.get(1).getBuckets().get(2).getFilterQuery());
    assertEquals(METRIC_TYPE.count, ((SimpleMetric) metrics[0]).getType());
    assertEquals("854", ((SimpleMetric) metrics[0]).getValue().get("count"));
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) Arrays(java.util.Arrays) SearchContext(org.alfresco.rest.api.search.context.SearchContext) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) VersionService(org.alfresco.service.cmr.version.VersionService) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) JSONException(org.json.JSONException) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) JSONObject(org.json.JSONObject) PercentileMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric) Params(org.alfresco.rest.framework.resource.parameters.Params) Node(org.alfresco.rest.api.model.Node) Map(java.util.Map) METRIC_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE) SearchMapper(org.alfresco.rest.api.search.impl.SearchMapper) NodeService(org.alfresco.service.cmr.repository.NodeService) TestCase.assertFalse(junit.framework.TestCase.assertFalse) ResultSet(org.alfresco.service.cmr.search.ResultSet) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) DeletedNodes(org.alfresco.rest.api.DeletedNodes) FacetQueryContext(org.alfresco.rest.api.search.context.FacetQueryContext) Set(java.util.Set) TestCase.assertNull(junit.framework.TestCase.assertNull) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Version2Model(org.alfresco.repo.version.Version2Model) VersionImpl(org.alfresco.repo.version.common.VersionImpl) Stream(java.util.stream.Stream) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) TestCase.assertTrue(junit.framework.TestCase.assertTrue) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Mockito.mock(org.mockito.Mockito.mock) NodeVersionsRelation(org.alfresco.rest.api.nodes.NodeVersionsRelation) LimitBy(org.alfresco.service.cmr.search.LimitBy) TupleList(org.alfresco.rest.api.search.model.TupleList) StoreMapper(org.alfresco.rest.api.search.impl.StoreMapper) BeforeClass(org.junit.BeforeClass) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) 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) GeneralHighlightParameters(org.alfresco.service.cmr.search.GeneralHighlightParameters) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResultMapper(org.alfresco.rest.api.search.impl.ResultMapper) GUID(org.alfresco.util.GUID) QName(org.alfresco.service.namespace.QName) PropertyLookupRegistry(org.alfresco.rest.api.lookups.PropertyLookupRegistry) StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodesImpl(org.alfresco.rest.api.impl.NodesImpl) FieldHighlightParameters(org.alfresco.service.cmr.search.FieldHighlightParameters) JSONTokener(org.json.JSONTokener) Matchers.notNull(org.mockito.Matchers.notNull) ServiceRegistry(org.alfresco.service.ServiceRegistry) IOException(java.io.IOException) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) PersonPropertyLookup(org.alfresco.rest.api.lookups.PersonPropertyLookup) FACET_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) ListMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Collections(java.util.Collections) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) JSONArray(org.json.JSONArray) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) SearchContext(org.alfresco.rest.api.search.context.SearchContext) JSONObject(org.json.JSONObject) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) Test(org.junit.Test)

Example 4 with GenericFacetResponse

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

the class ResultMapperTests method testRange.

@Test
public void testRange() throws Exception {
    ResultSet results = mockResultset(Collections.emptyList(), Collections.emptyList());
    SearchQuery searchQuery = helper.searchQueryFromJson();
    SearchRequestContext searchRequest = SearchRequestContext.from(searchQuery);
    SearchParameters searchParams = searchMapper.toSearchParameters(EMPTY_PARAMS, searchQuery, searchRequest);
    SearchContext searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchRequest, searchQuery, 0);
    // Numeric facet range
    List<GenericFacetResponse> rangeFacets = searchContext.getFacets().stream().filter(f -> f.getType().equals(FACET_TYPE.range)).collect(Collectors.toList());
    assertEquals(2, rangeFacets.size());
    assertEquals(4, rangeFacets.get(0).getBuckets().size());
    assertEquals("created", rangeFacets.get(0).getLabel());
    assertEquals("[2015-09-29T10:45:15.729Z - 2016-01-07T10:45:15.729Z)", rangeFacets.get(0).getBuckets().get(0).getLabel());
    Object[] metrics1 = rangeFacets.get(0).getBuckets().get(0).getMetrics().toArray();
    assertEquals("0", ((SimpleMetric) metrics1[0]).getValue().get("count"));
    assertEquals("created:[\"2015-09-29T10:45:15.729Z\" TO \"2016-01-07T10:45:15.729Z\">", rangeFacets.get(0).getBuckets().get(0).getFilterQuery());
    assertEquals(null, rangeFacets.get(0).getBuckets().get(0).getBucketInfo().get("count"));
    assertEquals("false", rangeFacets.get(0).getBuckets().get(0).getBucketInfo().get("endInclusive"));
    assertEquals("true", rangeFacets.get(0).getBuckets().get(0).getBucketInfo().get("startInclusive"));
    assertEquals(3, rangeFacets.get(1).getBuckets().size());
    assertEquals("content.size", rangeFacets.get(1).getLabel());
    assertEquals("[0 - 100)", rangeFacets.get(1).getBuckets().get(0).getLabel());
    Object[] metrics = rangeFacets.get(1).getBuckets().get(0).getMetrics().toArray();
    assertEquals("4", ((SimpleMetric) metrics[0]).getValue().get("count"));
    assertEquals("content.size:[\"0\" TO \"100\">", rangeFacets.get(1).getBuckets().get(0).getFilterQuery());
    assertEquals(null, rangeFacets.get(1).getBuckets().get(0).getBucketInfo().get("count"));
    Map<String, String> facetInfo = rangeFacets.get(1).getBuckets().get(0).getBucketInfo();
    assertEquals("0", facetInfo.get("start"));
    assertEquals("100", facetInfo.get("end"));
    assertEquals("[100 - 200)", rangeFacets.get(1).getBuckets().get(1).getLabel());
    metrics = rangeFacets.get(1).getBuckets().get(1).getMetrics().toArray();
    assertEquals("6", ((SimpleMetric) metrics[0]).getValue().get("count"));
    facetInfo = rangeFacets.get(1).getBuckets().get(1).getBucketInfo();
    assertEquals("100", facetInfo.get("start"));
    assertEquals("200", facetInfo.get("end"));
    assertEquals("content.size:[\"100\" TO \"200\">", rangeFacets.get(1).getBuckets().get(1).getFilterQuery());
    assertEquals(null, rangeFacets.get(1).getBuckets().get(1).getBucketInfo().get("count"));
    assertEquals("false", rangeFacets.get(1).getBuckets().get(0).getBucketInfo().get("endInclusive"));
    assertEquals("true", rangeFacets.get(1).getBuckets().get(0).getBucketInfo().get("startInclusive"));
    assertEquals("[200 - 300)", rangeFacets.get(1).getBuckets().get(2).getLabel());
    metrics = rangeFacets.get(1).getBuckets().get(2).getMetrics().toArray();
    assertEquals("3", ((SimpleMetric) metrics[0]).getValue().get("count"));
    facetInfo = rangeFacets.get(1).getBuckets().get(2).getBucketInfo();
    assertEquals("200", facetInfo.get("start"));
    assertEquals("300", facetInfo.get("end"));
    assertEquals("content.size:[\"200\" TO \"300\">", rangeFacets.get(1).getBuckets().get(2).getFilterQuery());
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) Arrays(java.util.Arrays) SearchContext(org.alfresco.rest.api.search.context.SearchContext) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) VersionService(org.alfresco.service.cmr.version.VersionService) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) JSONException(org.json.JSONException) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) JSONObject(org.json.JSONObject) PercentileMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric) Params(org.alfresco.rest.framework.resource.parameters.Params) Node(org.alfresco.rest.api.model.Node) Map(java.util.Map) METRIC_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE) SearchMapper(org.alfresco.rest.api.search.impl.SearchMapper) NodeService(org.alfresco.service.cmr.repository.NodeService) TestCase.assertFalse(junit.framework.TestCase.assertFalse) ResultSet(org.alfresco.service.cmr.search.ResultSet) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) DeletedNodes(org.alfresco.rest.api.DeletedNodes) FacetQueryContext(org.alfresco.rest.api.search.context.FacetQueryContext) Set(java.util.Set) TestCase.assertNull(junit.framework.TestCase.assertNull) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Version2Model(org.alfresco.repo.version.Version2Model) VersionImpl(org.alfresco.repo.version.common.VersionImpl) Stream(java.util.stream.Stream) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) TestCase.assertTrue(junit.framework.TestCase.assertTrue) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Mockito.mock(org.mockito.Mockito.mock) NodeVersionsRelation(org.alfresco.rest.api.nodes.NodeVersionsRelation) LimitBy(org.alfresco.service.cmr.search.LimitBy) TupleList(org.alfresco.rest.api.search.model.TupleList) StoreMapper(org.alfresco.rest.api.search.impl.StoreMapper) BeforeClass(org.junit.BeforeClass) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) 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) GeneralHighlightParameters(org.alfresco.service.cmr.search.GeneralHighlightParameters) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResultMapper(org.alfresco.rest.api.search.impl.ResultMapper) GUID(org.alfresco.util.GUID) QName(org.alfresco.service.namespace.QName) PropertyLookupRegistry(org.alfresco.rest.api.lookups.PropertyLookupRegistry) StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodesImpl(org.alfresco.rest.api.impl.NodesImpl) FieldHighlightParameters(org.alfresco.service.cmr.search.FieldHighlightParameters) JSONTokener(org.json.JSONTokener) Matchers.notNull(org.mockito.Matchers.notNull) ServiceRegistry(org.alfresco.service.ServiceRegistry) IOException(java.io.IOException) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) PersonPropertyLookup(org.alfresco.rest.api.lookups.PersonPropertyLookup) FACET_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) ListMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Collections(java.util.Collections) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) JSONArray(org.json.JSONArray) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) SearchContext(org.alfresco.rest.api.search.context.SearchContext) Matchers.anyString(org.mockito.Matchers.anyString) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Example 5 with GenericFacetResponse

use of org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse 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)

Aggregations

GenericFacetResponse (org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse)9 FacetFieldContext (org.alfresco.rest.api.search.context.FacetFieldContext)9 FacetQueryContext (org.alfresco.rest.api.search.context.FacetQueryContext)9 SearchContext (org.alfresco.rest.api.search.context.SearchContext)9 SpellCheckContext (org.alfresco.rest.api.search.context.SpellCheckContext)9 Serializable (java.io.Serializable)8 ArrayList (java.util.ArrayList)8 Arrays (java.util.Arrays)8 Collections (java.util.Collections)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)8 GenericBucket (org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket)8 FACET_TYPE (org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE)8 Metric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric)8 METRIC_TYPE (org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE)8 SimpleMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric)8