Search in sources :

Example 1 with Ordering

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

use of org.alfresco.repo.search.impl.querymodel.Ordering in project alfresco-repository by Alfresco.

the class DBQuery method buildPredicateCommands.

/*
     * (non-Javadoc)
     * @see org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryBuilderComponent#buildPredicateCommands()
     */
@Override
public void buildPredicateCommands(List<DBQueryBuilderPredicatePartCommand> predicatePartCommands) {
    boolean requiresAnd = false;
    if (selectorGroup != null) {
        for (String selector : selectorGroup) {
            Selector current = getSource().getSelector(selector);
            if (current instanceof DBQueryBuilderComponent) {
                if (requiresAnd) {
                    DBQueryBuilderPredicatePartCommand and = new DBQueryBuilderPredicatePartCommand();
                    and.setType(DBQueryBuilderPredicatePartCommandType.AND);
                    predicatePartCommands.add(and);
                }
                ((DBQueryBuilderComponent) current).buildPredicateCommands(predicatePartCommands);
                requiresAnd = true;
            } else {
                throw new UnsupportedOperationException();
            }
        }
    }
    if (getConstraint() != null) {
        if (getConstraint() instanceof DBQueryBuilderComponent) {
            if (requiresAnd) {
                DBQueryBuilderPredicatePartCommand and = new DBQueryBuilderPredicatePartCommand();
                and.setType(DBQueryBuilderPredicatePartCommandType.AND);
                predicatePartCommands.add(and);
            }
            ((DBQueryBuilderComponent) getConstraint()).buildPredicateCommands(predicatePartCommands);
        } else {
            throw new UnsupportedOperationException();
        }
    }
    if (getOrderings() != null) {
        for (Ordering ordering : getOrderings()) {
            if (ordering instanceof DBQueryBuilderComponent) {
                ((DBQueryBuilderComponent) ordering).buildPredicateCommands(predicatePartCommands);
            } else {
                throw new UnsupportedOperationException();
            }
        }
    }
}
Also used : Ordering(org.alfresco.repo.search.impl.querymodel.Ordering) Selector(org.alfresco.repo.search.impl.querymodel.Selector)

Example 3 with Ordering

use of org.alfresco.repo.search.impl.querymodel.Ordering in project alfresco-repository by Alfresco.

the class AbstractAlfrescoFtsQueryLanguage method buildOrderings.

public List<Ordering> buildOrderings(QueryModelFactory factory, SearchParameters searchParameters) {
    List<Ordering> orderings = new ArrayList<Ordering>(searchParameters.getSortDefinitions().size());
    for (SortDefinition sd : searchParameters.getSortDefinitions()) {
        if (sd.getSortType() == SortType.FIELD) {
            Function function = factory.getFunction(PropertyAccessor.NAME);
            Argument arg = factory.createPropertyArgument(PropertyAccessor.ARG_PROPERTY, true, true, "", sd.getField());
            Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>();
            functionArguments.put(arg.getName(), arg);
            Column column = factory.createColumn(function, functionArguments, sd.getField());
            Order order = sd.isAscending() ? Order.ASCENDING : Order.DESCENDING;
            Ordering ordering = factory.createOrdering(column, order);
            orderings.add(ordering);
        } else if (sd.getSortType() == SortType.SCORE) {
            Function function = factory.getFunction(Score.NAME);
            Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>();
            Column column = factory.createColumn(function, functionArguments, Score.NAME);
            Order order = sd.isAscending() ? Order.ASCENDING : Order.DESCENDING;
            Ordering ordering = factory.createOrdering(column, order);
            orderings.add(ordering);
        } else {
            throw new UnsupportedOperationException("Unsupported Ordering " + sd.getSortType());
        }
    }
    return orderings;
}
Also used : Order(org.alfresco.repo.search.impl.querymodel.Order) Argument(org.alfresco.repo.search.impl.querymodel.Argument) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Function(org.alfresco.repo.search.impl.querymodel.Function) Column(org.alfresco.repo.search.impl.querymodel.Column) Ordering(org.alfresco.repo.search.impl.querymodel.Ordering) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SortDefinition(org.alfresco.service.cmr.search.SearchParameters.SortDefinition)

Aggregations

Ordering (org.alfresco.repo.search.impl.querymodel.Ordering)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 AlfrescoFunctionEvaluationContext (org.alfresco.repo.search.impl.parsers.AlfrescoFunctionEvaluationContext)1 FTSParser (org.alfresco.repo.search.impl.parsers.FTSParser)1 Argument (org.alfresco.repo.search.impl.querymodel.Argument)1 Column (org.alfresco.repo.search.impl.querymodel.Column)1 Constraint (org.alfresco.repo.search.impl.querymodel.Constraint)1 Function (org.alfresco.repo.search.impl.querymodel.Function)1 Order (org.alfresco.repo.search.impl.querymodel.Order)1 QueryModelFactory (org.alfresco.repo.search.impl.querymodel.QueryModelFactory)1 Selector (org.alfresco.repo.search.impl.querymodel.Selector)1 LuceneQueryBuilder (org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilder)1 LuceneQueryModelFactory (org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory)1 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)1 SortDefinition (org.alfresco.service.cmr.search.SearchParameters.SortDefinition)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1