Search in sources :

Example 1 with FacetQueryContext

use of org.alfresco.rest.api.search.context.FacetQueryContext 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 2 with FacetQueryContext

use of org.alfresco.rest.api.search.context.FacetQueryContext 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 3 with FacetQueryContext

use of org.alfresco.rest.api.search.context.FacetQueryContext in project alfresco-remote-api by Alfresco.

the class SearchQuerySerializerTests method testSerializeContext.

@Test
public void testSerializeContext() throws IOException {
    ExecutionResult exec1 = new ExecutionResult(new Farmer("180"), null);
    FacetFieldContext ffc = new FacetFieldContext("theLabel", Arrays.asList(new Bucket("b1", "name:b1", 23, "displayText1"), new Bucket("b2", null, 34, "displayText2"), new Bucket("", null, 42, "displayText3")));
    SearchContext searchContext = new SearchContext(23l, null, Arrays.asList(new FacetQueryContext("f1", "creator:bob", 15), new FacetQueryContext("f2", null, 20)), Arrays.asList(ffc), new SpellCheckContext("aFlag", Arrays.asList("bish", "bash")), null);
    CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
    String out = helper.writeResponse(coll);
    assertTrue("There must 'context' json output", out.contains("\"context\":{\"consistency\":{\"lastTxId\":23}"));
    assertTrue("There must 'facetQueries' json output", out.contains("\"facetQueries\":"));
    assertTrue("There must 'facetQueries f1' json output", out.contains("{\"label\":\"f1\",\"filterQuery\":\"creator:bob\",\"count\":15}"));
    assertTrue("There must 'facetQueries f2' json output", out.contains("{\"label\":\"f2\",\"count\":20}"));
    assertTrue("There must 'spellCheck' json output", out.contains("\"spellCheck\":{\"type\":\"aFlag\",\"suggestions\":[\"bish\",\"bash\"]}"));
    assertTrue("There must 'facetsFields' json output", out.contains("\"facetsFields\":[{\"label\":\"theLabel\",\"buckets\""));
    assertTrue("There must 'bucket1' json output", out.contains("{\"label\":\"b1\",\"filterQuery\":\"name:b1\",\"count\":23,\"display\":\"displayText1\"}"));
    assertTrue("There must 'bucket2' json output", out.contains("{\"label\":\"b2\",\"count\":34,\"display\":\"displayText2\"}"));
    assertTrue("There must 'bucket3' json output", out.contains("{\"label\":\"\",\"count\":42,\"display\":\"displayText3\"}"));
    searchContext = new SearchContext(-1, null, null, null, null, null);
    coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
    out = helper.writeResponse(coll);
    assertTrue("There must NOT BE a 'context' json output", out.contains("\"context\":{}"));
    assertFalse("There must NOT BE a 'facetsFields' json output", out.contains("\"facetsFields\":{}"));
}
Also used : FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) FacetQueryContext(org.alfresco.rest.api.search.context.FacetQueryContext) Bucket(org.alfresco.rest.api.search.context.FacetFieldContext.Bucket) SearchContext(org.alfresco.rest.api.search.context.SearchContext) ExecutionResult(org.alfresco.rest.framework.jacksonextensions.ExecutionResult) Farmer(org.alfresco.rest.framework.tests.api.mocks.Farmer) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext) Test(org.junit.Test)

Aggregations

FacetFieldContext (org.alfresco.rest.api.search.context.FacetFieldContext)3 FacetQueryContext (org.alfresco.rest.api.search.context.FacetQueryContext)3 SearchContext (org.alfresco.rest.api.search.context.SearchContext)3 SpellCheckContext (org.alfresco.rest.api.search.context.SpellCheckContext)3 GenericFacetResponse (org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse)2 Bucket (org.alfresco.rest.api.search.context.FacetFieldContext.Bucket)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)1 GenericBucket (org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket)1