Java Code Examples for org.opengis.filter.expression.Expression#accept()
The following examples show how to use
org.opengis.filter.expression.Expression#accept() .
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: FilterToElastic.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
/** * Write the FilterBuilder for a Not filter * * @param filter the filter to visit * @param extraData extra data (unused by this method) * */ public Object visit(Not filter, Object extraData) { if(filter.getFilter() instanceof PropertyIsNull) { Expression expr = ((PropertyIsNull) filter.getFilter()).getExpression(); expr.accept(this, extraData); } else { filter.getFilter().accept(this, extraData); } if(filter.getFilter() instanceof PropertyIsNull) { queryBuilder = ImmutableMap.of("exists", ImmutableMap.of("field", field)); } else { queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must_not", queryBuilder)); } return extraData; }
Example 2
Source File: FilterToElasticHelper.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
private void visitGeoShapeBinarySpatialOperator(BinarySpatialOperator filter, Expression e1, Expression e2, boolean swapped, Object extraData) { SpatialRelation shapeRelation; if (filter instanceof Disjoint) { shapeRelation = SpatialRelation.DISJOINT; } else if ((!swapped && filter instanceof Within) || (swapped && filter instanceof Contains)) { shapeRelation = SpatialRelation.WITHIN; } else if (filter instanceof Intersects || filter instanceof BBOX) { shapeRelation = SpatialRelation.INTERSECTS; } else { FilterToElastic.LOGGER.fine(filter.getClass().getSimpleName() + " is unsupported for geo_shape types"); shapeRelation = null; delegate.fullySupported = false; } if (shapeRelation != null) { e1.accept(delegate, extraData); key = (String) delegate.field; e2.accept(delegate, extraData); shapeBuilder = delegate.currentShapeBuilder; } if (shapeRelation != null && shapeBuilder != null) { delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_shape", ImmutableMap.of(key, ImmutableMap.of("shape", shapeBuilder, "relation", shapeRelation))))); } else { delegate.queryBuilder = MATCH_ALL; } }
Example 3
Source File: FilterToElasticHelper.java From elasticgeo with GNU General Public License v3.0 | 4 votes |
private void visitGeoPointBinarySpatialOperator(BinarySpatialOperator filter, Expression e1, Expression e2, boolean swapped, Object extraData) { e1.accept(delegate, extraData); key = (String) delegate.field; e2.accept(delegate, extraData); final Geometry geometry = delegate.currentGeometry; if (geometry instanceof Polygon && ((!swapped && filter instanceof Within) || (swapped && filter instanceof Contains) || filter instanceof Intersects)) { final Polygon polygon = (Polygon) geometry; final List<List<Double>> points = new ArrayList<>(); for (final Coordinate coordinate : polygon.getCoordinates()) { points.add(ImmutableList.of(coordinate.x, coordinate.y)); } delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_polygon", ImmutableMap.of(key, ImmutableMap.of("points", points))))); } else if (filter instanceof BBOX) { final BoundingBox envelope = ((BBOX) filter).getBounds(); final double minY = clipLat(envelope.getMinY()); final double maxY = clipLat(envelope.getMaxY()); final double minX, maxX; if (envelope.getWidth() < 360) { minX = clipLon(envelope.getMinX()); maxX = clipLon(envelope.getMaxX()); } else { minX = -180; maxX = 180; } delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_bounding_box", ImmutableMap.of(key, ImmutableMap.of("top_left", ImmutableList.of(minX, maxY), "bottom_right", ImmutableList.of(maxX, minY)))))); } else { FilterToElastic.LOGGER.fine(filter.getClass().getSimpleName() + " is unsupported for geo_point types"); delegate.fullySupported = false; delegate.queryBuilder = MATCH_ALL; } }
Example 4
Source File: FilterToElastic.java From elasticgeo with GNU General Public License v3.0 | 4 votes |
/** * Writes the FilterBuilder for the PropertyIsBetween Filter. * * @param filter the Filter to be visited. * */ public Object visit(PropertyIsBetween filter, Object extraData) { LOGGER.finest("exporting PropertyIsBetween"); Expression expr = filter.getExpression(); Expression lowerbounds = filter.getLowerBoundary(); Expression upperbounds = filter.getUpperBoundary(); Class<?> context; nested = false; AttributeDescriptor attType = (AttributeDescriptor)expr.evaluate(featureType); if (attType != null) { context = attType.getType().getBinding(); if (attType.getUserData().containsKey(NESTED)) { nested = (Boolean) attType.getUserData().get(NESTED); } if (Date.class.isAssignableFrom(context)) { updateDateFormatter(attType); } } else { //assume it's a string? context = String.class; } expr.accept(this, extraData); key = (String) field; lowerbounds.accept(this, context); lower = field; upperbounds.accept(this, context); Object upper = field; if(nested) { path = extractNestedPath(key); } queryBuilder = ImmutableMap.of("range", ImmutableMap.of(key, ImmutableMap.of("gte", lower, "lte", upper))); if(nested) { queryBuilder = ImmutableMap.of("nested", ImmutableMap.of("path", path, "query", queryBuilder)); } return extraData; }
Example 5
Source File: FilterToElastic.java From elasticgeo with GNU General Public License v3.0 | 4 votes |
/** * Writes the FilterBuilder for the Like Filter. * * @param filter the filter to be visited * */ public Object visit(PropertyIsLike filter, Object extraData) { char esc = filter.getEscape().charAt(0); char multi = filter.getWildCard().charAt(0); char single = filter.getSingleChar().charAt(0); if (filter.isMatchingCase()) { LOGGER.fine("Case sensitive search not supported"); } String literal = filter.getLiteral(); Expression att = filter.getExpression(); AttributeDescriptor attType = (AttributeDescriptor) att.evaluate(featureType); Boolean analyzed = false; nested = false; if (attType != null) { if (attType.getUserData().containsKey(ANALYZED)) { analyzed = (Boolean) attType.getUserData().get(ANALYZED); } if (attType.getUserData().containsKey(NESTED)) { nested = (Boolean) attType.getUserData().get(NESTED); } if (Date.class.isAssignableFrom(attType.getType().getBinding())) { updateDateFormatter(attType); } } att.accept(this, extraData); key = (String) field; String pattern; if (analyzed) { // use query string query post filter for analyzed fields pattern = convertToQueryString(esc, multi, single, literal); } else { // default to regexp filter pattern = convertToRegex(esc, multi, single, literal); } if (nested) { path = extractNestedPath(key); } if (analyzed) { // use query string query for analyzed fields queryBuilder = ImmutableMap.of("query_string", ImmutableMap.of("query", pattern, "default_field", key)); } else { // default to regexp query queryBuilder = ImmutableMap.of("regexp", ImmutableMap.of(key, pattern)); } if (nested) { queryBuilder = ImmutableMap.of("nested", ImmutableMap.of("path", path, "query", queryBuilder)); } return extraData; }
Example 6
Source File: FilterToElastic.java From elasticgeo with GNU General Public License v3.0 | 3 votes |
/** * Writes the FilterBuilder for the Null Filter. * * @param filter the null filter. * */ public Object visit(PropertyIsNull filter, Object extraData) { LOGGER.finest("exporting NullFilter"); Expression expr = filter.getExpression(); expr.accept(this, extraData); queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must_not", ImmutableMap.of("exists", ImmutableMap.of("field", field)))); return extraData; }