org.alfresco.repo.search.impl.querymodel.Constraint Java Examples
The following examples show how to use
org.alfresco.repo.search.impl.querymodel.Constraint.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DBConjunction.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@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) { for (Constraint constraint : getConstraints()) { if (constraint instanceof DBQueryBuilderComponent) { if(constraint.getOccur() == Occur.OPTIONAL) { throw new QueryModelException("Disjunctions are not suported"); } DBQueryBuilderComponent dbQueryBuilderComponent = (DBQueryBuilderComponent) constraint; dbQueryBuilderComponent.prepare(namespaceService, dictionaryService, qnameDAO, nodeDAO, tenantService, selectors, functionArgs, functionContext, supportBooleanFloatAndDouble); } else { throw new UnsupportedOperationException(); } } }
Example #2
Source File: DBConjunction.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void buildJoins(Map<QName, DBQueryBuilderJoinCommand> singleJoins, List<DBQueryBuilderJoinCommand> multiJoins) { for (Constraint constraint : getConstraints()) { if (constraint instanceof DBQueryBuilderComponent) { DBQueryBuilderComponent dbQueryBuilderComponent = (DBQueryBuilderComponent) constraint; dbQueryBuilderComponent.buildJoins(singleJoins, multiJoins); } else { throw new UnsupportedOperationException(); } } }
Example #3
Source File: DBDisjunction.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@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) { //throw new QueryModelException("Disjunctions are not suported"); for (Constraint constraint : getConstraints()) { if (constraint instanceof DBQueryBuilderComponent) { DBQueryBuilderComponent dbQueryBuilderComponent = (DBQueryBuilderComponent) constraint; dbQueryBuilderComponent.prepare(namespaceService, dictionaryService, qnameDAO, nodeDAO, tenantService, selectors, functionArgs, functionContext, supportBooleanFloatAndDouble); } else { throw new UnsupportedOperationException(); } } }
Example #4
Source File: DBDisjunction.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void buildJoins(Map<QName, DBQueryBuilderJoinCommand> singleJoins, List<DBQueryBuilderJoinCommand> multiJoins) { for (Constraint constraint : getConstraints()) { if (constraint instanceof DBQueryBuilderComponent) { DBQueryBuilderComponent dbQueryBuilderComponent = (DBQueryBuilderComponent) constraint; dbQueryBuilderComponent.buildJoins(singleJoins, multiJoins); } else { throw new UnsupportedOperationException(); } } }
Example #5
Source File: CMISQueryParser.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
/** * @param orNode CommonTree * @param factory QueryModelFactory * @param functionEvaluationContext FunctionEvaluationContext * @param selectors Map<String, Selector> * @param columnMap HashMap<String, Column> * @return Constraint */ private Constraint buildDisjunction(CommonTree orNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext, Map<String, Selector> selectors, HashMap<String, Column> columnMap) { List<Constraint> constraints = new ArrayList<Constraint>(orNode.getChildCount()); for (int i = 0; i < orNode.getChildCount(); i++) { CommonTree andNode = (CommonTree) orNode.getChild(i); Constraint constraint = buildConjunction(andNode, factory, functionEvaluationContext, selectors, columnMap); constraints.add(constraint); } if (constraints.size() == 1) { return constraints.get(0); } else { return factory.createDisjunction(constraints); } }
Example #6
Source File: CMISFTSQueryParser.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
static private Constraint buildFTSTest(CommonTree argNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext, Selector selector, Map<String, Column> columnMap, String defaultField) { CommonTree testNode = argNode; switch (testNode.getType()) { case CMIS_FTSParser.DISJUNCTION: case CMIS_FTSParser.CONJUNCTION: return buildFTSConnective(testNode, factory, functionEvaluationContext, selector, columnMap, defaultField); case CMIS_FTSParser.TERM: return buildTerm(testNode, factory, functionEvaluationContext, selector, columnMap); case CMIS_FTSParser.PHRASE: return buildPhrase(testNode, factory, functionEvaluationContext, selector, columnMap); default: throw new FTSQueryException("Unsupported FTS option " + testNode.getText()); } }
Example #7
Source File: CMISQueryParser.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
/** * @param andNode CommonTree * @param factory QueryModelFactory * @param functionEvaluationContext FunctionEvaluationContext * @param selectors Map<String, Selector> * @param columnMap HashMap<String, Column> * @return Constraint */ private Constraint buildConjunction(CommonTree andNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext, Map<String, Selector> selectors, HashMap<String, Column> columnMap) { List<Constraint> constraints = new ArrayList<Constraint>(andNode.getChildCount()); for (int i = 0; i < andNode.getChildCount(); i++) { CommonTree notNode = (CommonTree) andNode.getChild(i); Constraint constraint = buildNegation(notNode, factory, functionEvaluationContext, selectors, columnMap); constraints.add(constraint); } if (constraints.size() == 1 && constraints.get(0).getOccur() != Occur.EXCLUDE) { return constraints.get(0); } else { return factory.createConjunction(constraints); } }
Example #8
Source File: CMISQueryParser.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
/** * @param notNode CommonTree * @param factory QueryModelFactory * @param functionEvaluationContext FunctionEvaluationContext * @param selectors Map<String, Selector> * @param columnMap HashMap<String, Column> * @return Constraint */ private Constraint buildNegation(CommonTree notNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext, Map<String, Selector> selectors, HashMap<String, Column> columnMap) { if (notNode.getType() == CMISParser.NEGATION) { Constraint constraint = buildTest((CommonTree) notNode.getChild(0), factory, functionEvaluationContext, selectors, columnMap); constraint.setOccur(Occur.EXCLUDE); return constraint; } else { return buildTest(notNode, factory, functionEvaluationContext, selectors, columnMap); } }
Example #9
Source File: AbstractAlfrescoFtsQueryLanguage.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public ResultSet executeQuery(SearchParameters searchParameters) { String ftsExpression = searchParameters.getQuery(); QueryModelFactory factory = queryEngine.getQueryModelFactory(); AlfrescoFunctionEvaluationContext context = new AlfrescoFunctionEvaluationContext( namespaceService, dictionaryService, searchParameters.getNamespace()); QueryOptions options = QueryOptions.create(searchParameters); FTSParser.Mode mode; if(options.getDefaultFTSConnective() == Connective.AND) { mode = FTSParser.Mode.DEFAULT_CONJUNCTION; } else { mode = FTSParser.Mode.DEFAULT_DISJUNCTION; } Constraint constraint = FTSQueryParser.buildFTS(ftsExpression, factory, context, null, null, mode, options.getDefaultFTSFieldConnective(), searchParameters.getQueryTemplates(), options.getDefaultFieldName(), FTSQueryParser.RerankPhase.SINGLE_PASS); org.alfresco.repo.search.impl.querymodel.Query query = factory.createQuery(null, null, constraint, buildOrderings(factory, searchParameters)); QueryEngineResults results = queryEngine.executeQuery(query, options, context); ResultSet resultSet = results.getResults().values().iterator().next(); return resultSet; }
Example #10
Source File: LuceneDisjunction.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext) throws E { LuceneQueryParserExpressionAdaptor<Q, E> expressionBuilder = luceneContext.getLuceneQueryParserAdaptor().getExpressionAdaptor(); ArrayList<Pair<Constraint, Q>> queriestoDisjoin = new ArrayList<>(); for (Constraint constraint : getConstraints()) { if (constraint instanceof LuceneQueryBuilderComponent) { @SuppressWarnings("unchecked") LuceneQueryBuilderComponent<Q, S, E> luceneQueryBuilderComponent = (LuceneQueryBuilderComponent<Q, S, E>) constraint; Q constraintQuery = luceneQueryBuilderComponent.addComponent(selectors, functionArgs, luceneContext, functionContext); queriestoDisjoin.add(new Pair<Constraint, Q>(constraint, constraintQuery)); if (constraintQuery != null) { switch (constraint.getOccur()) { case DEFAULT: case MANDATORY: case OPTIONAL: expressionBuilder.addOptional(constraintQuery, constraint.getBoost()); break; case EXCLUDE: LuceneQueryParserExpressionAdaptor<Q, E> subExpressionBuilder = luceneContext.getLuceneQueryParserAdaptor().getExpressionAdaptor(); subExpressionBuilder.addRequired(luceneContext.getLuceneQueryParserAdaptor().getMatchAllNodesQuery()); subExpressionBuilder.addExcluded(constraintQuery); expressionBuilder.addOptional(subExpressionBuilder.getQuery(), constraint.getBoost()); break; } } } else { throw new UnsupportedOperationException(); } } return expressionBuilder.getQuery(); }
Example #11
Source File: BaseJoin.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public BaseJoin(Source left, Source right, JoinType joinType, Constraint joinConstraint) { this.left = left; this.right = right; this.joinType = joinType; this.joinConstraint = joinConstraint; }
Example #12
Source File: BaseQuery.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public BaseQuery(List<Column> columns, Source source, Constraint constraint, List<Ordering> orderings) { this.columns = columns; this.source = source; this.constraint = constraint; this.orderings = orderings; }
Example #13
Source File: FTSQueryParser.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
static private void setBoost(Constraint constraint, CommonTree subNode) { for (int i = 0, l = subNode.getChildCount(); i < l; i++) { CommonTree child = (CommonTree) subNode.getChild(i); if (child.getType() == FTSParser.BOOST) { String boostString = child.getChild(0).getText(); float boost = Float.parseFloat(boostString); constraint.setBoost(boost); return; } } }
Example #14
Source File: CMISQueryParser.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
/** * @param testNode CommonTree * @param factory QueryModelFactory * @param functionEvaluationContext FunctionEvaluationContext * @param selectors Map<String, Selector> * @param columnMap HashMap<String, Column> * @return Constraint */ private Constraint buildTest(CommonTree testNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext, Map<String, Selector> selectors, HashMap<String, Column> columnMap) { if (testNode.getType() == CMISParser.DISJUNCTION) { return buildDisjunction(testNode, factory, functionEvaluationContext, selectors, columnMap); } else { return buildPredicate(testNode, factory, functionEvaluationContext, selectors, columnMap); } }
Example #15
Source File: CMISFTSQueryParser.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unused") static public Constraint buildFTS(String ftsExpression, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext, Selector selector, Map<String, Column> columnMap, String defaultField) { // TODO: Decode sql escape for '' should do in CMIS layer // parse templates to trees ... CMIS_FTSParser parser = null; try { CharStream cs = new ANTLRStringStream(ftsExpression); CMIS_FTSLexer lexer = new CMIS_FTSLexer(cs); CommonTokenStream tokens = new CommonTokenStream(lexer); parser = new CMIS_FTSParser(tokens); CommonTree ftsNode = (CommonTree) parser.cmisFtsQuery().getTree(); return buildFTSConnective(ftsNode, factory, functionEvaluationContext, selector, columnMap, defaultField); } catch (RecognitionException e) { if (parser != null) { String[] tokenNames = parser.getTokenNames(); String hdr = parser.getErrorHeader(e); String msg = parser.getErrorMessage(e, tokenNames); throw new FTSQueryException(hdr + "\n" + msg, e); } return null; } }
Example #16
Source File: DBDisjunction.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void buildPredicateCommands(List<DBQueryBuilderPredicatePartCommand> predicatePartCommands) { DBQueryBuilderPredicatePartCommand open = new DBQueryBuilderPredicatePartCommand(); open.setType(DBQueryBuilderPredicatePartCommandType.OPEN); predicatePartCommands.add(open); boolean requiresOr = false; for (Constraint constraint : getConstraints()) { if (constraint instanceof DBQueryBuilderComponent) { if(requiresOr) { DBQueryBuilderPredicatePartCommand and = new DBQueryBuilderPredicatePartCommand(); and.setType(DBQueryBuilderPredicatePartCommandType.OR); predicatePartCommands.add(and); } else { requiresOr = true; } DBQueryBuilderComponent dbQueryBuilderComponent = (DBQueryBuilderComponent) constraint; dbQueryBuilderComponent.buildPredicateCommands(predicatePartCommands); } else { throw new UnsupportedOperationException(); } } DBQueryBuilderPredicatePartCommand close = new DBQueryBuilderPredicatePartCommand(); close.setType(DBQueryBuilderPredicatePartCommandType.CLOSE); predicatePartCommands.add(close); }
Example #17
Source File: CMISFTSQueryParser.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
static private Constraint buildPhrase(CommonTree testNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext, Selector selector, Map<String, Column> columnMap) { String functionName = FTSPhrase.NAME; Function function = factory.getFunction(functionName); Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>(); LiteralArgument larg = factory.createLiteralArgument(FTSPhrase.ARG_PHRASE, DataTypeDefinition.TEXT, getText(testNode.getChild(0))); functionArguments.put(larg.getName(), larg); larg = factory.createLiteralArgument(FTSPhrase.ARG_TOKENISATION_MODE, DataTypeDefinition.ANY, AnalysisMode.DEFAULT); functionArguments.put(larg.getName(), larg); return factory.createFunctionalConstraint(function, functionArguments); }
Example #18
Source File: CMISFTSQueryParser.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
static private Constraint buildTerm(CommonTree testNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext, Selector selector, Map<String, Column> columnMap) { String functionName = FTSTerm.NAME; Function function = factory.getFunction(functionName); Map<String, Argument> functionArguments = new LinkedHashMap<String, Argument>(); LiteralArgument larg = factory.createLiteralArgument(FTSTerm.ARG_TERM, DataTypeDefinition.TEXT, getText(testNode.getChild(0))); functionArguments.put(larg.getName(), larg); larg = factory.createLiteralArgument(FTSTerm.ARG_TOKENISATION_MODE, DataTypeDefinition.ANY, AnalysisMode.DEFAULT); functionArguments.put(larg.getName(), larg); return factory.createFunctionalConstraint(function, functionArguments); }
Example #19
Source File: BaseDisjunction.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public List<Constraint> getConstraints() { return constraints; }
Example #20
Source File: BaseDisjunction.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public BaseDisjunction(List<Constraint> constraints) { this.constraints = constraints; }
Example #21
Source File: BaseJoin.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public Constraint getJoinCondition() { return joinConstraint; }
Example #22
Source File: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
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<>()); @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 .... return new ContextAwareQuery(luceneQuery, Boolean.TRUE.equals(isFilter) ? null : searchParameters); }
Example #23
Source File: LuceneQueryModelFactory.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public Query createQuery(List<Column> columns, Source source, Constraint constraint, List<Ordering> orderings) { return new LuceneQuery<Q, S, E>(columns, source, constraint, orderings); }
Example #24
Source File: LuceneQueryModelFactory.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public Join createJoin(Source left, Source right, JoinType joinType, Constraint joinCondition) { return new LuceneJoin(left, right, joinType, joinCondition); }
Example #25
Source File: DBQuery.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * @param source Source * @param constraint Constraint */ public DBQuery(List<Column> columns, Source source, Constraint constraint, List<Ordering> orderings) { super(columns, source, constraint, orderings); }
Example #26
Source File: LuceneQueryModelFactory.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public Constraint createFunctionalConstraint(Function function, Map<String, Argument> functionArguments) { return new LuceneFunctionalConstraint<Q, S, E>(function, functionArguments); }
Example #27
Source File: LuceneQueryModelFactory.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public Constraint createDisjunction(List<Constraint> constraints) { return new LuceneDisjunction<Q, S, E>(constraints); }
Example #28
Source File: DBQueryModelFactory.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public Constraint createFunctionalConstraint(Function function, Map<String, Argument> functionArguments) { return new DBFunctionalConstraint(function, functionArguments); }
Example #29
Source File: DBConjunction.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** */ public DBConjunction(List<Constraint> constraints) { super(constraints); }
Example #30
Source File: DBConjunction.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void buildPredicateCommands(List<DBQueryBuilderPredicatePartCommand> predicatePartCommands) { DBQueryBuilderPredicatePartCommand open = new DBQueryBuilderPredicatePartCommand(); open.setType(DBQueryBuilderPredicatePartCommandType.OPEN); predicatePartCommands.add(open); boolean requiresAnd = false; for (Constraint constraint : getConstraints()) { if (constraint instanceof DBQueryBuilderComponent) { if(requiresAnd) { DBQueryBuilderPredicatePartCommand and = new DBQueryBuilderPredicatePartCommand(); and.setType(DBQueryBuilderPredicatePartCommandType.AND); predicatePartCommands.add(and); } else { requiresAnd = true; } if(constraint.getOccur() == Occur.EXCLUDE) { DBQueryBuilderPredicatePartCommand not = new DBQueryBuilderPredicatePartCommand(); not.setType(DBQueryBuilderPredicatePartCommandType.NOT); predicatePartCommands.add(not); } DBQueryBuilderComponent dbQueryBuilderComponent = (DBQueryBuilderComponent) constraint; dbQueryBuilderComponent.buildPredicateCommands(predicatePartCommands); } else { throw new UnsupportedOperationException(); } } DBQueryBuilderPredicatePartCommand close = new DBQueryBuilderPredicatePartCommand(); close.setType(DBQueryBuilderPredicatePartCommandType.CLOSE); predicatePartCommands.add(close); }