Support for geospatial queries in Mongodb
Bug #727942 reported by
Timo Westkämper
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Querydsl |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Related infos : http://
Changed in querydsl: | |
status: | New → Fix Committed |
To post a comment you must log in.
The support for the near-function has been made available via custom types
The MorphiaAnnotati onProcessor declares a custom-type mapping from Double[] to Point like this :
configuration .addCustomType( Double[ ].class, Point.class);
Now you can use Double arrays in your domain class and they will be mapped to the Point class :
@Entity
public class GeoEntity {
private @Id ObjectId id;
private Double[] location;
// ...
}
The Point class provides the methods needed for "near" usage :
public class Point extends ArrayPath<Double>{
public BooleanExpression near(double latVal, double longVal){ n.create( MongodbOps. NEAR, this, new ConstantImpl< Double[ ]>(new Double[]{latVal, longVal}));
return BooleanOperatio
}
}
Here is a test case which demonstrates the usage :
@Test
public void Near(){
ds.save(new GeoEntity(10.0, 50.0));
ds.save(new GeoEntity(20.0, 50.0));
ds.save(new GeoEntity(30.0, 50.0));
}