Search in sources :

Example 1 with ContextualPredicate

use of ddf.catalog.pubsub.predicate.ContextualPredicate 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)

Aggregations

FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)1 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)1 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)1 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)1 Expression (org.opengis.filter.expression.Expression)1 PropertyName (org.opengis.filter.expression.PropertyName)1