Search in sources :

Example 1 with SpellCheckResult

use of org.alfresco.service.cmr.search.SpellCheckResult 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)

Aggregations

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 GenericFacetResponse (org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse)1 FACET_TYPE (org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE)1 Metric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric)1 METRIC_TYPE (org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE)1 RangeResultMapper (org.alfresco.repo.search.impl.solr.facet.facetsresponse.RangeResultMapper)1 SimpleMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric)1