|
I have created a class with fields annotated with @Latitude and @Longitude:
https://github.com/infinispan/infinispan/blob/master/integrationtests/as-lucene-directory/src/test/java/org/infinispan/test/integration/as/wildfly/model/Member.java
This method is used to perform a spatial search:
public List<Member> spatialSearch(double latitude, double longitude, double distanceinKM) {
Query spatialQuery = Search.getFullTextEntityManager(em).getSearchFactory()
.buildQueryBuilder().forEntity( Member.class ).get().spatial()
.within( distanceinKM, Unit.KM )
.ofLatitude( latitude )
.andLongitude( longitude )
.createQuery();
return Search.getFullTextEntityManager(em).createFullTextQuery(spatialQuery, Member.class).getResultList();
}
This method is used to perform a spatial search and also uses a projection to return the distance each member is from the specified longitude and latitude:
public List<Object[]> spatialSearchWithDistance(double latitude, double longitude, double distanceinKM) {
Query spatialQuery = Search.getFullTextEntityManager(em).getSearchFactory()
.buildQueryBuilder().forEntity(Member.class).get().spatial()
.onField("location")
.within(distanceinKM, Unit.KM)
.ofLatitude(latitude)
.andLongitude(longitude)
.createQuery();
FullTextQuery hibQuery = Search.getFullTextEntityManager(em).createFullTextQuery(spatialQuery, Member.class);
hibQuery.setProjection(FullTextQuery.SPATIAL_DISTANCE, FullTextQuery.THIS);
hibQuery.setSpatialParameters(latitude, longitude, "location");
return hibQuery.getResultList();
}
Then created objects that have the latitude and longitude set. When I search using a search radius that should include multiple members, the first method returns both members. However when using the same parameters, the second method only returns one member.
|