use of org.geotools.filter.SortByImpl in project ddf by codice.
the class SolrProviderTest method testSpatialPointRadius.
@Test
public void testSpatialPointRadius() throws Exception {
deleteAllIn(provider);
MetacardImpl metacard1 = new MockMetacard(Library.getFlagstaffRecord());
MetacardImpl metacard2 = new MockMetacard(Library.getTampaRecord());
MetacardImpl metacard3 = new MockMetacard(Library.getShowLowRecord());
// Add in the geometry
metacard1.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
metacard2.setLocation(TAMPA_AIRPORT_POINT_WKT);
metacard3.setLocation(SHOW_LOW_AIRPORT_POINT_WKT);
List<Metacard> list = Arrays.asList((Metacard) metacard1, metacard2, metacard3);
/** CREATE **/
create(list);
Filter filter = filterBuilder.attribute(Metacard.ID).is().like().text("*");
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Failed to find all records.", 3, sourceResponse.getResults().size());
CommonQueryBuilder builder = new CommonQueryBuilder();
// Right on Flagstaff
QueryImpl query = builder.pointRadius(-111.67121887207031, 35.138454437255859, 10.0);
query.setPageSize(1);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals("Failed to find Flagstaff record only.", 1, sourceResponse.getResults().size());
for (Result r : sourceResponse.getResults()) {
assertTrue("Wrong record, Flagstaff keyword was not found.", ALL_RESULTS != r.getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE));
LOGGER.info("Distance to Flagstaff: {}", r.getDistanceInMeters());
// assertTrue(r.getDistanceInMeters() != null);
}
// Right on Flagstaff, finding 2 records with 195 km radius
query = builder.pointRadius(-111.67121887207031, 35.138454437255859, 195000);
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl("foo", SortOrder.ASCENDING));
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals("Failed to find the two records.", 2, sourceResponse.getResults().size());
ArrayList<Result> results = new ArrayList<Result>();
for (Result r : sourceResponse.getResults()) {
results.add(r);
}
// querybuilder
for (int i = 0; i < 2; i++) {
Result result = results.get(i);
LOGGER.info("Distance of [{}]]: {}", i, result.getDistanceInMeters());
if (i == 0) {
assertTrue("Grabbed the wrong record.", ALL_RESULTS != result.getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE));
}
if (i == 1) {
assertTrue("Grabbed the wrong record - should be Show Low.", ALL_RESULTS != result.getMetacard().getMetadata().indexOf("Show Low"));
}
}
// NEGATIVE CASE
query = builder.pointRadius(80.1, 25, 195000);
query.setPageSize(3);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals("Should have not found any records.", 0, sourceResponse.getResults().size());
// FEET
double[] coords = { -111.67121887207031, 35.138454437255859 };
query = new QueryImpl(builder.filterFactory.dwithin(Metacard.ANY_GEO, new PointImpl(new DirectPositionImpl(coords), DefaultGeographicCRS.WGS84), 195000, UomOgcMapping.FOOT.name()));
query.setStartIndex(1);
SortByImpl sortby = new SortByImpl(builder.filterFactory.property(Result.DISTANCE), org.opengis.filter.sort.SortOrder.ASCENDING);
query.setSortBy(sortby);
query.setPageSize(3);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(1, sourceResponse.getResults().size());
}
Aggregations