Search in sources :

Example 86 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet 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 87 with ResultSet

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

Example 88 with ResultSet

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

Example 89 with ResultSet

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

the class AuditMethodInterceptorTest method testAuditSearchServiceQuery.

/**
 * Test for <a href="https://issues.alfresco.com/jira/browse/MNT-16748">MNT-16748</a> <br>
 * Use {@link SearchService#query(StoreRef, String, String)} to perform a query.
 */
public void testAuditSearchServiceQuery() throws Exception {
    // Run as admin
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    // Perform a search
    @SuppressWarnings("unused") ResultSet rs = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<ResultSet>() {

        @Override
        public ResultSet execute() throws Throwable {
            return searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, "/app:company_home");
        }
    }, true, false);
    // Check the audit entries
    checkAuditEntries(APPLICATION_NAME_MNT_16748, SearchService.LANGUAGE_XPATH, "/app:company_home", 1);
}
Also used : ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 90 with ResultSet

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

the class PersonServiceImpl method getPeopleFtsList.

private List<NodeRef> getPeopleFtsList(String pattern, PagingRequest pagingRequest) throws Throwable {
    // Think this code is based on org.alfresco.repo.jscript.People.getPeopleImplSearch(String, StringTokenizer, int, int)
    List<NodeRef> people = null;
    SearchParameters params = new SearchParameters();
    params.addQueryTemplate("_PERSON", "|%firstName OR |%lastName OR |%userName");
    params.setDefaultFieldName("_PERSON");
    StringBuilder query = new StringBuilder(256);
    query.append("TYPE:\"").append(ContentModel.TYPE_PERSON).append("\" AND (");
    StringTokenizer t = new StringTokenizer(pattern, " ");
    if (t.countTokens() == 1) {
        // fts-alfresco property search i.e. location:"maidenhead"
        query.append('"').append(pattern).append("*\"");
    } else {
        // multiple terms supplied - look for first and second name etc.
        // assume first term is first name, any more are second i.e.
        // "Fraun van de Wiels"
        // also allow fts-alfresco property search to reduce results
        params.setDefaultOperator(SearchParameters.Operator.AND);
        StringBuilder multiPartNames = new StringBuilder(pattern.length());
        int numOfTokens = t.countTokens();
        int counter = 1;
        String term = null;
        // MNT-8539, in order to support firstname and lastname search
        while (t.hasMoreTokens()) {
            term = t.nextToken();
            // firstName and lastName
            if (term.endsWith("*")) {
                term = term.substring(0, term.lastIndexOf("*"));
            }
            multiPartNames.append("\"");
            multiPartNames.append(term);
            multiPartNames.append("*\"");
            if (numOfTokens > counter) {
                multiPartNames.append(' ');
            }
            counter++;
        }
        // name and "lewis martinez" is the last name.
        if (multiPartNames.length() > 0) {
            query.append("firstName:");
            query.append(multiPartNames);
            query.append(" OR lastName:");
            query.append(multiPartNames);
        }
    }
    query.append(")");
    // define the search parameters
    params.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
    params.addStore(this.storeRef);
    params.setQuery(query.toString());
    if (pagingRequest.getMaxItems() > 0) {
        params.setLimitBy(LimitBy.FINAL_SIZE);
        params.setLimit(pagingRequest.getMaxItems());
    }
    ResultSet results = null;
    try {
        results = searchService.query(params);
        people = results.getNodeRefs();
    } catch (Throwable err) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to execute people search: " + query.toString(), err);
        }
        throw err;
    } finally {
        if (results != null) {
            results.close();
        }
    }
    return people;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) StringTokenizer(java.util.StringTokenizer) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Aggregations

ResultSet (org.alfresco.service.cmr.search.ResultSet)112 NodeRef (org.alfresco.service.cmr.repository.NodeRef)57 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)49 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)22 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)20 Test (org.junit.Test)20 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)17 QName (org.alfresco.service.namespace.QName)16 StoreRef (org.alfresco.service.cmr.repository.StoreRef)14 ResultSetRow (org.alfresco.service.cmr.search.ResultSetRow)14 HashSet (java.util.HashSet)13 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)13 SearchService (org.alfresco.service.cmr.search.SearchService)13 NodeService (org.alfresco.service.cmr.repository.NodeService)12 IOException (java.io.IOException)11 List (java.util.List)11 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)10 PagingLuceneResultSet (org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet)10