Search in sources :

Example 1 with CmisFunctionEvaluationContext

use of org.alfresco.opencmis.search.CmisFunctionEvaluationContext in project SearchServices by Alfresco.

the class AlfrescoSolrDataModel method parseCMISQueryToAlfrescoAbstractQuery.

public org.alfresco.repo.search.impl.querymodel.Query parseCMISQueryToAlfrescoAbstractQuery(CMISQueryMode mode, SearchParameters searchParameters, SolrQueryRequest req, String alternativeDictionary, CmisVersion cmisVersion) {
    // convert search parameters to cmis query options
    // TODO: how to handle store ref
    CMISQueryOptions options = new CMISQueryOptions(searchParameters.getQuery(), StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS);
    options.setDefaultFieldName(searchParameters.getDefaultFieldName());
    // TODO: options.setDefaultFTSConnective()
    // TODO: options.setDefaultFTSFieldConnective()
    options.setIncludeInTransactionData(!searchParameters.excludeDataInTheCurrentTransaction());
    options.setLocales(searchParameters.getLocales());
    options.setMlAnalaysisMode(searchParameters.getMlAnalaysisMode());
    options.setQueryParameterDefinitions(searchParameters.getQueryParameterDefinitions());
    for (String name : searchParameters.getQueryTemplates().keySet()) {
        String template = searchParameters.getQueryTemplates().get(name);
        options.addQueryTemplate(name, template);
    }
    // parse cmis syntax
    CapabilityJoin joinSupport = (mode == CMISQueryMode.CMS_STRICT) ? CapabilityJoin.NONE : CapabilityJoin.INNERANDOUTER;
    CmisFunctionEvaluationContext functionContext = getCMISFunctionEvaluationContext(mode, cmisVersion, alternativeDictionary);
    CMISDictionaryService cmisDictionary = getCMISDictionary(alternativeDictionary, cmisVersion);
    CMISQueryParser parser = new CMISQueryParser(options, cmisDictionary, joinSupport);
    org.alfresco.repo.search.impl.querymodel.Query queryModelQuery = parser.parse(new LuceneQueryModelFactory<Query, Sort, SyntaxError>(), functionContext);
    if (queryModelQuery.getSource() != null) {
        List<Set<String>> selectorGroups = queryModelQuery.getSource().getSelectorGroups(functionContext);
        if (selectorGroups.size() == 0) {
            throw new UnsupportedOperationException("No selectors");
        }
    }
    return queryModelQuery;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CmisFunctionEvaluationContext(org.alfresco.opencmis.search.CmisFunctionEvaluationContext) Query(org.apache.lucene.search.Query) CapabilityJoin(org.apache.chemistry.opencmis.commons.enums.CapabilityJoin) CMISQueryOptions(org.alfresco.opencmis.search.CMISQueryOptions) CMISDictionaryService(org.alfresco.opencmis.dictionary.CMISDictionaryService) SyntaxError(org.apache.solr.search.SyntaxError) Sort(org.apache.lucene.search.Sort) CMISQueryParser(org.alfresco.opencmis.search.CMISQueryParser)

Example 2 with CmisFunctionEvaluationContext

use of org.alfresco.opencmis.search.CmisFunctionEvaluationContext in project SearchServices by Alfresco.

the class AlfrescoSolrDataModel method getCMISQuery.

/**
 * @param mode CMISQueryMode
 * @param searchParametersAndFilter Pair<SearchParameters, Boolean>
 * @param req SolrQueryRequest
 * @param queryModelQuery Query
 * @param cmisVersion CmisVersion
 * @param alternativeDictionary String
 * @return Query
 * @throws ParseException
 */
public Query getCMISQuery(CMISQueryMode mode, Pair<SearchParameters, Boolean> searchParametersAndFilter, SolrQueryRequest req, org.alfresco.repo.search.impl.querymodel.Query queryModelQuery, CmisVersion cmisVersion, String alternativeDictionary) throws ParseException {
    SearchParameters searchParameters = searchParametersAndFilter.getFirst();
    Boolean isFilter = searchParametersAndFilter.getSecond();
    CmisFunctionEvaluationContext functionContext = getCMISFunctionEvaluationContext(mode, cmisVersion, alternativeDictionary);
    Set<String> selectorGroup = queryModelQuery.getSource().getSelectorGroups(functionContext).get(0);
    LuceneQueryBuilderContext<Query, Sort, ParseException> luceneContext = getLuceneQueryBuilderContext(searchParameters, req, alternativeDictionary, FTSQueryParser.RerankPhase.SINGLE_PASS);
    @SuppressWarnings("unchecked") LuceneQueryBuilder<Query, Sort, ParseException> builder = (LuceneQueryBuilder<Query, Sort, ParseException>) queryModelQuery;
    org.apache.lucene.search.Query luceneQuery = builder.buildQuery(selectorGroup, luceneContext, functionContext);
    ContextAwareQuery contextAwareQuery = new ContextAwareQuery(luceneQuery, Boolean.TRUE.equals(isFilter) ? null : searchParameters);
    return contextAwareQuery;
}
Also used : Query(org.apache.lucene.search.Query) CmisFunctionEvaluationContext(org.alfresco.opencmis.search.CmisFunctionEvaluationContext) Query(org.apache.lucene.search.Query) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) LuceneQueryBuilder(org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilder) Sort(org.apache.lucene.search.Sort) ParseException(org.apache.lucene.queryparser.classic.ParseException)

