Search in sources :

Example 16 with Expression

use of org.opengis.filter.expression.Expression in project ddf by codice.

the class MockQuery method addContextualFilter.

public void addContextualFilter(String searchPhrase, String textPathSections, boolean caseSensitive) {
    Filter filter = null;
    if (searchPhrase != null) {
        if (textPathSections != null) {
            List<Filter> xpathFilters = new ArrayList<Filter>();
            String[] selectors = textPathSections.split(",");
            for (int i = 0; i < selectors.length; i++) {
                Expression xpathRef = new AttributeExpressionImpl(selectors[i]);
                filter = FILTER_FACTORY.like(xpathRef, searchPhrase);
                xpathFilters.add(filter);
            }
            filter = FILTER_FACTORY.or(xpathFilters);
        } else {
            filter = FILTER_FACTORY.like(FILTER_FACTORY.property(Metacard.ANY_TEXT), searchPhrase, SubscriptionFilterVisitor.LUCENE_WILDCARD_CHAR, SubscriptionFilterVisitor.LUCENE_SINGLE_CHAR, SubscriptionFilterVisitor.LUCENE_ESCAPE_CHAR, caseSensitive);
        }
        if (filter != null) {
            filters.add(filter);
        }
    }
}
Also used : SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) Filter(org.opengis.filter.Filter) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) ArrayList(java.util.ArrayList)

Example 17 with Expression

use of org.opengis.filter.expression.Expression in project ddf by codice.

the class SubscriptionFilterVisitor method visit.

/**
     * PropertyIsLike filter maps to a Contextual search criteria.
     */
