org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext Java Examples

The following examples show how to use org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext. 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: CMISQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @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 #2
Source File: DBConjunction.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: LuceneNotEquals.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    setPropertyAndStaticArguments(functionArgs);

    Q query = functionContext.buildLuceneInequality(lqpa, getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY, functionContext
            .getLuceneFunction(getFunctionArgument()));

    if (query == null)
    {
        throw new QueryModelException("No query time mapping for property  " + getPropertyArgument().getPropertyName() + ", it should not be allowed in predicates");
    }

    return query;
}
 
Example #4
Source File: CMISFTSQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #5
Source File: Child.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Serializable getValue(Map<String, Argument> args, FunctionEvaluationContext context)
{
    Argument selectorArgument = args.get(ARG_SELECTOR);
    String selectorName = DefaultTypeConverter.INSTANCE.convert(String.class, selectorArgument.getValue(context));
    Argument parentArgument = args.get(ARG_PARENT);
    NodeRef parent = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, parentArgument.getValue(context));

    NodeRef child = context.getNodeRefs().get(selectorName);

    for (ChildAssociationRef car : context.getNodeService().getParentAssocs(child))
    {
        if (car.getParentRef().equals(parent))
        {
            return Boolean.TRUE;
        }
    }
    return Boolean.FALSE;
}
 
Example #6
Source File: CMISQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @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 #7
Source File: LuceneFunctionalConstraint.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext) throws E
{
    Function function = getFunction();
    if(function != null)
    {
        if(function instanceof LuceneQueryBuilderComponent)
        {
            @SuppressWarnings("unchecked")
            LuceneQueryBuilderComponent<Q, S, E> luceneQueryBuilderComponent = (LuceneQueryBuilderComponent<Q, S, E>)function;
            return luceneQueryBuilderComponent.addComponent(selectors, getFunctionArguments(), luceneContext, functionContext);            
        }
        else
        {
            throw new UnsupportedOperationException();
        }
    }
    return null;
}
 
Example #8
Source File: LuceneFTSPrefixTerm.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_TERM);
    String term = (String) argument.getValue(functionContext);
    // strip trailing wildcard *
    term = term.substring(0, term.length()-1);

    argument = functionArgs.get(ARG_TOKENISATION_MODE);
    AnalysisMode mode = (AnalysisMode) argument.getValue(functionContext);
    
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getPrefixQuery(functionContext.getLuceneFieldName(prop), term, mode);
    }
    else
    {
        query = lqpa.getPrefixQuery(lqpa.getField(), term, mode);
        
    }
    return query;
}
 
Example #9
Source File: LuceneFTSFuzzyTerm.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_TERM);
    String term = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_MIN_SIMILARITY);
    Float minSimilarity = (Float) argument.getValue(functionContext);

    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getFuzzyQuery(functionContext.getLuceneFieldName(prop), term, minSimilarity);
    }
    else
    {
        query = lqpa.getFuzzyQuery(lqpa.getField(), term, minSimilarity);
        
    }
    return query;
}
 
Example #10
Source File: LuceneExists.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    PropertyArgument propertyArgument = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Argument inverseArgument = functionArgs.get(ARG_NOT);
    Boolean not = DefaultTypeConverter.INSTANCE.convert(Boolean.class, inverseArgument.getValue(functionContext));

    Q query = functionContext.buildLuceneExists(lqpa, propertyArgument.getPropertyName(), not);

    if (query == null)
    {
        throw new QueryModelException("No query time mapping for property  " + propertyArgument.getPropertyName() + ", it should not be allowed in predicates");
    }

    return query;
}
 
Example #11
Source File: LuceneLike.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    PropertyArgument propertyArgument = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Argument inverseArgument = functionArgs.get(ARG_NOT);
    Boolean not = DefaultTypeConverter.INSTANCE.convert(Boolean.class, inverseArgument.getValue(functionContext));
    Argument expressionArgument = functionArgs.get(ARG_EXP);
    Serializable expression = expressionArgument.getValue(functionContext);

    Q query = functionContext.buildLuceneLike(lqpa, propertyArgument.getPropertyName(), expression, not);

    if (query == null)
    {
        throw new QueryModelException("No query time mapping for property  " + propertyArgument.getPropertyName() + ", it should not be allowed in predicates");
    }

    return query;
}
 