Example 3 with CmisFunctionEvaluationContext

use of org.alfresco.opencmis.search.CmisFunctionEvaluationContext in project SearchServices by Alfresco.

the class AlfrescoSolrDataModel method getCMISFunctionEvaluationContext.

public CmisFunctionEvaluationContext getCMISFunctionEvaluationContext(CMISQueryMode mode, CmisVersion cmisVersion, String alternativeDictionary) {
    BaseTypeId[] validScopes = (mode == CMISQueryMode.CMS_STRICT) ? CmisFunctionEvaluationContext.STRICT_SCOPES : CmisFunctionEvaluationContext.ALFRESCO_SCOPES;
    CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();
    functionContext.setCmisDictionaryService(getCMISDictionary(alternativeDictionary, cmisVersion));
    functionContext.setValidScopes(validScopes);
    return functionContext;
}
Also used : CmisFunctionEvaluationContext(org.alfresco.opencmis.search.CmisFunctionEvaluationContext) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId)

Example 4 with CmisFunctionEvaluationContext

use of org.alfresco.opencmis.search.CmisFunctionEvaluationContext 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 5 with CmisFunctionEvaluationContext

use of org.alfresco.opencmis.search.CmisFunctionEvaluationContext in project alfresco-repository by Alfresco.

the class DbCmisQueryLanguage method executeQueryImpl.

private ResultSet executeQueryImpl(SearchParameters searchParameters) {
    CMISQueryOptions options = CMISQueryOptions.create(searchParameters);
    options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS);
    CapabilityJoin joinSupport = CapabilityJoin.INNERANDOUTER;
    BaseTypeId[] validScopes = CmisFunctionEvaluationContext.ALFRESCO_SCOPES;
    CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();
    functionContext.setCmisDictionaryService(cmisDictionaryService);
    functionContext.setValidScopes(validScopes);
    CMISQueryParser parser = new CMISQueryParser(options, cmisDictionaryService, joinSupport);
    org.alfresco.repo.search.impl.querymodel.Query queryModelQuery = parser.parse(new DBQueryModelFactory(), functionContext);
    // TODO: Remove as this appears to be dead code
    // // build lucene query
    // Set<String> selectorGroup = null;
    // if (queryModelQuery.getSource() != null)
    // {
    // List<Set<String>> selectorGroups = queryModelQuery.getSource().getSelectorGroups(functionContext);
    // if (selectorGroups.size() == 0)
    // {
    // throw new UnsupportedOperationException("No selectors");
    // }
    // if (selectorGroups.size() > 1)
    // {
    // throw new UnsupportedOperationException("Advanced join is not supported");
    // }
    // selectorGroup = selectorGroups.get(0);
    // }
    // 
    QueryEngineResults results = queryEngine.executeQuery(queryModelQuery, options, functionContext);
    ResultSet resultSet = results.getResults().values().iterator().next();
    return resultSet;
}
Also used : QueryEngineResults(org.alfresco.repo.search.impl.querymodel.QueryEngineResults) CmisFunctionEvaluationContext(org.alfresco.opencmis.search.CmisFunctionEvaluationContext) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) CapabilityJoin(org.apache.chemistry.opencmis.commons.enums.CapabilityJoin) CMISQueryOptions(org.alfresco.opencmis.search.CMISQueryOptions) ResultSet(org.alfresco.service.cmr.search.ResultSet) CMISQueryParser(org.alfresco.opencmis.search.CMISQueryParser) DBQueryModelFactory(org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryModelFactory)

Aggregations

CmisFunctionEvaluationContext (org.alfresco.opencmis.search.CmisFunctionEvaluationContext)5 CMISQueryParser (org.alfresco.opencmis.search.CMISQueryParser)3 BaseTypeId (org.apache.chemistry.opencmis.commons.enums.BaseTypeId)3 CapabilityJoin (org.apache.chemistry.opencmis.commons.enums.CapabilityJoin)3 CMISQueryOptions (org.alfresco.opencmis.search.CMISQueryOptions)2 ResultSet (org.alfresco.service.cmr.search.ResultSet)2 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)2 Query (org.apache.lucene.search.Query)2 Sort (org.apache.lucene.search.Sort)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 CMISDictionaryService (org.alfresco.opencmis.dictionary.CMISDictionaryService)1 CMISResultSet (org.alfresco.opencmis.search.CMISResultSet)1 Query (org.alfresco.repo.search.impl.querymodel.Query)1 QueryEngineResults (org.alfresco.repo.search.impl.querymodel.QueryEngineResults)1 DBQueryModelFactory (org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryModelFactory)1 LuceneQueryBuilder (org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilder)1 LuceneQueryModelFactory (org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory)1 LimitBy (org.alfresco.service.cmr.search.LimitBy)1