use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.
the class MapReduceTests method mapReduceShouldUseQueryMapper.
// DATAMONGO-938
@Test
public void mapReduceShouldUseQueryMapper() {
MongoCollection<Document> c = mongoTemplate.getDb().getCollection("jmrWithGeo", Document.class);
c.insertOne(new Document("x", Arrays.asList("a", "b")).append("loc", Arrays.<Double>asList(0D, 0D)));
c.insertOne(new Document("x", Arrays.asList("b", "c")).append("loc", Arrays.<Double>asList(0D, 0D)));
c.insertOne(new Document("x", Arrays.asList("c", "d")).append("loc", Arrays.<Double>asList(0D, 0D)));
Query query = new Query(where("x").ne(new String[] { "a", "b" }).and("loc").within(new Box(new double[] { 0, 0 }, new double[] { 1, 1 })));
MapReduceResults<ValueObject> results = template.mapReduce(query, "jmrWithGeo", mapFunction, reduceFunction, ValueObject.class);
Map<String, Float> m = copyToMap(results);
assertEquals(3, m.size());
assertEquals(1, m.get("b").intValue());
assertEquals(2, m.get("c").intValue());
assertEquals(1, m.get("d").intValue());
}
use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoBoxCorrectly.
// DATAMONGO-858
@Test
public void shouldWriteEntityWithGeoBoxCorrectly() {
ClassWithGeoBox object = new ClassWithGeoBox();
object.box = new Box(new Point(1, 2), new Point(3, 4));
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
assertThat(document, is(notNullValue()));
assertThat(document.get("box"), is(instanceOf(org.bson.Document.class)));
assertThat(document.get("box"), is((Object) new org.bson.Document().append("first", toDocument(object.box.getFirst())).append("second", toDocument(object.box.getSecond()))));
}
use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.
the class MongoConvertersUnitTests method convertsBoxToDocumentAndBackCorrectly.
// DATAMONGO-858
@Test
public void convertsBoxToDocumentAndBackCorrectly() {
Box box = new Box(new Point(1, 2), new Point(3, 4));
Document document = GeoConverters.BoxToDocumentConverter.INSTANCE.convert(box);
Shape shape = GeoConverters.DocumentToBoxConverter.INSTANCE.convert(document);
assertThat(shape, is((org.springframework.data.geo.Shape) box));
}
use of org.springframework.data.geo.Box in project nixmash-blog by mintster.
the class SolrLocationTests method testFindByNearWithBox.
@Test
public void testFindByNearWithBox() {
// locatedinYonkers location: 22.17614, -90.87341
List<Product> found = repo.findByLocationNear(new Box(new Point(22, -91), new Point(23, -90)));
locationAsserts(found);
}
Aggregations