Java Code Examples for org.geotools.data.Query#setHints()
The following examples show how to use
org.geotools.data.Query#setHints() .
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: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testNativeTermQuery() throws Exception { init("not-active"); Map<String, String> vparams = new HashMap<>(); Map<String,Object> query = ImmutableMap.of("term", ImmutableMap.of("security_ss", "WPA")); vparams.put("q", mapper.writeValueAsString(query)); Hints hints = new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, vparams); Query q = new Query(featureSource.getSchema().getTypeName()); q.setHints(hints); FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo filter = ff.equals(ff.property("speed_is"), ff.literal("300")); q.setFilter(filter); ContentFeatureCollection features = featureSource.getFeatures(q); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.12"); }
Example 2
Source File: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testEncodedNativeTermQuery() throws Exception { init("not-active"); Map<String, String> vparams = new HashMap<>(); Map<String,Object> query = ImmutableMap.of("term", ImmutableMap.of("security_ss", "WPA")); vparams.put("q", URLEncoder.encode(mapper.writeValueAsString(query), "UTF-8")); Hints hints = new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, vparams); Query q = new Query(featureSource.getSchema().getTypeName()); q.setHints(hints); FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo filter = ff.equals(ff.property("speed_is"), ff.literal("300")); q.setFilter(filter); ContentFeatureCollection features = featureSource.getFeatures(q); assertEquals(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.12"); }
Example 3
Source File: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testNativeBooleanQuery() throws Exception { init(); Map<String, String> vparams = new HashMap<>(); Map<String,Object> query = ImmutableMap.of("bool", ImmutableMap.of("must", ImmutableMap.of("term", ImmutableMap.of("security_ss", "WPA")), "must_not", ImmutableMap.of("term", ImmutableMap.of("modem_b", true)))); vparams.put("q", mapper.writeValueAsString(query)); Hints hints = new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, vparams); Query q = new Query(featureSource.getSchema().getTypeName()); q.setHints(hints); FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo filter = ff.equals(ff.property("speed_is"), ff.literal("300")); q.setFilter(filter); ContentFeatureCollection features = featureSource.getFeatures(q); assertEquals(2, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getAttribute("modem_b"), false); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getAttribute("modem_b"), false); }
Example 4
Source File: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testNativeAggregation() throws Exception { init(); Map<String, String> vparams = new HashMap<>(); Map<String,Object> query = ImmutableMap.of("agg", ImmutableMap.of("geohash_grid", ImmutableMap.of("field", "geo", "precision", 3))); vparams.put("a", mapper.writeValueAsString(query)); Hints hints = new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, vparams); Query q = new Query(featureSource.getSchema().getTypeName()); q.setHints(hints); ContentFeatureCollection features = featureSource.getFeatures(q); assertFalse(features.isEmpty()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertNotNull(fsi.next().getAttribute("_aggregation")); }
Example 5
Source File: ElasticFilterTest.java From elasticgeo with GNU General Public License v3.0 | 4 votes |
@Before public void setUp() { ff = CommonFactoryFinder.getFilterFactory2(); SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName("test"); typeBuilder.add("stringAttr", String.class); typeBuilder.add("integerAttr", Integer.class); typeBuilder.add("longAttr", Long.class); typeBuilder.add("booleanAttr", Boolean.class); typeBuilder.add("doubleAttr", Double.class); typeBuilder.add("floatAttr", Float.class); typeBuilder.add("dateAttr", Date.class); AttributeDescriptor geoPointAtt; AttributeTypeBuilder geoPointAttBuilder = new AttributeTypeBuilder(); geoPointAttBuilder.setName("geo_point"); geoPointAttBuilder.setBinding(Point.class); geoPointAtt = geoPointAttBuilder.buildDescriptor("geo_point", geoPointAttBuilder.buildType()); geoPointAtt.getUserData().put(GEOMETRY_TYPE, ElasticGeometryType.GEO_POINT); typeBuilder.add(geoPointAtt); AttributeDescriptor geoShapeAtt; AttributeTypeBuilder geoShapeAttBuilder = new AttributeTypeBuilder(); geoShapeAttBuilder.setName("geom"); geoShapeAttBuilder.setBinding(Geometry.class); geoShapeAtt = geoShapeAttBuilder.buildDescriptor("geom", geoShapeAttBuilder.buildType()); geoShapeAtt.getUserData().put(GEOMETRY_TYPE, ElasticGeometryType.GEO_SHAPE); typeBuilder.add(geoShapeAtt); AttributeDescriptor analyzedAtt; AttributeTypeBuilder analyzedAttBuilder = new AttributeTypeBuilder(); analyzedAttBuilder.setName("analyzed"); analyzedAttBuilder.setBinding(String.class); analyzedAtt = analyzedAttBuilder.buildDescriptor("analyzed", analyzedAttBuilder.buildType()); analyzedAtt.getUserData().put(ANALYZED, true); typeBuilder.add(analyzedAtt); AttributeDescriptor netsedAtt; AttributeTypeBuilder nestedAttBuilder = new AttributeTypeBuilder(); nestedAttBuilder.setName("nested.hej"); nestedAttBuilder.setBinding(String.class); netsedAtt = nestedAttBuilder.buildDescriptor("nested.hej", nestedAttBuilder.buildType()); netsedAtt.getUserData().put(NESTED, true); netsedAtt.getUserData().put(ANALYZED, true); typeBuilder.add(netsedAtt); AttributeDescriptor netsedDateAtt; AttributeTypeBuilder nestedDateAttBuilder = new AttributeTypeBuilder(); nestedDateAttBuilder.setName("nested.datehej"); nestedDateAttBuilder.setBinding(Date.class); netsedDateAtt = nestedDateAttBuilder.buildDescriptor("nested.datehej", nestedDateAttBuilder.buildType()); netsedDateAtt.getUserData().put(NESTED, true); typeBuilder.add(netsedDateAtt); featureType = typeBuilder.buildFeatureType(); setFilterBuilder(); parameters = new HashMap<>(); final Hints hints = new Hints(); hints.put(Hints.VIRTUAL_TABLE_PARAMETERS, parameters); query = new Query(); query.setHints(hints); dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); gf = new GeometryFactory(); }