Example #12
Source File: LuceneFTSWildTerm.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_TERM);
    String term = (String) argument.getValue(functionContext);

    argument = functionArgs.get(ARG_TOKENISATION_MODE);
    AnalysisMode mode = (AnalysisMode) argument.getValue(functionContext);
    
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getWildcardQuery(functionContext.getLuceneFieldName(prop), term, mode);
    }
    else
    {
        query = lqpa.getWildcardQuery(lqpa.getField(), term, mode);
        
    }
    return query;
}
 
Example #13
Source File: DBDisjunction.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #14
Source File: LuceneFTSTerm.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_TERM);
    String term = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_TOKENISATION_MODE);
    AnalysisMode mode = (AnalysisMode) argument.getValue(functionContext);

    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getFieldQuery(functionContext.getLuceneFieldName(prop), term, mode, LuceneFunction.FIELD);
    }
    else
    {
        query = lqpa.getFieldQuery(lqpa.getField(), term, mode, LuceneFunction.FIELD);
        
    }
    return query;
}
 
Example #15
Source File: LuceneFTSRange.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_FROM_INC);
    Boolean fromInc = (Boolean) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_FROM);
    String from = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_TO);
    String to = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_TO_INC);
    Boolean toInc = (Boolean) argument.getValue(functionContext);
    
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getRangeQuery(functionContext.getLuceneFieldName(prop), from, to, fromInc, toInc, AnalysisMode.DEFAULT, LuceneFunction.FIELD);
    }
    else
    {
        query = lqpa.getRangeQuery(lqpa.getField(), from, to, fromInc, toInc, AnalysisMode.DEFAULT, LuceneFunction.FIELD);
    }
    return query;
}
 
Example #16
Source File: CMISQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @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 #17
Source File: LuceneSelector.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext) throws E
{
	LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
	switch(getJoinType())
	{
	case INNER:
	case NONE:      
       return lqpa.getFieldQuery("CLASS", getType().toString());
	case LEFT:
		return lqpa.getMatchAllNodesQuery();
	case  RIGHT:
    default:
    	throw new IllegalArgumentException();
	}
    
}
 
Example #18
Source File: DBFunctionalConstraint.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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)
{
    Function function = getFunction();
    if(function != null)
    {
        if(function instanceof DBQueryBuilderComponent)
        {
            DBQueryBuilderComponent dbQueryBuilderComponent = (DBQueryBuilderComponent)function;
            dbQueryBuilderComponent.prepare(namespaceService, dictionaryService, qnameDAO, nodeDAO, tenantService, selectors,  getFunctionArguments(), functionContext, supportBooleanFloatAndDouble);
        }
        else
        {
            throw new UnsupportedOperationException();
        }
    }
}
 
Example #19
Source File: Score.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Serializable getValue(Map<String, Argument> args, FunctionEvaluationContext context)
{
    Argument qualifier = args.get(ARG_QUALIFIER);
    if(qualifier != null)
    {
        return context.getScores().get(qualifier.getValue(context));
    }
    else
    {
        return context.getScore();
    }
}
 
Example #20
Source File: PropertyAccessor.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Serializable getValue(Map<String, Argument> args, FunctionEvaluationContext context)
{
    Argument arg = args.get(ARG_PROPERTY);
    if(!(arg instanceof PropertyArgument))
    {
        throw new QueryModelException("Function "+NAME+" requires a property argument");
    }
    return arg.getValue(context);
}
 
Example #21
Source File: LuceneLessThanOrEquals.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    
    setPropertyAndStaticArguments(functionArgs);
   
    Q query = functionContext.buildLuceneLessThanOrEquals(lqpa, getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY, functionContext.getLuceneFunction(getFunctionArgument()));
    if(query == null)
    {
        throw new QueryModelException("No query time mapping for property  "+getPropertyArgument().getPropertyName()+", it should not be allowed in predicates");
    }
    
    return query;
}
 
