Search in sources :

Example 1 with LikePattern

use of org.apache.jackrabbit.oak.query.fulltext.LikePattern in project jackrabbit-oak by apache.

the class LikePatternTest method pattern.

private static void pattern(String pattern, String match, String noMatch, String lower, String upper) {
    LikePattern p = new LikePattern(pattern);
    if (match != null) {
        assertTrue(p.matches(match));
    }
    if (noMatch != null) {
        assertFalse(p.matches(noMatch));
    }
    assertEquals(lower, p.getLowerBound());
    assertEquals(upper, p.getUpperBound());
}
Also used : LikePattern(org.apache.jackrabbit.oak.query.fulltext.LikePattern)

Example 2 with LikePattern

use of org.apache.jackrabbit.oak.query.fulltext.LikePattern in project jackrabbit-oak by apache.

the class ComparisonImpl method restrict.

@Override
public void restrict(FilterImpl f) {
    PropertyValue v = operand2.currentValue();
    if (!PropertyValues.canConvert(operand2.getPropertyType(), operand1.getPropertyType())) {
        throw new IllegalArgumentException("Unsupported conversion from property type " + PropertyType.nameFromValue(operand2.getPropertyType()) + " to property type " + PropertyType.nameFromValue(operand1.getPropertyType()));
    }
    if (v != null) {
        if (operator == Operator.LIKE) {
            String pattern;
            pattern = v.getValue(Type.STRING);
            LikePattern p = new LikePattern(pattern);
            String lowerBound = p.getLowerBound();
            if (lowerBound != null) {
                String upperBound = p.getUpperBound();
                if (lowerBound.equals(upperBound)) {
                    // no wildcards: equality comparison
                    // but v may contain escaped wildcards, so we can't use it
                    PropertyValue pv = PropertyValues.newString(lowerBound);
                    operand1.restrict(f, Operator.EQUAL, pv);
                } else if (operand1.supportsRangeConditions()) {
                    if (lowerBound != null) {
                        PropertyValue pv = PropertyValues.newString(lowerBound);
                        operand1.restrict(f, Operator.GREATER_OR_EQUAL, pv);
                    }
                    if (upperBound != null) {
                        PropertyValue pv = PropertyValues.newString(upperBound);
                        operand1.restrict(f, Operator.LESS_OR_EQUAL, pv);
                    }
                } else {
                    // path conditions
                    operand1.restrict(f, operator, v);
                }
            } else {
                // like '%' conditions
                operand1.restrict(f, operator, v);
            }
        } else {
            operand1.restrict(f, operator, v);
        }
    }
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) LikePattern(org.apache.jackrabbit.oak.query.fulltext.LikePattern)

Aggregations

LikePattern (org.apache.jackrabbit.oak.query.fulltext.LikePattern)2 PropertyValue (org.apache.jackrabbit.oak.api.PropertyValue)1