@Override
public Object visit(PropertyIsLike filter, Object data) {
    LOGGER.debug("ENTERING: PropertyIsLike filter");
    String wildcard = filter.getWildCard();
    String escape = filter.getEscape();
    String single = filter.getSingleChar();
    boolean isFuzzy = false;
    List<String> textPathList = null;
    LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
    Expression expression = likeFilter.getExpression();
    // ContentTypePredicate
    if (expression instanceof PropertyName) {
        PropertyName propertyName = (PropertyName) expression;
        if (Metacard.CONTENT_TYPE.equals(propertyName.getPropertyName())) {
            LOGGER.debug("Expression is ContentType.");
            String typeValue = likeFilter.getLiteral();
            ContentTypePredicate predicate = new ContentTypePredicate(typeValue, null);
            return predicate;
        } else if (Metacard.CONTENT_TYPE_VERSION.equals(propertyName.getPropertyName())) {
            LOGGER.debug("Expression is ContentTypeVersion.");
            String versionValue = likeFilter.getLiteral();
            ContentTypePredicate predicate = new ContentTypePredicate(null, versionValue);
            return predicate;
        }
    }
    if (expression instanceof AttributeExpressionImpl) {
        AttributeExpressionImpl textPathExpression = (AttributeExpressionImpl) expression;
        textPathList = extractXpathSelectors(textPathExpression);
    } else if (expression instanceof FuzzyFunction) {
        FuzzyFunction fuzzyFunction = (FuzzyFunction) expression;
        LOGGER.debug("fuzzy search");
        isFuzzy = true;
        List<Expression> expressions = fuzzyFunction.getParameters();
        AttributeExpressionImpl firstExpression = (AttributeExpressionImpl) expressions.get(0);
        if (!Metacard.ANY_TEXT.equals(firstExpression.getPropertyName())) {
            LOGGER.debug("fuzzy search has a text path section");
            textPathList = extractXpathSelectors(firstExpression);
        }
    }
    String searchPhrase = likeFilter.getLiteral();
    LOGGER.debug("raw searchPhrase = [{}]", searchPhrase);
    String sterilizedSearchPhrase = sterilize(searchPhrase, wildcard, escape, single);
    LOGGER.debug("sterilizedSearchPhrase = [{}]", sterilizedSearchPhrase);
    ContextualPredicate contextPred = new ContextualPredicate(sterilizedSearchPhrase, isFuzzy, likeFilter.isMatchingCase(), textPathList);
    LOGGER.debug("EXITING: PropertyIsLike filter");
    return contextPred;
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) FuzzyFunction(ddf.catalog.impl.filter.FuzzyFunction) LikeFilterImpl(org.geotools.filter.LikeFilterImpl) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) ContextualPredicate(ddf.catalog.pubsub.predicate.ContextualPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with Expression

use of org.opengis.filter.expression.Expression in project ddf by codice.

the class GeoToolsFunctionFactoryTest method testProximityFunction.

@Test
public void testProximityFunction() {
    List<Expression> expr = new ArrayList<>();
    expr.add(Expression.NIL);
    expr.add(Expression.NIL);
    expr.add(Expression.NIL);
    Function result = toTest.function(ProximityFunction.NAME.getName(), expr, null);
    assertThat(result.getName(), is(ProximityFunction.NAME.getName()));
}
Also used : Function(org.opengis.filter.expression.Function) Expression(org.opengis.filter.expression.Expression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 19 with Expression

use of org.opengis.filter.expression.Expression in project ddf by codice.

the class TestCswRecordMapperFilterVisitor method testVisitPropertyIsGreaterThanOrEqualToTemporal.

@Ignore("not supported by solr provider")
@Test
public void testVisitPropertyIsGreaterThanOrEqualToTemporal() {
    Expression val = factory.literal(new Date());
    PropertyIsGreaterThanOrEqualTo filter = factory.greaterOrEqual(created, val);
    Object obj = visitor.visit(filter, null);
    assertThat(obj, instanceOf(Or.class));
    Or duplicate = (Or) obj;
    for (Filter child : duplicate.getChildren()) {
        BinaryTemporalOperator binary = (BinaryTemporalOperator) child;
        assertThat(binary, anyOf(instanceOf(TEquals.class), instanceOf(After.class)));
        assertThat(binary.getExpression1(), is(created));
        assertThat(binary.getExpression2(), is(val));
    }
}
Also used : PropertyIsGreaterThanOrEqualTo(org.opengis.filter.PropertyIsGreaterThanOrEqualTo) BinaryTemporalOperator(org.opengis.filter.temporal.BinaryTemporalOperator) Or(org.opengis.filter.Or) Expression(org.opengis.filter.expression.Expression) Filter(org.opengis.filter.Filter) Date(java.util.Date) Ignore(org.junit.Ignore) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 20 with Expression

use of org.opengis.filter.expression.Expression in project ddf by codice.

the class TestCswRecordMapperFilterVisitor method testVisitPropertyIsLessThan.

@Test
public void testVisitPropertyIsLessThan() {
    Expression val = factory.literal(8);
    PropertyIsLessThan filter = factory.less(attrExpr, val);
    Object obj = visitor.visit(filter, null);
    assertThat(obj, instanceOf(PropertyIsLessThan.class));
    PropertyIsLessThan duplicate = (PropertyIsLessThan) obj;
    assertThat(duplicate.getExpression1(), is(attrExpr));
    assertThat(duplicate.getExpression2(), is(val));
}
Also used : Expression(org.opengis.filter.expression.Expression) PropertyIsLessThan(org.opengis.filter.PropertyIsLessThan) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Aggregations

Expression (org.opengis.filter.expression.Expression)38 Test (org.junit.Test)20 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)17 ArrayList (java.util.ArrayList)9 Date (java.util.Date)8 AttributeType (ddf.catalog.data.AttributeType)7 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)7 Filter (org.opengis.filter.Filter)7 Literal (org.opengis.filter.expression.Literal)5 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)3 FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)3 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)3 DefaultInstant (org.geotools.temporal.object.DefaultInstant)3 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)3 DefaultPosition (org.geotools.temporal.object.DefaultPosition)3 PropertyIsEqualTo (org.opengis.filter.PropertyIsEqualTo)3 PropertyIsLike (org.opengis.filter.PropertyIsLike)3 Function (org.opengis.filter.expression.Function)3