Search in sources :

Example 1 with LuceneQueryModelFactory

use of org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory in project SearchServices by Alfresco.

the class AlfrescoSolrDataModel method getFTSQuery.

/**
 * @param searchParametersAndFilter Pair<SearchParameters, Boolean>
 * @param req SolrQueryRequest
 * @return Query
 * @throws ParseException
 */
public Query getFTSQuery(Pair<SearchParameters, Boolean> searchParametersAndFilter, SolrQueryRequest req, FTSQueryParser.RerankPhase rerankPhase) throws ParseException {
    SearchParameters searchParameters = searchParametersAndFilter.getFirst();
    Boolean isFilter = searchParametersAndFilter.getSecond();
    QueryModelFactory factory = new LuceneQueryModelFactory<Query, Sort, SyntaxError>();
    AlfrescoFunctionEvaluationContext functionContext = new AlfrescoSolr4FunctionEvaluationContext(namespaceDAO, getDictionaryService(CMISStrictDictionaryService.DEFAULT), NamespaceService.CONTENT_MODEL_1_0_URI, req.getSchema());
    FTSParser.Mode mode;
    if (searchParameters.getDefaultFTSOperator() == org.alfresco.service.cmr.search.SearchParameters.Operator.AND) {
        mode = FTSParser.Mode.DEFAULT_CONJUNCTION;
    } else {
        mode = FTSParser.Mode.DEFAULT_DISJUNCTION;
    }
    Constraint constraint = FTSQueryParser.buildFTS(searchParameters.getQuery(), factory, functionContext, null, null, mode, searchParameters.getDefaultFTSOperator() == org.alfresco.service.cmr.search.SearchParameters.Operator.OR ? Connective.OR : Connective.AND, searchParameters.getQueryTemplates(), searchParameters.getDefaultFieldName(), rerankPhase);
    org.alfresco.repo.search.impl.querymodel.Query queryModelQuery = factory.createQuery(null, null, constraint, new ArrayList<Ordering>());
    @SuppressWarnings("unchecked") LuceneQueryBuilder<Query, Sort, ParseException> builder = (LuceneQueryBuilder<Query, Sort, ParseException>) queryModelQuery;
    LuceneQueryBuilderContext<Query, Sort, ParseException> luceneContext = getLuceneQueryBuilderContext(searchParameters, req, CMISStrictDictionaryService.DEFAULT, rerankPhase);
    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);
    }
    Query luceneQuery = builder.buildQuery(selectorGroup, luceneContext, functionContext);
    // query needs some search parameters fro correct caching ....
    ContextAwareQuery contextAwareQuery = new ContextAwareQuery(luceneQuery, Boolean.TRUE.equals(isFilter) ? null : searchParameters);
    return contextAwareQuery;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Query(org.apache.lucene.search.Query) Constraint(org.alfresco.repo.search.impl.querymodel.Constraint) FTSParser(org.alfresco.repo.search.impl.parsers.FTSParser) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) LuceneQueryModelFactory(org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory) LuceneQueryBuilder(org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilder) Ordering(org.alfresco.repo.search.impl.querymodel.Ordering) Sort(org.apache.lucene.search.Sort) AlfrescoFunctionEvaluationContext(org.alfresco.repo.search.impl.parsers.AlfrescoFunctionEvaluationContext) ParseException(org.apache.lucene.queryparser.classic.ParseException) LuceneQueryModelFactory(org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory) QueryModelFactory(org.alfresco.repo.search.impl.querymodel.QueryModelFactory)

Example 2 with LuceneQueryModelFactory

use of org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory 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)

Aggregations

LuceneQueryModelFactory (org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory)2 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 CMISQueryParser (org.alfresco.opencmis.search.CMISQueryParser)1 CMISResultSet (org.alfresco.opencmis.search.CMISResultSet)1 CmisFunctionEvaluationContext (org.alfresco.opencmis.search.CmisFunctionEvaluationContext)1 AlfrescoFunctionEvaluationContext (org.alfresco.repo.search.impl.parsers.AlfrescoFunctionEvaluationContext)1 FTSParser (org.alfresco.repo.search.impl.parsers.FTSParser)1 Constraint (org.alfresco.repo.search.impl.querymodel.Constraint)1 Ordering (org.alfresco.repo.search.impl.querymodel.Ordering)1 Query (org.alfresco.repo.search.impl.querymodel.Query)1 QueryModelFactory (org.alfresco.repo.search.impl.querymodel.QueryModelFactory)1 LuceneQueryBuilder (org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilder)1 LimitBy (org.alfresco.service.cmr.search.LimitBy)1 ResultSet (org.alfresco.service.cmr.search.ResultSet)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