Example #22
Source File: LuceneFTSProximity.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_FIRST);
    String first = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_LAST);
    String last = (String) argument.getValue(functionContext);

    int slop = 100;
    argument = functionArgs.get(ARG_SLOP);
    if(argument != null)
    {
        String val = (String) argument.getValue(functionContext);
        try
        {
            slop = Integer.parseInt(val);
        }
        catch(NumberFormatException nfe)
        {
            // ignore rubbish
        }
    }
    
    
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getSpanQuery(functionContext.getLuceneFieldName(prop), first, last, slop, true);
    }
    else
    {
        query = lqpa.getSpanQuery(lqpa.getField(), first, last, slop, true);
        
    }
    return query;
}
 
Example #23
Source File: LuceneFTSPhrase.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_PHRASE);
    String term = (String) argument.getValue(functionContext);

    Integer slop = Integer.valueOf(lqpa.getPhraseSlop());
    argument = functionArgs.get(ARG_SLOP);
    if(argument != null)
    { 
       slop = (Integer) argument.getValue(functionContext);
    }
    
    argument = functionArgs.get(ARG_TOKENISATION_MODE);
    AnalysisMode mode = (AnalysisMode) argument.getValue(functionContext);
    
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getFieldQuery(functionContext.getLuceneFieldName(prop), term, mode, slop, LuceneFunction.FIELD);
    }
    else
    {
        query = lqpa.getFieldQuery(lqpa.getField(), term, mode, slop, LuceneFunction.FIELD);
    }
    return query;
}
 
Example #24
Source File: LuceneLessThan.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    setPropertyAndStaticArguments(functionArgs);
   
    Q query = functionContext.buildLuceneLessThan(lqpa, getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY, functionContext.getLuceneFunction(getFunctionArgument()));
    
    if(query == null)
    {
        throw new QueryModelException("No query time mapping for property  "+getPropertyArgument().getPropertyName()+", it is not allowed in predicates");
    }
    
    return query;
}
 
Example #25
Source File: LuceneEquals.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    setPropertyAndStaticArguments(functionArgs);
   
    Q query = functionContext.buildLuceneEquality(lqpa, getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY, functionContext.getLuceneFunction(getFunctionArgument()));
    
    if(query == null)
    {
        throw new QueryModelException("No query time mapping for property  "+getPropertyArgument().getPropertyName()+", it should not be allowed in predicates");
    }
    
    return query;
}
 
Example #26
Source File: CMISFTSQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #27
Source File: CMISFTSQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #28
Source File: CMISQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkPredicateConditionsForLike(Map<String, Argument> functionArguments,
        FunctionEvaluationContext functionEvaluationContext, Map<String, Column> columnMap)
{
    if (options.getQueryMode() == CMISQueryMode.CMS_STRICT)
    {
        PropertyArgument propertyArgument = (PropertyArgument) functionArguments.get(Like.ARG_PROPERTY);

        boolean isMultiValued = functionEvaluationContext.isMultiValued(propertyArgument.getPropertyName());

        if (isMultiValued)
        {
            throw new QueryModelException("Like is not supported for multi-valued properties");
        }

        String cmisPropertyName = propertyArgument.getPropertyName();

        Column column = columnMap.get(cmisPropertyName);
        if (column != null)
        {
            // check for function type
            if (column.getFunction().getName().equals(PropertyAccessor.NAME))
            {
                PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(
                        PropertyAccessor.ARG_PROPERTY);
                cmisPropertyName = arg.getPropertyName();
            } else
            {
                throw new CmisInvalidArgumentException("Complex column reference not supoprted in LIKE "
                        + cmisPropertyName);
            }
        }

        PropertyDefinitionWrapper propDef = cmisDictionaryService.findPropertyByQueryName(cmisPropertyName);
        if (propDef.getPropertyDefinition().getPropertyType() != PropertyType.STRING)
        {
            throw new CmisInvalidArgumentException("LIKE is only supported against String types" + cmisPropertyName);
        }
    }
}
 
Example #29
Source File: LuceneDisjunction.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #30
Source File: Lower.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Serializable getValue(Map<String, Argument> args, FunctionEvaluationContext context)
{
    Argument arg = args.get(ARG_ARG);
    Serializable value = arg.getValue(context);
    String stringValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
    return stringValue.toLowerCase();
}