Search in sources :

Example 6 with SolrJSONResultSet

use of org.alfresco.repo.search.impl.lucene.SolrJSONResultSet in project alfresco-remote-api by Alfresco.

the class ResultMapperTests method testFacetingGroupResponse.

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

Example 7 with SolrJSONResultSet

use of org.alfresco.repo.search.impl.lucene.SolrJSONResultSet in project alfresco-remote-api by Alfresco.

the class ResultMapper method toCollectionWithPagingInfo.

/**
 * Turns the results into a CollectionWithPagingInfo
 * @param params
 * @param searchQuery
 *@param results  @return CollectionWithPagingInfo<Node>
 */
public CollectionWithPagingInfo<Node> toCollectionWithPagingInfo(Params params, SearchRequestContext searchRequestContext, SearchQuery searchQuery, ResultSet results) {
    SearchContext context = null;
    Integer total = null;
    List<Node> noderesults = new ArrayList<Node>();
    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    Map<NodeRef, List<Pair<String, List<String>>>> hightLighting = results.getHighlighting();
    int notFound = 0;
    boolean isHistory = searchRequestContext.getStores().contains(StoreMapper.HISTORY);
    for (ResultSetRow row : results) {
        Node aNode = getNode(row, params, mapUserInfo, isHistory);
        if (aNode != null) {
            float f = row.getScore();
            List<HighlightEntry> highlightEntries = null;
            List<Pair<String, List<String>>> high = hightLighting.get(row.getNodeRef());
            if (high != null && !high.isEmpty()) {
                highlightEntries = new ArrayList<HighlightEntry>(high.size());
                for (Pair<String, List<String>> highlight : high) {
                    highlightEntries.add(new HighlightEntry(highlight.getFirst(), highlight.getSecond()));
                }
            }
            aNode.setSearch(new SearchEntry(f, highlightEntries));
            noderesults.add(aNode);
        } else {
            logger.debug("Unknown noderef returned from search results " + row.getNodeRef());
            notFound++;
        }
    }
    SolrJSONResultSet solrResultSet = findSolrResultSet(results);
    if (solrResultSet != null) {
        // We used Solr for this query
        context = toSearchContext(solrResultSet, searchRequestContext, searchQuery, notFound);
        total = setTotal(solrResultSet);
    } else {
        // This probably wasn't solr
        if (!results.hasMore()) {
            // If there are no more results then we are confident that the number found is correct
            // otherwise we are not confident enough that its accurate
            total = setTotal(results);
        }
    }
    return CollectionWithPagingInfo.asPaged(params.getPaging(), noderesults, results.hasMore(), total, null, context);
}
Also used : HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) ArrayList(java.util.ArrayList) SearchContext(org.alfresco.rest.api.search.context.SearchContext) UserInfo(org.alfresco.rest.api.model.UserInfo) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) NodeRef(org.alfresco.service.cmr.repository.NodeRef) List(java.util.List) TupleList(org.alfresco.rest.api.search.model.TupleList) ArrayList(java.util.ArrayList) SearchEntry(org.alfresco.rest.api.search.model.SearchEntry) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) Pair(org.alfresco.util.Pair)

Example 8 with SolrJSONResultSet

use of org.alfresco.repo.search.impl.lucene.SolrJSONResultSet in project alfresco-remote-api by Alfresco.

the class ResultMapper method toSearchContext.

/**
 * Uses the results from Solr to set the Search Context
 * @param SolrJSONResultSet
 * @param searchQuery
 * @return SearchContext
 */
