Java Code Examples for org.alfresco.repo.search.adaptor.lucene.LuceneFunction

The following examples show how to use org.alfresco.repo.search.adaptor.lucene.LuceneFunction. These examples are extracted from open source projects. 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
public String getFieldAndFunction()
{
    if(function != null)
    {
        if(function == LuceneFunction.LOWER)
        {
            return "LOWER( "+alias +"." +fieldName+") ";
        }
        else if(function == LuceneFunction.UPPER)
        {
            return "UPPER( "+alias +"." +fieldName+") ";
        }
        else
        {
            return alias +"." +fieldName;
        }
    }
    else
    {
        return alias +"." +fieldName;
    }
}
 
Example 2
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 3
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 4
@Override
@SuppressWarnings("unchecked")
public <Q, S, E extends Throwable> Q buildLuceneGreaterThan(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    if (value instanceof Comparable)
    {
        Comparable<Serializable> comparable = (Comparable<Serializable>) value;
        if (comparable.compareTo(value) > 0)
        {
            return lqpa.getMatchAllQuery();
        }
        else
        {
            return lqpa.getMatchNoneQuery();
        }
    }
    else
    {
        return lqpa.getMatchNoneQuery();
    }
}
 
Example 5
@Override
@SuppressWarnings("unchecked")
public <Q, S, E extends Throwable> Q buildLuceneGreaterThanOrEquals(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    if (value instanceof Comparable)
    {
        Comparable<Serializable> comparable = (Comparable<Serializable>) value;
        if (comparable.compareTo(value) >= 0)
        {
            return lqpa.getMatchAllQuery();
        }
        else
        {
            return lqpa.getMatchNoneQuery();
        }
    }
    else
    {
        return lqpa.getMatchNoneQuery();
    }
}
 
Example 6
@Override
@SuppressWarnings("unchecked")
public <Q, S, E extends Throwable> Q buildLuceneLessThan(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    if (value instanceof Comparable)
    {
        Comparable<Serializable> comparable = (Comparable<Serializable>) value;
        if (comparable.compareTo(value) < 0)
        {
            return lqpa.getMatchAllQuery();            }
        else
        {
            return lqpa.getMatchNoneQuery();
        }
    }
    else
    {
        return lqpa.getMatchNoneQuery();
    }
}
 
Example 7
@Override
@SuppressWarnings("unchecked")
public <Q, S, E extends Throwable> Q buildLuceneLessThanOrEquals(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    if (value instanceof Comparable)
    {
        Comparable<Serializable> comparable = (Comparable<Serializable>) value;
        if (comparable.compareTo(value) <= 0)
        {
            return lqpa.getMatchAllQuery();
        }
        else
        {
            return lqpa.getMatchNoneQuery();
        }
    }
    else
    {
        return lqpa.getMatchNoneQuery();
    }
}
 
Example 8
@Override
public <Q, S, E extends Throwable> Q buildLuceneIn(LuceneQueryParserAdaptor<Q, S, E> lqpa, Collection<Serializable> values, Boolean not, PredicateMode mode) throws E
{
    LuceneQueryParserExpressionAdaptor<Q, E> expressionAdaptor = lqpa.getExpressionAdaptor();
    for(Serializable value : values)
    {
        expressionAdaptor.addOptional(buildLuceneEquality(lqpa, value, mode, LuceneFunction.FIELD));
    }
    if(not)
    {
        return expressionAdaptor.getNegatedQuery();
    }
    else
    {
        return expressionAdaptor.getQuery();
    }
}
 
Example 9
public LuceneFunction getLuceneFunction(FunctionArgument functionArgument)
{
    if (functionArgument == null)
    {
        return LuceneFunction.FIELD;
    } else
    {
        String functionName = functionArgument.getFunction().getName();
        if (functionName.equals(Upper.NAME))
        {
            return LuceneFunction.UPPER;
        } else if (functionName.equals(Lower.NAME))
        {
            return LuceneFunction.LOWER;
        } else
        {
            throw new QueryModelException("Unsupported function: " + functionName);
        }
    }
}
 
Example 10
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 11
@Override
public <Q, S, E extends Throwable> Q buildLuceneEquality(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    if (EqualsHelper.nullSafeEquals(value, value))
    {
        return lqpa.getMatchAllQuery();
    }
    else
    {
        return lqpa.getMatchNoneQuery();
    }
}
 
Example 12
@Override
public <Q, S, E extends Throwable> Q buildLuceneInequality(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    if (!EqualsHelper.nullSafeEquals(value, value))
    {
        return lqpa.getMatchAllQuery();
    }
    else
    {
        return lqpa.getMatchNoneQuery();
    }
}
 
Example 13
@Override
public <Q, S, E extends Throwable> Q buildLuceneExists(LuceneQueryParserAdaptor<Q, S, E> lqpa, Boolean not) throws E
{
    if (not)
    {
        return lqpa.getFieldQuery("ISNULL", getQNameForExists().toString(), AnalysisMode.DEFAULT, LuceneFunction.FIELD);
    }
    else
    {
        return lqpa.getFieldQuery("ISNOTNULL", getQNameForExists().toString(), AnalysisMode.DEFAULT, LuceneFunction.FIELD);
    }
}
 
Example 14
@Override
public <Q, S, E extends Throwable> Q buildLuceneGreaterThan(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    String field = getLuceneFieldName();
    String stringValue = getValueAsString(value);
    return lqpa.getRangeQuery(field, stringValue, getRangeMax(), false, true, AnalysisMode.IDENTIFIER, luceneFunction);
}
 
