diff --git a/es/src/main/java/com/scaleset/search/es/DefaultQueryConverter.java b/es/src/main/java/com/scaleset/search/es/DefaultQueryConverter.java index 562f70c..a42721c 100644 --- a/es/src/main/java/com/scaleset/search/es/DefaultQueryConverter.java +++ b/es/src/main/java/com/scaleset/search/es/DefaultQueryConverter.java @@ -243,6 +243,7 @@ protected void registerDefaultFilterConverters() { register("geo_bounding_box", new GeoBoundingBoxFilterConverter()); register("geo_distance", new GeoDistanceFilterConverter()); register("geo_shape", new GeoShapeFilterConverter()); + register("geo_shape_circle", new GeoCircleFilterConverter()); register("geo_polygon", new GeoPolygonFilterConverter()); register("query", new QueryFilterConverter()); register("type", new TypeFilterConverter()); diff --git a/es/src/main/java/com/scaleset/search/es/filter/GeoCircleFilterConverter.java b/es/src/main/java/com/scaleset/search/es/filter/GeoCircleFilterConverter.java new file mode 100644 index 0000000..73fc4a4 --- /dev/null +++ b/es/src/main/java/com/scaleset/search/es/filter/GeoCircleFilterConverter.java @@ -0,0 +1,34 @@ +package com.scaleset.search.es.filter; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.scaleset.geo.geojson.GeoJsonModule; +import com.scaleset.search.Filter; +import com.scaleset.utils.Coerce; +import com.spatial4j.core.context.jts.JtsSpatialContext; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.GeometryFactory; +import org.elasticsearch.common.geo.ShapeRelation; +import org.elasticsearch.common.geo.builders.ShapeBuilder; +import org.elasticsearch.index.query.FilterBuilder; +import org.elasticsearch.index.query.FilterBuilders; + +public class GeoCircleFilterConverter implements FilterConverter { + + private Coerce coerce = new Coerce(new ObjectMapper().registerModule(new GeoJsonModule())); + + public static final JtsSpatialContext SPATIAL_CONTEXT = JtsSpatialContext.GEO; + public static final GeometryFactory FACTORY = SPATIAL_CONTEXT.getGeometryFactory(); + protected final boolean multiPolygonMayOverlap = false; + + @Override + public FilterBuilder convert(Filter filter) { + String field = filter.getString("field"); + Coordinate geometry = filter.get(Coordinate.class, "geometry"); + String radius = filter.getString("radius"); + ShapeBuilder shapeBuilder = ShapeBuilder.newCircleBuilder().center(geometry).radius(radius); + FilterBuilder result = FilterBuilders.geoWithinFilter(field, shapeBuilder); + return result; + } + +}