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

The following examples show how to use org.alfresco.repo.search.adaptor.lucene.LuceneFunction. 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: DBQueryBuilderPredicatePartCommand.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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
Source File: BaseLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: CmisFunctionEvaluationContext.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #4
Source File: FixedValueLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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
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 #6
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 #7
Source File: FixedValueLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #8
Source File: FixedValueLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #9
Source File: FixedValueLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #10
Source File: ParentLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #11
Source File: ObjectTypeIdLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #12
Source File: Lucene4QueryParserAdaptor.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #13
Source File: FixedValueLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #14
Source File: FixedValueLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #15
Source File: ObjectTypeIdLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #16
Source File: AbstractSimpleLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #17
Source File: AbstractSimpleLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #18
Source File: AbstractSimpleLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #19
Source File: AbstractSimpleLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #20
Source File: AbstractSimpleLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #21
Source File: ObjectIdLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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
Source File: ObjectIdLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #23
Source File: ParentLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #24
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 #25
Source File: Lucene4QueryParserAdaptor.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Query getFieldQuery(String field, String queryText, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException
{
    return lqp.getFieldQuery(field, queryText, analysisMode, luceneFunction);
}
 
Example #26
Source File: ObjectIdLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public <Q, S, E extends Throwable> Q buildLuceneLessThanOrEquals(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 'less than or equals' comparison");
}
 
Example #27
Source File: ObjectIdLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public <Q, S, E extends Throwable> Q buildLuceneLessThan(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 'less than' comparison");
}
 
Example #28
Source File: CmisFunctionEvaluationContext.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
public <Q, S, E extends Throwable> Q buildLuceneLessThanOrEquals(LuceneQueryParserAdaptor<Q, S, E> lqpa, String propertyName, Serializable value,
        PredicateMode mode, LuceneFunction luceneFunction) throws E
{
    PropertyDefinitionWrapper propertyDef = cmisDictionaryService.findProperty(propertyName);
    return propertyDef.getPropertyLuceneBuilder().buildLuceneLessThanOrEquals(lqpa, value, mode, luceneFunction);
}
 
Example #29
Source File: Lucene4QueryParserAdaptor.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Query getRangeQuery(String field, String lower, String upper, boolean includeLower, boolean includeUpper, AnalysisMode analysisMode, LuceneFunction luceneFunction)
        throws ParseException
{
    return lqp.getRangeQuery(field, lower, upper, includeLower, includeUpper, analysisMode, luceneFunction);
}
 
Example #30
Source File: Lucene4QueryParserAdaptor.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Query getFieldQuery(String luceneFieldName, String term, AnalysisMode analysisMode, Integer slop, LuceneFunction luceneFunction) throws ParseException
{
    return lqp.getFieldQuery(luceneFieldName, term, analysisMode, slop, luceneFunction);
}