use of org.alfresco.service.cmr.search.ResultSet in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method testToSearchContext.
@Test
public void testToSearchContext() 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);
assertEquals(34l, searchContext.getConsistency().getlastTxId());
assertEquals(6, searchContext.getFacetQueries().size());
assertEquals(0, searchContext.getFacetQueries().get(0).getCount());
assertEquals("cm:created:bob", searchContext.getFacetQueries().get(0).getFilterQuery());
assertEquals("small", searchContext.getFacetQueries().get(0).getLabel());
assertEquals("searchInsteadFor", searchContext.getSpellCheck().getType());
assertEquals(1, searchContext.getSpellCheck().getSuggestions().size());
assertEquals("alfresco", searchContext.getSpellCheck().getSuggestions().get(0));
assertEquals(1, searchContext.getFacetsFields().size());
assertEquals("content.size", searchContext.getFacetsFields().get(0).getLabel());
// 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());
Metric[] metrics = intervalFacets.get(0).getBuckets().get(0).getMetrics().toArray(new Metric[intervalFacets.get(0).getBuckets().get(0).getMetrics().size()]);
assertEquals(METRIC_TYPE.count, metrics[0].getType());
assertEquals("4", metrics[0].getValue().get("count"));
// Requests search Query
assertNotNull(searchContext.getRequest());
assertEquals("great", searchContext.getRequest().getQuery().getUserQuery());
// Pivot
assertEquals(7, searchContext.getFacets().size());
GenericFacetResponse pivotFacet = searchContext.getFacets().get(4);
assertEquals(FACET_TYPE.pivot, pivotFacet.getType());
assertEquals("creator", pivotFacet.getLabel());
assertEquals(2, pivotFacet.getBuckets().size());
GenericBucket pivotBucket = pivotFacet.getBuckets().get(1);
assertEquals("mjackson", pivotBucket.getLabel());
assertEquals("creator:\"mjackson\"", pivotBucket.getFilterQuery());
metrics = pivotBucket.getMetrics().toArray(new Metric[pivotBucket.getMetrics().size()]);
assertEquals("{count=7}", metrics[0].getValue().toString());
assertEquals(1, pivotBucket.getFacets().size());
GenericFacetResponse nestedFacet = pivotBucket.getFacets().get(0);
assertEquals(FACET_TYPE.pivot, nestedFacet.getType());
assertEquals("mylabel", nestedFacet.getLabel());
assertEquals(2, nestedFacet.getBuckets().size());
GenericBucket nestedBucket = nestedFacet.getBuckets().get(0);
assertEquals("mjackson", nestedBucket.getLabel());
assertEquals("modifier:\"mjackson\"", nestedBucket.getFilterQuery());
metrics = nestedBucket.getMetrics().toArray(new Metric[nestedBucket.getMetrics().size()]);
assertEquals("{count=3}", metrics[0].getValue().toString());
GenericBucket nestedBucket2 = nestedFacet.getBuckets().get(1);
assertEquals("admin", nestedBucket2.getLabel());
assertEquals("modifier:\"admin\"", nestedBucket2.getFilterQuery());
metrics = nestedBucket2.getMetrics().toArray(new Metric[nestedBucket2.getMetrics().size()]);
assertEquals("{count=4}", metrics[0].getValue().toString());
// Stats
GenericFacetResponse statsFacet = searchContext.getFacets().get(5);
assertEquals(FACET_TYPE.stats, statsFacet.getType());
assertEquals("created", statsFacet.getLabel());
Set<Metric> statsMetrics = statsFacet.getBuckets().get(0).getMetrics();
assertEquals(8, statsMetrics.size());
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.sumOfSquares, 2.1513045770343806E27)));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.min, "2011-02-15T20:16:27.080Z")));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.max, "2017-04-10T15:06:30.143Z")));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.mean, "2016-09-05T04:20:12.898Z")));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.countValues, 990)));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.missing, 290)));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.sum, 1.458318720769983E15)));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.stddev, 5.6250677994522545E10)));
statsFacet = searchContext.getFacets().get(6);
assertEquals("numericLabel", statsFacet.getLabel());
statsMetrics = statsFacet.getBuckets().get(0).getMetrics();
assertEquals(7, statsMetrics.size());
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.sumOfSquares, 0)));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.countValues, 0)));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.missing, 0)));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.sum, 0)));
assertTrue(statsMetrics.contains(new SimpleMetric(METRIC_TYPE.stddev, 0)));
JSONArray dVals = new JSONArray(Arrays.asList(12, 13, 14, 15, 16, 17, 1));
assertTrue(statsMetrics.contains(new ListMetric(METRIC_TYPE.distinctValues, dVals)));
JSONArray pers = new JSONArray(Arrays.asList("0.99", 20.0685, "0.0", 12.0));
assertTrue(statsMetrics.contains(new PercentileMetric(METRIC_TYPE.percentiles, pers)));
assertEquals("min must be excluded because its null", 0, statsMetrics.stream().filter(metric -> METRIC_TYPE.min.equals(metric.getType())).count());
assertEquals("max must be excluded because its null", 0, statsMetrics.stream().filter(metric -> METRIC_TYPE.max.equals(metric.getType())).count());
assertEquals("mean must be excluded because its NaN", 0, statsMetrics.stream().filter(metric -> METRIC_TYPE.mean.equals(metric.getType())).count());
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method testFacetQueryWithoutGroupResponse.
@Test
public /**
* Test facet fields with out group label in the query.
* This is to support original api methods query for facet query.
*
* @throws Exception
*/
void testFacetQueryWithoutGroupResponse() throws Exception {
String jsonQuery = "{\"query\": {\"query\": \"alfresco\"}," + "\"facetQueries\": [" + "{\"query\": \"content.size:[0 TO 102400]\", \"label\": \"small\"}," + "{\"query\": \"content.size:[102400 TO 1048576]\", \"label\": \"medium\"}," + "{\"query\": \"content.size:[1048576 TO 16777216]\", \"label\": \"large\"}]" + "}";
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());
assertTrue(searchContext.getFacets().isEmpty());
assertEquals(3, searchContext.getFacetQueries().size());
assertEquals("small", searchContext.getFacetQueries().get(0).getLabel());
assertEquals("content.size:[0 TO 102400]", searchContext.getFacetQueries().get(0).getFilterQuery());
assertEquals(52, searchContext.getFacetQueries().get(0).getCount());
assertEquals("large", searchContext.getFacetQueries().get(1).getLabel());
assertEquals("content.size:[1048576 TO 16777216]", searchContext.getFacetQueries().get(1).getFilterQuery());
assertEquals(0, searchContext.getFacetQueries().get(1).getCount());
assertEquals("medium", searchContext.getFacetQueries().get(2).getLabel());
assertEquals("content.size:[102400 TO 1048576]", searchContext.getFacetQueries().get(2).getFilterQuery());
assertEquals(0, searchContext.getFacetQueries().get(2).getCount());
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method facetFormatTest.
@Test
public /**
* Validates that when facetFormat is specified then all facets are returned
* in the generic facet response format AKA V2.
*/
void facetFormatTest() throws Exception {
String jsonQuery = "{\"query\": {\"query\": \"alfresco\"}," + "\"facetQueries\": [" + "{\"query\": \"content.size:[0 TO 102400]\", \"label\": \"small\"}," + "{\"query\": \"content.size:[102400 TO 1048576]\", \"label\": \"medium\"}," + "{\"query\": \"content.size:[1048576 TO 16777216]\", \"label\": \"large\"}]" + ",\"facetFormat\":\"V2\"" + "}";
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:[0 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());
jsonQuery = jsonQuery.replace("V2", "V1");
searchQuery = helper.extractFromJson(jsonQuery);
results = mockResultset(expectedResponse);
searchRequest = SearchRequestContext.from(searchQuery);
searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchRequest, searchQuery, 0);
assertEquals(34l, searchContext.getConsistency().getlastTxId());
assertEquals(3, searchContext.getFacetQueries().size());
assertEquals("small", searchContext.getFacetQueries().get(0).getLabel());
assertEquals("content.size:[0 TO 102400]", searchContext.getFacetQueries().get(0).getFilterQuery());
assertEquals(52, searchContext.getFacetQueries().get(0).getCount());
assertEquals("large", searchContext.getFacetQueries().get(1).getLabel());
// FacetField Test
jsonQuery = "{\"query\": {\"query\": \"A*\"}," + "\"facetFields\": {\"facets\": [" + "{\"field\": \"creator\", \"mincount\": 1}," + "{\"field\": \"modifier\", \"mincount\": 1}]}," + "\"facetFormat\":\"V1\"}";
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_fields\":{\"creator\":[\"System\",124,\"mjackson\",11,\"abeecher\",4],\"modifier\":[\"System\",124,\"mjackson\",8,\"admin\",7]}}," + "\"processedDenies\":true, \"lastIndexedTx\":34}";
results = mockResultset(expectedResponse);
searchQuery = helper.extractFromJson(jsonQuery);
searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchRequest, searchQuery, 0);
assertFalse(searchContext.getFacetsFields().isEmpty());
assertTrue(searchContext.getFacets().isEmpty());
assertEquals("creator", searchContext.getFacetsFields().get(0).getLabel());
assertEquals(3, searchContext.getFacetsFields().get(0).getBuckets().size());
assertEquals(124, searchContext.getFacetsFields().get(0).getBuckets().get(0).getCount());
assertEquals("creator:\"System\"", searchContext.getFacetsFields().get(0).getBuckets().get(0).getFilterQuery());
assertEquals("System", searchContext.getFacetsFields().get(0).getBuckets().get(0).getLabel());
assertEquals("modifier", searchContext.getFacetsFields().get(1).getLabel());
jsonQuery = jsonQuery.replace("V1", "V2");
searchQuery = helper.extractFromJson(jsonQuery);
searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchRequest, searchQuery, 0);
assertTrue(searchContext.getFacetsFields().isEmpty());
assertFalse(searchContext.getFacets().isEmpty());
assertEquals("creator", searchContext.getFacets().get(0).getLabel());
assertEquals(3, searchContext.getFacets().get(0).getBuckets().size());
metrics = searchContext.getFacets().get(0).getBuckets().get(0).getMetrics().toArray(new Metric[searchContext.getFacets().get(0).getBuckets().get(0).getMetrics().size()]);
assertEquals("{count=124}", metrics[0].getValue().toString());
assertEquals("creator:\"System\"", searchContext.getFacets().get(0).getBuckets().get(0).getFilterQuery());
assertEquals("System", searchContext.getFacets().get(0).getBuckets().get(0).getLabel());
assertEquals("modifier", searchContext.getFacets().get(1).getLabel());
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method testFacetingWithPartialGroup.
@Test
public /**
* When the following is passed
* "facetQueries": [
* {"query": "content.size:[0 TO 102400]", "label": "small", "group": "one"},
* {"query": "content.size:[102400 TO 1048576]", "label": "medium", "group": "two"},
* {"query": "content.size:[1048576 TO 16777216]", "label": "large"}
* We expect to see 3 groups of 1,2,null.
* @throws Exception
*/
void testFacetingWithPartialGroup() throws Exception {
String jsonQuery = "{\"query\": {\"query\": \"alfresco\"}," + "\"facetQueries\": [" + "{\"query\": \"content.size:[o TO 102400]\", \"label\": \"small\",\"group\":\"1\"}," + "{\"query\": \"content.size:[102400 TO 1048576]\", \"label\": \"medium\",\"group\":\"2\"}," + "{\"query\": \"content.size:[1048576 TO 16777216]\", \"label\": \"large\"}]" + "}";
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(3, searchContext.getFacets().size());
assertEquals(1, searchContext.getFacets().get(0).getBuckets().size());
assertEquals(1, searchContext.getFacets().get(1).getBuckets().size());
assertEquals(1, searchContext.getFacets().get(2).getBuckets().size());
assertEquals("large", searchContext.getFacets().get(0).getBuckets().get(0).getLabel());
assertEquals("small", searchContext.getFacets().get(1).getBuckets().get(0).getLabel());
assertEquals("medium", searchContext.getFacets().get(2).getBuckets().get(0).getLabel());
assertEquals("content.size:[o TO 102400]", searchContext.getFacets().get(1).getBuckets().get(0).getFilterQuery());
assertFalse(searchContext.getFacets().get(0).getBuckets().get(0).getMetrics().isEmpty());
Metric[] metrics = searchContext.getFacets().get(1).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());
}
use of org.alfresco.service.cmr.search.ResultSet in project records-management by Alfresco.
the class RMAfterInvocationProvider method decide.
private ResultSet decide(Authentication authentication, Object object, ConfigAttributeDefinition config, ResultSet returnedObject) {
if (returnedObject == null) {
return null;
}
class RMFilteringResultSet extends FilteringResultSet {
private long numberFound;
public RMFilteringResultSet(ResultSet unfiltered, BitSet inclusionMask) {
super(unfiltered, inclusionMask);
}
@Override
public long getNumberFound() {
return numberFound;
}
private void setNumberFound(long numberFound) {
this.numberFound = numberFound;
}
}
BitSet inclusionMask = new BitSet(returnedObject.length());
RMFilteringResultSet filteringResultSet = new RMFilteringResultSet(returnedObject, inclusionMask);
List<ConfigAttributeDefintion> supportedDefinitions = extractSupportedDefinitions(config);
Integer maxSize = null;
if (returnedObject.getResultSetMetaData().getSearchParameters().getMaxItems() >= 0) {
maxSize = Integer.valueOf(returnedObject.getResultSetMetaData().getSearchParameters().getMaxItems());
}
if ((maxSize == null) && (returnedObject.getResultSetMetaData().getSearchParameters().getLimitBy() == LimitBy.FINAL_SIZE)) {
maxSize = Integer.valueOf(returnedObject.getResultSetMetaData().getSearchParameters().getLimit());
}
// Allow for skip
if ((maxSize != null) && (returnedObject.getResultSetMetaData().getSearchParameters().getSkipCount() >= 0)) {
maxSize = Integer.valueOf(maxSize + returnedObject.getResultSetMetaData().getSearchParameters().getSkipCount());
}
if (supportedDefinitions.size() == 0) {
if (maxSize == null) {
return returnedObject;
} else if (returnedObject.length() > maxSize.intValue()) {
for (int i = 0; i < maxSize.intValue(); i++) {
inclusionMask.set(i, true);
}
filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(returnedObject.getResultSetMetaData().getLimitedBy(), PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
return filteringResultSet;
} else {
for (int i = 0; i < returnedObject.length(); i++) {
inclusionMask.set(i, true);
}
filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(returnedObject.getResultSetMetaData().getLimitedBy(), PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
return filteringResultSet;
}
}
// record the start time
long startTimeMillis = System.currentTimeMillis();
// set the default, unlimited resultset type
filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(returnedObject.getResultSetMetaData().getLimitedBy(), PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
for (int i = 0; i < returnedObject.length(); i++) {
long currentTimeMillis = System.currentTimeMillis();
// All permission checks must pass
inclusionMask.set(i, true);
if (!nodeService.exists(returnedObject.getNodeRef(i))) {
inclusionMask.set(i, false);
} else {
int parentCheckRead = checkRead(returnedObject.getChildAssocRef(i).getParentRef());
int childCheckRead = checkRead(returnedObject.getNodeRef(i));
for (ConfigAttributeDefintion cad : supportedDefinitions) {
NodeRef testNodeRef = returnedObject.getNodeRef(i);
int checkRead = childCheckRead;
if (cad.parent) {
testNodeRef = returnedObject.getChildAssocRef(i).getParentRef();
checkRead = parentCheckRead;
}
if (isUnfiltered(testNodeRef)) {
continue;
}
if (inclusionMask.get(i) && (testNodeRef != null) && (checkRead != AccessDecisionVoter.ACCESS_GRANTED)) {
inclusionMask.set(i, false);
}
}
}
// Bug out if we are limiting by size
if ((maxSize != null) && (filteringResultSet.length() > maxSize.intValue())) {
// Remove the last match to fix the correct size
inclusionMask.set(i, false);
filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(LimitBy.FINAL_SIZE, PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
break;
}
}
filteringResultSet.setNumberFound(returnedObject.getNumberFound());
return filteringResultSet;
}
Aggregations