Search in sources :

Example 91 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.

the class SolrClientUtil method extractMapping.

public static SolrStoreMappingWrapper extractMapping(StoreRef store, HashMap<StoreRef, SolrStoreMappingWrapper> mappingLookup, ShardRegistry shardRegistry, boolean useDynamicShardRegistration, BeanFactory beanFactory) {
    if ((shardRegistry != null) && useDynamicShardRegistration) {
        SearchParameters sp = new SearchParameters();
        sp.addStore(store);
        List<ShardInstance> slice = shardRegistry.getIndexSlice(sp);
        if ((slice == null) || (slice.size() == 0)) {
            logger.error("No available shards for solr query of store " + store + " - trying non-dynamic configuration");
            SolrStoreMappingWrapper mappings = mappingLookup.get(store);
            if (mappings == null) {
                throw new LuceneQueryParserException("No solr query support for store " + store);
            }
            return mappings;
        }
        return DynamicSolrStoreMappingWrapperFactory.wrap(slice, beanFactory);
    } else {
        SolrStoreMappingWrapper mappings = mappingLookup.get(store);
        if (mappings == null) {
            throw new LuceneQueryParserException("No solr query support for store " + store);
        }
        return mappings;
    }
}
Also used : BasicSearchParameters(org.alfresco.service.cmr.search.BasicSearchParameters) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) ShardInstance(org.alfresco.repo.index.shard.ShardInstance)

Example 92 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.

the class SolrOpenCMISQueryServiceImpl method query.

@Override
public CMISResultSet query(CMISQueryOptions options) {
    SearchParameters searchParameters = options.getAsSearchParmeters();
    searchParameters.addExtraParameter("cmisVersion", options.getCmisVersion().toString());
    ResultSet rs = solrQueryLanguage.executeQuery(searchParameters);
    CapabilityJoin joinSupport = getJoinSupport();
    if (options.getQueryMode() == CMISQueryOptions.CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS) {
        joinSupport = CapabilityJoin.INNERANDOUTER;
    }
    // TODO: Refactor to avoid duplication of valid scopes here and in CMISQueryParser
    BaseTypeId[] validScopes = (options.getQueryMode() == CMISQueryMode.CMS_STRICT) ? CmisFunctionEvaluationContext.STRICT_SCOPES : CmisFunctionEvaluationContext.ALFRESCO_SCOPES;
    CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();
    functionContext.setCmisDictionaryService(cmisDictionaryService);
    functionContext.setNodeService(nodeService);
    functionContext.setValidScopes(validScopes);
    CMISQueryParser parser = new CMISQueryParser(options, cmisDictionaryService, joinSupport);
    Query query = parser.parse(new LuceneQueryModelFactory(), functionContext);
    Map<String, ResultSet> wrapped = new HashMap<String, ResultSet>();
    for (Set<String> group : query.getSource().getSelectorGroups(functionContext)) {
        for (String selector : group) {
            wrapped.put(selector, rs);
        }
    }
    LimitBy limitBy = null;
    limitBy = rs.getResultSetMetaData().getLimitedBy();
    CMISResultSet cmis = new CMISResultSet(wrapped, options, limitBy, nodeService, query, cmisDictionaryService, alfrescoDictionaryService);
    return cmis;
}
Also used : CmisFunctionEvaluationContext(org.alfresco.opencmis.search.CmisFunctionEvaluationContext) CapabilityQuery(org.apache.chemistry.opencmis.commons.enums.CapabilityQuery) Query(org.alfresco.repo.search.impl.querymodel.Query) HashMap(java.util.HashMap) LimitBy(org.alfresco.service.cmr.search.LimitBy) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) CapabilityJoin(org.apache.chemistry.opencmis.commons.enums.CapabilityJoin) CMISResultSet(org.alfresco.opencmis.search.CMISResultSet) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) LuceneQueryModelFactory(org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory) ResultSet(org.alfresco.service.cmr.search.ResultSet) CMISResultSet(org.alfresco.opencmis.search.CMISResultSet) CMISQueryParser(org.alfresco.opencmis.search.CMISQueryParser)

Example 93 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.

the class SolrQueryHTTPClient method buildPivotParameters.