public SearchContext toSearchContext(SolrJSONResultSet solrResultSet, SearchRequestContext searchRequestContext, SearchQuery searchQuery, int notFound) {
    SearchContext context = null;
    Map<String, Integer> facetQueries = solrResultSet.getFacetQueries();
    List<GenericFacetResponse> facets = new ArrayList<>();
    List<FacetQueryContext> facetResults = null;
    SpellCheckContext spellCheckContext = null;
    List<FacetFieldContext> ffcs = new ArrayList<FacetFieldContext>();
    if (searchQuery == null) {
        throw new IllegalArgumentException("searchQuery can't be null");
    }
    // Facet queries
    if (facetQueries != null && !facetQueries.isEmpty()) {
        // If group by field populated in query facet return bucketing into facet field.
        List<GenericFacetResponse> facetQueryForFields = getFacetBucketsFromFacetQueries(facetQueries, searchQuery);
        if (hasGroup(searchQuery) || FacetFormat.V2 == searchQuery.getFacetFormat()) {
            facets.addAll(facetQueryForFields);
        } else {
            // Return the old way facet query with no bucketing.
            facetResults = new ArrayList<>(facetQueries.size());
            for (Entry<String, Integer> fq : facetQueries.entrySet()) {
                String filterQuery = null;
                if (searchQuery.getFacetQueries() != null) {
                    Optional<FacetQuery> found = searchQuery.getFacetQueries().stream().filter(facetQuery -> fq.getKey().equals(facetQuery.getLabel())).findFirst();
                    filterQuery = found.isPresent() ? found.get().getQuery() : fq.getKey();
                }
                facetResults.add(new FacetQueryContext(fq.getKey(), filterQuery, fq.getValue()));
            }
        }
    }
    // Field Facets
    Map<String, List<Pair<String, Integer>>> facetFields = solrResultSet.getFieldFacets();
    if (FacetFormat.V2 == searchQuery.getFacetFormat()) {
        facets.addAll(getFacetBucketsForFacetFieldsAsFacets(facetFields, searchQuery));
    } else {
        ffcs.addAll(getFacetBucketsForFacetFields(facetFields, searchQuery));
    }
    Map<String, List<Pair<String, Integer>>> facetInterval = solrResultSet.getFacetIntervals();
    facets.addAll(getGenericFacetsForIntervals(facetInterval, searchQuery));
    Map<String, List<Map<String, String>>> facetRanges = solrResultSet.getFacetRanges();
    facets.addAll(RangeResultMapper.getGenericFacetsForRanges(facetRanges, searchQuery.getFacetRanges()));
    List<GenericFacetResponse> stats = getFieldStats(searchRequestContext, solrResultSet.getStats());
    List<GenericFacetResponse> pimped = getPivots(searchRequestContext, solrResultSet.getPivotFacets(), stats);
    facets.addAll(pimped);
    facets.addAll(stats);
    // Spelling
    SpellCheckResult spell = solrResultSet.getSpellCheckResult();
    if (spell != null && spell.getResultName() != null && !spell.getResults().isEmpty()) {
        spellCheckContext = new SpellCheckContext(spell.getResultName(), spell.getResults());
    }
    // Put it all together
    context = new SearchContext(solrResultSet.getLastIndexedTxId(), facets, facetResults, ffcs, spellCheckContext, searchRequestContext.includeRequest() ? searchQuery : null);
    return isNullContext(context) ? null : context;
}
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) 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) ArrayList(java.util.ArrayList) SearchContext(org.alfresco.rest.api.search.context.SearchContext) SpellCheckResult(org.alfresco.service.cmr.search.SpellCheckResult) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery) List(java.util.List) TupleList(org.alfresco.rest.api.search.model.TupleList) ArrayList(java.util.ArrayList) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext)

Example 9 with SolrJSONResultSet

use of org.alfresco.repo.search.impl.lucene.SolrJSONResultSet in project alfresco-remote-api by Alfresco.

the class ResultMapperTests method testFacetingGroupResponseV1.

@Test
public /**
 * Test facet group with out facet fields
 * @throws Exception
 */
void testFacetingGroupResponseV1() throws Exception {
    String jsonQuery = "{\"query\": {\"query\": \"alfresco\"}, \"facetFormat\":\"V1\"," + "\"facetQueries\": [" + "{\"query\": \"content.size:[o TO 102400]\", \"label\": \"small\"}," + "{\"query\": \"content.size:[102400 TO 1048576]\", \"label\": \"medium\",\"group\":\"foo\"}," + "{\"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(2, searchContext.getFacets().size());
    assertEquals(2, searchContext.getFacets().get(0).getBuckets().size());
    assertEquals("small", searchContext.getFacets().get(0).getBuckets().get(0).getLabel());
    assertEquals("content.size:[o TO 102400]", searchContext.getFacets().get(0).getBuckets().get(0).getFilterQuery());
    assertFalse(searchContext.getFacets().get(0).getBuckets().get(0).getMetrics().isEmpty());
    Metric[] metrics = searchContext.getFacets().get(0).getBuckets().get(0).getMetrics().toArray(new Metric[searchContext.getFacets().get(0).getBuckets().get(0).getMetrics().size()]);
    assertEquals(METRIC_TYPE.count, metrics[0].getType());
    assertEquals("{count=52}", metrics[0].getValue().toString());
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SearchContext(org.alfresco.rest.api.search.context.SearchContext) PercentileMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) ListMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric) Matchers.anyString(org.mockito.Matchers.anyString) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) Test(org.junit.Test)

Example 10 with SolrJSONResultSet

use of org.alfresco.repo.search.impl.lucene.SolrJSONResultSet 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());
}
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) PercentileMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) JSONArray(org.json.JSONArray) SearchContext(org.alfresco.rest.api.search.context.SearchContext) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) ListMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric) 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) PercentileMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) ListMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric) Test(org.junit.Test)

Aggregations

SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)13 ResultSet (org.alfresco.service.cmr.search.ResultSet)12 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)11 SearchContext (org.alfresco.rest.api.search.context.SearchContext)11 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)10 SearchQuery (org.alfresco.rest.api.search.model.SearchQuery)10 Metric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric)9 SimpleMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric)9 Test (org.junit.Test)9 Matchers.anyString (org.mockito.Matchers.anyString)9 ListMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric)8 PercentileMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Serializable (java.io.Serializable)5 Arrays (java.util.Arrays)5 Collections (java.util.Collections)5 Map (java.util.Map)5