Example 15
@Override
public <Q, S, E extends Throwable> Q buildLuceneGreaterThanOrEquals(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    String field = getLuceneFieldName();
    String stringValue = getValueAsString(value);
    return lqpa.getRangeQuery(field, stringValue, getRangeMax(), true, true, AnalysisMode.IDENTIFIER, luceneFunction);
}
 
Example 16
@Override
public <Q, S, E extends Throwable> Q buildLuceneLessThan(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    String field = getLuceneFieldName();
    String stringValue = getValueAsString(value);
    return lqpa.getRangeQuery(field, getRangeMin(), stringValue, true, false, AnalysisMode.IDENTIFIER, luceneFunction);
}
 
Example 17
@Override
public <Q, S, E extends Throwable> Q buildLuceneLessThanOrEquals(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    String field = getLuceneFieldName();
    String stringValue = getValueAsString(value);
    return lqpa.getRangeQuery(field, getRangeMin(), stringValue, true, true, AnalysisMode.IDENTIFIER, luceneFunction);
}
 
Example 18
@Override
public <Q, S, E extends Throwable> Q buildLuceneEquality(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode,
        LuceneFunction luceneFunction) throws E
{
    String field = getLuceneFieldName();
    String stringValue = getValueAsString(lqpa, value);
    return lqpa.getFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
}
 
Example 19
@Override
public <Q, S, E extends Throwable> Q buildLuceneExists(LuceneQueryParserAdaptor<Q, S, E> lqpa, Boolean not) throws E
{
    if (not)
    {
        return lqpa.getFieldQuery("ISROOT", "T", AnalysisMode.IDENTIFIER, LuceneFunction.FIELD);
    } else
    {
        return lqpa.getNegatedQuery(lqpa.getFieldQuery("ISROOT", "T", AnalysisMode.IDENTIFIER, LuceneFunction.FIELD));
    }
}
 
Example 20
@Override
public <Q, S, E extends Throwable> Q buildLuceneEquality(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    String field = getLuceneFieldName();
    String stringValue = getValueAsString(lqpa, value);
    return lqpa.getIdentifierQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
}
 
Example 21
@Override
public <Q, S, E extends Throwable> Q buildLuceneGreaterThanOrEquals(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode,
        LuceneFunction luceneFunction) throws E
{
    throw new CmisInvalidArgumentException("Property " + PropertyIds.OBJECT_ID
            + " can not be used in a 'greater than or equals' comparison");
}
 
Example 22
@Override
public <Q, S, E extends Throwable> Q buildLuceneEquality(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode,
        LuceneFunction luceneFunction) throws E
{
    String field = getLuceneFieldName();
    String stringValue = getValueAsString(value);
    TypeDefinitionWrapper type = cmisDictionaryService.findType(stringValue);
    return lqpa
            .getFieldQuery(field, type.getAlfrescoClass().toString(), AnalysisMode.IDENTIFIER, luceneFunction);
}
 
Example 23
@Override
public <Q, S, E extends Throwable> Q buildLuceneGreaterThanOrEquals(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value, PredicateMode mode,
        LuceneFunction luceneFunction) throws E
{
    throw new CmisInvalidArgumentException("Property " + PropertyIds.OBJECT_TYPE_ID
            + " can not be used in a 'greater than or equals' comparison");
}
 
Example 24
@Override
public Query getIdentifierQuery(String field, String stringValue, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException
{
    String[] split = stringValue.split(";");
    if(split.length == 1)
    {
        return lqp.getFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
    }
    else
    {
        if(split[1].equalsIgnoreCase("PWC"))
        {
            return getMatchNoneQuery();
        }
        
        BooleanQuery.Builder query = new BooleanQuery.Builder();
        BooleanQuery.Builder part1 = new BooleanQuery.Builder();
        part1.add(lqp.getFieldQuery(field, split[0], AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST);
        part1.add(lqp.getFieldQuery("@"+ContentModel.PROP_VERSION_LABEL.toString(), split[1], AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST);
        query.add(part1.build(), Occur.SHOULD);
        
        if(split[1].equals("1.0"))
        {
            BooleanQuery.Builder part2 = new BooleanQuery.Builder();
            part2.add(lqp.getFieldQuery(field, split[0], AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST);
            part2.add(lqp.getFieldQuery(QueryConstants.FIELD_ASPECT, ContentModel.ASPECT_VERSIONABLE.toString(), AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST_NOT);
            query.add(part2.build(), Occur.SHOULD);
        }
        return query.build();
    }
}
 
Example 25
/**
 * @param luceneFunction LuceneFunction
 */
public void setLuceneFunction(LuceneFunction luceneFunction)
{
    this.luceneFunction = luceneFunction;
}
 
Example 26
/**
 * @return the function
 */
public LuceneFunction getFunction()
{
    return function;
}
 
Example 27
/**
 * @param function the function to set
 */
public void setFunction(LuceneFunction function)
{
    this.function = function;
}
 
Example 28
public  <Q, S, E extends Throwable> Q buildLuceneEquality(LuceneQueryParserAdaptor<Q, S, E> lqpa, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    throw new UnsupportedOperationException();
}
 
Example 29
public  <Q, S, E extends Throwable> Q buildLuceneGreaterThan(LuceneQueryParserAdaptor<Q, S, E> lqpa, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    throw new UnsupportedOperationException();
}
 
Example 30
public  <Q, S, E extends Throwable> Q buildLuceneGreaterThanOrEquals(LuceneQueryParserAdaptor<Q, S, E> lqpa, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction)
throws E
{
    throw new UnsupportedOperationException();
}