protected void buildPivotParameters(SearchParameters searchParameters, URLCodec encoder, StringBuilder url) throws UnsupportedEncodingException {
    if (searchParameters.getPivots() != null && !searchParameters.getPivots().isEmpty()) {
        url.append("&facet=").append(encoder.encode("true", "UTF-8"));
        for (List<String> pivotKeys : searchParameters.getPivots()) {
            List<String> pivotsList = new ArrayList<>();
            pivotsList.addAll(pivotKeys);
            url.append("&facet.pivot=");
            StringBuilder prefix = new StringBuilder("{! ");
            if (searchParameters.getStats() != null && !searchParameters.getStats().isEmpty()) {
                for (StatsRequestParameters aStat : searchParameters.getStats()) {
                    if (pivotKeys.contains(aStat.getLabel())) {
                        prefix.append("stats=" + aStat.getLabel() + " ");
                        pivotsList.remove(aStat.getLabel());
                        // only do it once
                        break;
                    }
                }
            }
            if (searchParameters.getRanges() != null && !searchParameters.getRanges().isEmpty()) {
                for (RangeParameters aRange : searchParameters.getRanges()) {
                    Optional<String> found = pivotKeys.stream().filter(aKey -> aKey.equals(aRange.getLabel())).findFirst();
                    if (found.isPresent()) {
                        prefix.append("range=" + found.get() + " ");
                        pivotsList.remove(found.get());
                        // only do it once
                        break;
                    }
                }
            }
            if (// We have add something
            prefix.length() > 3) {
                url.append(encoder.encode(prefix.toString().trim(), "UTF-8"));
                url.append(encoder.encode("}", "UTF-8"));
            }
            url.append(encoder.encode(String.join(",", pivotsList), "UTF-8"));
        }
    }
}
Also used : SolrJsonProcessor(org.alfresco.repo.search.impl.lucene.SolrJsonProcessor) RangeParameters(org.alfresco.service.cmr.search.RangeParameters) URIException(org.apache.commons.httpclient.URIException) StringUtils(org.apache.commons.lang3.StringUtils) Header(org.apache.commons.httpclient.Header) DefaultTypeConverter(org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter) JSONResult(org.alfresco.repo.search.impl.lucene.JSONResult) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) PermissionService(org.alfresco.service.cmr.security.PermissionService) RepositoryState(org.alfresco.repo.admin.RepositoryState) NodeDAO(org.alfresco.repo.domain.node.NodeDAO) Locale(java.util.Locale) Map(java.util.Map) NodeService(org.alfresco.service.cmr.repository.NodeService) HttpStatus(org.apache.commons.httpclient.HttpStatus) ResultSet(org.alfresco.service.cmr.search.ResultSet) StatsParameters(org.alfresco.service.cmr.search.StatsParameters) QueryParserUtils(org.alfresco.repo.search.impl.QueryParserUtils) Set(java.util.Set) ShardRegistry(org.alfresco.repo.index.shard.ShardRegistry) Reader(java.io.Reader) CMISStrictDictionaryService(org.alfresco.opencmis.dictionary.CMISStrictDictionaryService) GetMethod(org.apache.commons.httpclient.methods.GetMethod) List(java.util.List) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) I18NUtil(org.springframework.extensions.surf.util.I18NUtil) HttpClient(org.apache.commons.httpclient.HttpClient) Entry(java.util.Map.Entry) Optional(java.util.Optional) LogFactory(org.apache.commons.logging.LogFactory) URI(org.apache.commons.httpclient.URI) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LimitBy(org.alfresco.service.cmr.search.LimitBy) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) Interval(org.alfresco.service.cmr.search.Interval) FieldFacet(org.alfresco.service.cmr.search.SearchParameters.FieldFacet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FieldFacetSort(org.alfresco.service.cmr.search.SearchParameters.FieldFacetSort) NamespaceDAO(org.alfresco.repo.dictionary.NamespaceDAO) ParameterCheck(org.alfresco.util.ParameterCheck) StatsRequestParameters(org.alfresco.service.cmr.search.StatsRequestParameters) HttpException(org.apache.commons.httpclient.HttpException) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) StoreRef(org.alfresco.service.cmr.repository.StoreRef) Iterator(java.util.Iterator) FieldFacetMethod(org.alfresco.service.cmr.search.SearchParameters.FieldFacetMethod) SearchDateConversion.parseDateInterval(org.alfresco.util.SearchDateConversion.parseDateInterval) FieldHighlightParameters(org.alfresco.service.cmr.search.FieldHighlightParameters) HttpServletResponse(javax.servlet.http.HttpServletResponse) JSONTokener(org.json.JSONTokener) Pair(org.alfresco.util.Pair) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) BeansException(org.springframework.beans.BeansException) InputStreamReader(java.io.InputStreamReader) TenantService(org.alfresco.repo.tenant.TenantService) BasicSearchParameters(org.alfresco.service.cmr.search.BasicSearchParameters) PermissionEvaluationMode(org.alfresco.service.cmr.search.PermissionEvaluationMode) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) SortDefinition(org.alfresco.service.cmr.search.SearchParameters.SortDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) SolrStatsResult(org.alfresco.repo.search.impl.lucene.SolrStatsResult) URLCodec(org.apache.commons.codec.net.URLCodec) StringJoiner(java.util.StringJoiner) BeanFactory(org.springframework.beans.factory.BeanFactory) PropertyCheck(org.alfresco.util.PropertyCheck) Log(org.apache.commons.logging.Log) BufferedReader(java.io.BufferedReader) Floc(org.alfresco.repo.index.shard.Floc) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) StatsRequestParameters(org.alfresco.service.cmr.search.StatsRequestParameters) RangeParameters(org.alfresco.service.cmr.search.RangeParameters)

