Search in sources :

Example 6 with Argument

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

Example 7 with Argument

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

the class DBChild method prepare.

/* (non-Javadoc)
     * @see org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryBuilderComponent#prepare(org.alfresco.service.namespace.NamespaceService, org.alfresco.service.cmr.dictionary.DictionaryService, org.alfresco.repo.domain.qname.QNameDAO, org.alfresco.repo.domain.node.NodeDAO)
     */
@Override
public void prepare(NamespaceService namespaceService, DictionaryService dictionaryService, QNameDAO qnameDAO, NodeDAO nodeDAO, TenantService tenantService, Set<String> selectors, Map<String, Argument> functionArgs, FunctionEvaluationContext functionContext, boolean supportBooleanFloatAndDouble) {
    Argument argument = functionArgs.get(ARG_PARENT);
    String id = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_SELECTOR);
    if (argument != null) {
        String selector = (String) argument.getValue(functionContext);
        if (!selectors.contains(selector)) {
            throw new QueryModelException("Unkown selector " + selector);
        }
    } else {
        if (selectors.size() > 1) {
            throw new QueryModelException("Selector must be specified for child constraint (IN_FOLDER) and join");
        }
    }
    ParentSupport parentSupport = new ParentSupport();
    parentSupport.setDbid(DBQuery.getDbid(id, nodeDAO, tenantService));
    parentSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.EQUALS);
    builderSupport = parentSupport;
}
Also used : Argument(org.alfresco.repo.search.impl.querymodel.Argument) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) ParentSupport(org.alfresco.repo.search.impl.querymodel.impl.db.ParentSupport)

Example 8 with Argument

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

the class DBIn method prepare.

/* (non-Javadoc)
     * @see org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryBuilderComponent#prepare(org.alfresco.service.namespace.NamespaceService, org.alfresco.service.cmr.dictionary.DictionaryService, org.alfresco.repo.domain.qname.QNameDAO, org.alfresco.repo.domain.node.NodeDAO, java.util.Set, java.util.Map, org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext)
     */
