use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class PredicateTest method testContextualQueryTrailingWildcard.
@Test
public void testContextualQueryTrailingWildcard() throws Exception {
Predicate predicate = getPredicate("test*");
for (String term : Arrays.asList(TRAILING_TERM, EMBEDDED_TERM)) {
for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
String phrase = String.format(term, specialChar);
String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(phrase));
Event testEvent = getEvent(metadata);
assertThat(phrase + " not matched", predicate.matches(testEvent), is(equalTo(true)));
}
}
for (String term : Arrays.asList(LEADING_TERM, EMBEDDED_TERM_REVERSED)) {
for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
String phrase = String.format(term, specialChar);
String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(phrase));
Event testEvent = getEvent(metadata);
assertThat(phrase + " matched", predicate.matches(testEvent), is(equalTo(false)));
}
}
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class SubscriptionFilterVisitor method visit.
/**
* Within filter maps to a CONTAINS Spatial search criteria.
*/
@Override
public Object visit(Within filter, Object data) {
LOGGER.debug("ENTERING: Within filter");
LOGGER.debug("Must have received CONTAINS query criteria: {}", filter.getExpression2());
com.vividsolutions.jts.geom.Geometry jtsGeometry = getJtsGeometery((LiteralExpressionImpl) filter.getExpression2());
Predicate predicate = new GeospatialPredicate(jtsGeometry, SpatialOperator.CONTAINS.name(), 0.0);
LOGGER.debug("EXITING: Within filter");
return predicate;
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class SubscriptionFilterVisitor method visit.
/**
* DWithin filter maps to a Point/Radius distance Spatial search criteria.
*/
@Override
public Object visit(DWithin filter, Object data) {
LOGGER.debug("ENTERING: DWithin filter");
LOGGER.debug("Must have received point/radius query criteria.");
double radius = filter.getDistance();
com.vividsolutions.jts.geom.Geometry jtsGeometry = getJtsGeometery((LiteralExpressionImpl) filter.getExpression2());
double radiusInDegrees = (radius * 180.0) / (Math.PI * EQUATORIAL_RADIUS_IN_METERS);
LOGGER.debug("radius in meters : {}", radius);
LOGGER.debug("radius in degrees : {}", radiusInDegrees);
Predicate predicate = new GeospatialPredicate(jtsGeometry, null, radiusInDegrees);
LOGGER.debug("EXITING: DWithin filter");
return predicate;
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class SubscriptionFilterVisitor method visit.
@Override
public Object visit(Or filter, Object data) {
LOGGER.debug("ENTERING: OR filter");
Predicate returnPredicate = null;
List<Predicate> predList = new ArrayList<Predicate>();
List<Filter> childList = filter.getChildren();
if (childList != null) {
for (Filter child : childList) {
if (child == null) {
continue;
}
predList.add((Predicate) child.accept(this, data));
}
}
for (Predicate p : predList) {
if (returnPredicate == null) {
returnPredicate = p;
} else {
returnPredicate = or(returnPredicate, p);
}
}
LOGGER.debug("EXITING: OR filter");
return returnPredicate;
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class PredicateTest method getPredicate.
private Predicate getPredicate(String searchPhrase, String textPathSections, boolean caseSensitive) {
MockQuery query = new MockQuery();
query.addContextualFilter(searchPhrase, textPathSections, caseSensitive);
SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
return (Predicate) query.getFilter().accept(visitor, null);
}
Aggregations