use of org.alfresco.rest.api.search.model.SearchQuery 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"));
}
use of org.alfresco.rest.api.search.model.SearchQuery 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"));
}
use of org.alfresco.rest.api.search.model.SearchQuery 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());
}
use of org.alfresco.rest.api.search.model.SearchQuery in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method hasGroupTest.
@Test
public void hasGroupTest() throws IOException {
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 jsonQueryWithGroup = "{\"query\": {\"query\": \"alfresco\"}," + "\"facetQueries\": [" + "{\"query\": \"content.size:[0 TO 102400]\", \"label\": \"small\"}," + "{\"query\": \"content.size:[102400 TO 1048576]\", \"label\": \"medium\",\"group\":\"foo\"}," + "{\"query\": \"content.size:[1048576 TO 16777216]\", \"label\": \"large\"}]" + "}";
SearchQuery searchQuery = helper.extractFromJson(jsonQuery);
assertFalse(ResultMapper.hasGroup(searchQuery));
SearchQuery searchQuery2 = helper.extractFromJson(jsonQueryWithGroup);
assertTrue(ResultMapper.hasGroup(searchQuery2));
assertFalse(ResultMapper.hasGroup(null));
String noFacetQueries = "{\"query\": {\"query\": \"alfresco\"}," + "\"facetQueries\": []" + "}";
SearchQuery searchQuery3 = helper.extractFromJson(noFacetQueries);
assertFalse(ResultMapper.hasGroup(searchQuery3));
}
use of org.alfresco.rest.api.search.model.SearchQuery 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());
}
Aggregations