Example 94 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.

the class SolrSearchService method contains.

@Override
public boolean contains(NodeRef nodeRef, QName propertyQName, String googleLikePattern, Operator defaultOperator) throws InvalidNodeRefException {
    ResultSet resultSet = null;
    try {
        // build Lucene search string specific to the node
        StringBuilder sb = new StringBuilder();
        sb.append("+ID:\"").append(nodeRef.toString()).append("\" +(TEXT:(").append(googleLikePattern.toLowerCase()).append(") ");
        if (propertyQName != null) {
            sb.append(" OR @").append(SearchLanguageConversion.escapeLuceneQuery(QName.createQName(propertyQName.getNamespaceURI(), ISO9075.encode(propertyQName.getLocalName())).toString()));
            sb.append(":(").append(googleLikePattern.toLowerCase()).append(")");
        } else {
            for (QName key : nodeService.getProperties(nodeRef).keySet()) {
                sb.append(" OR @").append(SearchLanguageConversion.escapeLuceneQuery(QName.createQName(key.getNamespaceURI(), ISO9075.encode(key.getLocalName())).toString()));
                sb.append(":(").append(googleLikePattern.toLowerCase()).append(")");
            }
        }
        sb.append(")");
        SearchParameters sp = new SearchParameters();
        sp.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp.setQuery(sb.toString());
        sp.setDefaultOperator(defaultOperator);
        sp.addStore(nodeRef.getStoreRef());
        resultSet = this.query(sp);
        boolean answer = resultSet.length() > 0;
        return answer;
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }
    }
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) QName(org.alfresco.service.namespace.QName) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 95 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.

the class DbOrIndexSwitchingQueryLanguage method flattenDBQuery.

private SearchParameters flattenDBQuery(SearchParameters sp) {
    if (sp.getFilterQueries().size() == 0) {
        return sp;
    } else {
        SearchParameters flatten = sp.copy();
        StringBuilder queryBuilder = new StringBuilder();
        queryBuilder.append("( ").append(sp.getQuery()).append(" )");
        for (String filter : sp.getFilterQueries()) {
            Matcher matcher = LuceneQueryLanguageSPI.AFTS_QUERY.matcher(filter);
            if (matcher.find()) {
                queryBuilder.append("AND ( ").append(matcher.group(2)).append(" )");
            } else {
                queryBuilder.append("AND ( ").append(filter).append(" )");
            }
        }
        flatten.setQuery(queryBuilder.toString());
        // the filter can be left and will be ignored by the DB query
        return flatten;
    }
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Matcher(java.util.regex.Matcher)

Aggregations

SearchParameters (org.alfresco.service.cmr.search.SearchParameters)120 ResultSet (org.alfresco.service.cmr.search.ResultSet)51 Test (org.junit.Test)41 NodeRef (org.alfresco.service.cmr.repository.NodeRef)33 ArrayList (java.util.ArrayList)25 StoreRef (org.alfresco.service.cmr.repository.StoreRef)16 IOException (java.io.IOException)15 HashMap (java.util.HashMap)14 QName (org.alfresco.service.namespace.QName)13 List (java.util.List)12 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)12 JSONObject (org.json.JSONObject)12 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 FieldHighlightParameters (org.alfresco.service.cmr.search.FieldHighlightParameters)11 Set (java.util.Set)10 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)10 RangeParameters (org.alfresco.service.cmr.search.RangeParameters)10 JSONArray (org.json.JSONArray)10 JSONTokener (org.json.JSONTokener)10 Locale (java.util.Locale)9