@Override
public void prepare(NamespaceService namespaceService, DictionaryService dictionaryService, QNameDAO qnameDAO, NodeDAO nodeDAO, TenantService tenantService, Set<String> selectors, Map<String, Argument> functionArgs, FunctionEvaluationContext functionContext, boolean supportBooleanFloatAndDouble) {
    PropertyArgument propertyArgument = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Argument inverseArgument = functionArgs.get(ARG_NOT);
    Boolean not = DefaultTypeConverter.INSTANCE.convert(Boolean.class, inverseArgument.getValue(functionContext));
    ListArgument listArgument = (ListArgument) functionArgs.get(ARG_LIST);
    Collection<Serializable> collection = (Collection<Serializable>) listArgument.getValue(functionContext);
    if (propertyArgument.getPropertyName().equals(PropertyIds.PARENT_ID)) {
        ParentSupport parentSupport = new ParentSupport();
        parentSupport.setDbids(DBQuery.getDbids(DBQuery.toStringValues(collection), nodeDAO, tenantService));
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            parentSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTIN);
        } else {
            parentSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.IN);
        }
        builderSupport = parentSupport;
    } else if (propertyArgument.getPropertyName().equals(PropertyIds.OBJECT_ID)) {
        UUIDSupport uuidSupport = new UUIDSupport();
        uuidSupport.setUuids(DBQuery.getUUIDs(DBQuery.toStringValues(collection)));
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            uuidSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTIN);
        } else {
            uuidSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.IN);
        }
        builderSupport = uuidSupport;
    } else if (propertyArgument.getPropertyName().equals(PropertyIds.OBJECT_TYPE_ID)) {
        TypeSupport typeSupport = new TypeSupport();
        ArrayList<Long> typeIds = new ArrayList<Long>();
        for (String typeName : DBQuery.toStringValues(collection)) {
            String alfTypeName = functionContext.getAlfrescoTypeName(typeName);
            typeIds.addAll(DBQuery.findTypeIds(alfTypeName, namespaceService, dictionaryService, qnameDAO, true));
        }
        typeSupport.setQnameIds(typeIds);
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            typeSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTIN);
        } else {
            typeSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.IN);
        }
        builderSupport = typeSupport;
    } else if (propertyArgument.getPropertyName().equals(PropertyIds.BASE_TYPE_ID)) {
        TypeSupport typeSupport = new TypeSupport();
        ArrayList<Long> typeIds = new ArrayList<Long>();
        for (String typeName : DBQuery.toStringValues(collection)) {
            String alfTypeName = functionContext.getAlfrescoTypeName(typeName);
            typeIds.addAll(DBQuery.findTypeIds(alfTypeName, namespaceService, dictionaryService, qnameDAO, false));
        }
        typeSupport.setQnameIds(typeIds);
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            typeSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTIN);
        } else {
            typeSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.IN);
        }
        builderSupport = typeSupport;
    } else if (propertyArgument.getPropertyName().equals(PropertyIds.CONTENT_STREAM_MIME_TYPE)) {
        PropertySupport propertySupport = new PropertySupport();
        propertySupport.setValues(DBQuery.toStringValues(collection));
        QName basePropertyQName = QName.createQName(DBQuery.expandQName(functionContext.getAlfrescoPropertyName(propertyArgument.getPropertyName()), namespaceService));
        propertySupport.setPropertyQName(basePropertyQName);
        propertySupport.setPropertyDataType(DBQuery.getDataTypeDefinition(dictionaryService, basePropertyQName));
        propertySupport.setPair(qnameDAO.getQName(basePropertyQName));
        propertySupport.setJoinCommandType(DBQueryBuilderJoinCommandType.CONTENT_MIMETYPE);
        propertySupport.setFieldName("mimetype_str");
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTIN);
        } else {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.IN);
        }
        builderSupport = propertySupport;
    } else if (propertyArgument.getPropertyName().equals(PropertyIds.CONTENT_STREAM_LENGTH)) {
        PropertySupport propertySupport = new PropertySupport();
        ArrayList<String> lengths = new ArrayList<String>();
        for (String value : DBQuery.toStringValues(collection)) {
            lengths.add(value);
        }
        propertySupport.setValues(DBQuery.toStringValues(lengths));
        QName basePropertyQName = QName.createQName(DBQuery.expandQName(functionContext.getAlfrescoPropertyName(propertyArgument.getPropertyName()), namespaceService));
        propertySupport.setPropertyQName(basePropertyQName);
        propertySupport.setPropertyDataType(DBQuery.getDataTypeDefinition(dictionaryService, basePropertyQName));
        propertySupport.setPair(qnameDAO.getQName(basePropertyQName));
        propertySupport.setJoinCommandType(DBQueryBuilderJoinCommandType.CONTENT_URL);
        propertySupport.setFieldName("content_size");
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTIN);
        } else {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.IN);
        }
        builderSupport = propertySupport;
    } else {
        PropertySupport propertySupport = new PropertySupport();
        propertySupport.setValues(DBQuery.toStringValues(collection));
        QName propertyQName = QName.createQName(DBQuery.expandQName(functionContext.getAlfrescoPropertyName(propertyArgument.getPropertyName()), namespaceService));
        propertySupport.setPropertyQName(propertyQName);
        propertySupport.setPropertyDataType(DBQuery.getDataTypeDefinition(dictionaryService, propertyQName));
        propertySupport.setPair(qnameDAO.getQName(propertyQName));
        propertySupport.setJoinCommandType(DBQuery.getJoinCommandType(propertyQName));
        propertySupport.setFieldName(DBQuery.getFieldName(dictionaryService, propertyQName, supportBooleanFloatAndDouble));
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTIN);
        } else {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.IN);
        }
        builderSupport = propertySupport;
    }
}
Also used : Serializable(java.io.Serializable) ListArgument(org.alfresco.repo.search.impl.querymodel.ListArgument) Argument(org.alfresco.repo.search.impl.querymodel.Argument) PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument) UUIDSupport(org.alfresco.repo.search.impl.querymodel.impl.db.UUIDSupport) TypeSupport(org.alfresco.repo.search.impl.querymodel.impl.db.TypeSupport) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) ParentSupport(org.alfresco.repo.search.impl.querymodel.impl.db.ParentSupport) Collection(java.util.Collection) PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument) PropertySupport(org.alfresco.repo.search.impl.querymodel.impl.db.PropertySupport) ListArgument(org.alfresco.repo.search.impl.querymodel.ListArgument)

Aggregations

Argument (org.alfresco.repo.search.impl.querymodel.Argument)8 PropertyArgument (org.alfresco.repo.search.impl.querymodel.PropertyArgument)6 PropertySupport (org.alfresco.repo.search.impl.querymodel.impl.db.PropertySupport)6 QName (org.alfresco.service.namespace.QName)6 ParentSupport (org.alfresco.repo.search.impl.querymodel.impl.db.ParentSupport)5 QueryModelException (org.alfresco.repo.search.impl.querymodel.QueryModelException)4 TypeSupport (org.alfresco.repo.search.impl.querymodel.impl.db.TypeSupport)4 AnalysisMode (org.alfresco.repo.search.adaptor.lucene.AnalysisMode)3 ArrayList (java.util.ArrayList)2 AspectSupport (org.alfresco.repo.search.impl.querymodel.impl.db.AspectSupport)2 UUIDSupport (org.alfresco.repo.search.impl.querymodel.impl.db.UUIDSupport)2 Serializable (java.io.Serializable)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Column (org.alfresco.repo.search.impl.querymodel.Column)1 Function (org.alfresco.repo.search.impl.querymodel.Function)1 ListArgument (org.alfresco.repo.search.impl.querymodel.ListArgument)1 Order (org.alfresco.repo.search.impl.querymodel.Order)1 Ordering (org.alfresco.repo.search.impl.querymodel.Ordering)1