Search in sources :

Example 1 with QueryConsistency

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

the class CMISQueryServiceImpl method executeQueryUsingEngine.

private Pair<Query, QueryEngineResults> executeQueryUsingEngine(QueryEngine queryEngine, CMISQueryOptions options) {
    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);
    QueryConsistency queryConsistency = options.getQueryConsistency();
    if (queryConsistency == QueryConsistency.DEFAULT) {
        options.setQueryConsistency(QueryConsistency.EVENTUAL);
    }
    Query query = parser.parse(queryEngine.getQueryModelFactory(), functionContext);
    QueryEngineResults queryEngineResults = queryEngine.executeQuery(query, options, functionContext);
    return new Pair<Query, QueryEngineResults>(query, queryEngineResults);
}
Also used : QueryEngineResults(org.alfresco.repo.search.impl.querymodel.QueryEngineResults) CapabilityQuery(org.apache.chemistry.opencmis.commons.enums.CapabilityQuery) Query(org.alfresco.repo.search.impl.querymodel.Query) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) CapabilityJoin(org.apache.chemistry.opencmis.commons.enums.CapabilityJoin) QueryConsistency(org.alfresco.service.cmr.search.QueryConsistency) Pair(org.alfresco.util.Pair)

Example 2 with QueryConsistency

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

the class DbOrIndexSwitchingQueryLanguage method executeQuery.

public ResultSet executeQuery(SearchParameters searchParameters) {
    QueryConsistency consistency = searchParameters.getQueryConsistency();
    if (consistency == QueryConsistency.DEFAULT) {
        consistency = queryConsistency;
    }
    switch(consistency) {
        case EVENTUAL:
            if (indexQueryLanguage != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Using SOLR query: " + dbQueryLanguage.getName() + " for " + searchParameters);
                }
                StopWatch stopWatch = new StopWatch("index only");
                stopWatch.start();
                ResultSet results = indexQueryLanguage.executeQuery(searchParameters);
                stopWatch.stop();
                if (logger.isDebugEnabled()) {
                    logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
                }
                return results;
            } else {
                throw new QueryModelException("No query language available");
            }
        case TRANSACTIONAL:
            if (dbQueryLanguage != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Trying db query for " + dbQueryLanguage.getName() + " for " + searchParameters);
                }
                StopWatch stopWatch = new StopWatch("database only");
                stopWatch.start();
                ResultSet results = dbQueryLanguage.executeQuery(flattenDBQuery(searchParameters));
                stopWatch.stop();
                if (logger.isDebugEnabled()) {
                    logger.debug("DB returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
                }
                return results;
            } else {
                throw new QueryModelException("No query language available");
            }
        case HYBRID:
            if (!hybridEnabled) {
                throw new DisabledFeatureException("Hybrid query is disabled.");
            }
            return executeHybridQuery(searchParameters);
        case DEFAULT:
        case TRANSACTIONAL_IF_POSSIBLE:
        default:
            StopWatch stopWatch = new StopWatch("DB if possible");
            // SEARCH-347, exclude TMDQ calls if faceting present.
            if (dbQueryLanguage != null && !searchParameters.hasFaceting()) {
                try {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Trying db query for " + dbQueryLanguage.getName() + " for " + searchParameters);
                    }
                    stopWatch.start();
                    ResultSet results = dbQueryLanguage.executeQuery(flattenDBQuery(searchParameters));
                    stopWatch.stop();
                    if (logger.isDebugEnabled()) {
                        logger.debug("DB returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
                    }
                    return results;
                } catch (QueryModelException qme) {
                    if (stopWatch.isRunning()) {
                        stopWatch.stop();
                    }
                    // MNT-10323: Logging configuration on JBoss leads to clogging of the log with a lot of these errors because of INFO level when WQS module is installed
                    if (logger.isDebugEnabled()) {
                        logger.debug("DB query failed for " + dbQueryLanguage.getName() + " for " + searchParameters, qme);
                    }
                    if (indexQueryLanguage != null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Using SOLR query: " + dbQueryLanguage.getName() + " for " + searchParameters);
                        }
                        stopWatch.start();
                        ResultSet results = indexQueryLanguage.executeQuery(searchParameters);
                        stopWatch.stop();
                        if (logger.isDebugEnabled()) {
                            logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
                        }
                        return results;
                    }
                }
            } else {
                if (indexQueryLanguage != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("(No DB QL) Using SOLR query: " + "dbQueryLanguage==null" + " for " + searchParameters);
                    }
                    stopWatch.start();
                    ResultSet results = indexQueryLanguage.executeQuery(searchParameters);
                    stopWatch.stop();
                    if (logger.isDebugEnabled()) {
                        logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
                    }
                    return results;
                }
            }
            throw new QueryModelException("No query language available");
    }
}
Also used : ResultSet(org.alfresco.service.cmr.search.ResultSet) ChildAssocRefResultSet(org.alfresco.repo.search.results.ChildAssocRefResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) QueryConsistency(org.alfresco.service.cmr.search.QueryConsistency) StopWatch(org.springframework.util.StopWatch)

Aggregations

QueryConsistency (org.alfresco.service.cmr.search.QueryConsistency)2 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)1 Query (org.alfresco.repo.search.impl.querymodel.Query)1 QueryEngineResults (org.alfresco.repo.search.impl.querymodel.QueryEngineResults)1 QueryModelException (org.alfresco.repo.search.impl.querymodel.QueryModelException)1 ChildAssocRefResultSet (org.alfresco.repo.search.results.ChildAssocRefResultSet)1 ResultSet (org.alfresco.service.cmr.search.ResultSet)1 Pair (org.alfresco.util.Pair)1 BaseTypeId (org.apache.chemistry.opencmis.commons.enums.BaseTypeId)1 CapabilityJoin (org.apache.chemistry.opencmis.commons.enums.CapabilityJoin)1 CapabilityQuery (org.apache.chemistry.opencmis.commons.enums.CapabilityQuery)1 StopWatch (org.springframework.util.StopWatch)1