Reputation: 196
I use App Engine datastore with JDO to store data about all users' posts along with the latitude & longitude of the place where they're posted from.
Provided with the co-ordinates of current user, I want to retrieve nearby posts within x kilometres of the current user.
At first I tried querying for a range of latitude & longitude, but it isn't possible as datastore doesn't support inequality filters on multiple properties.
According to this answer in RDBMS it can be achieved by performing calculation within the query itself.
How do I perform this query in JDO? Is there a better way to store the location data where it can be easily retrieved by calculating the distance?
Upvotes: 0
Views: 122
Reputation: 1327
1 - GAE-Search is a nice solution for high performance geospatial search on large dataset. You can even combine it with full-text search and do ranking together.
Downside is that you will have to duplicate your search index data in GAE-Search.
Best way to use it with datastore is to use the datastore key as the doc-id in GAE-Search index where you have one-to-one mapping with datastore entity (and use the same key in mem-cache that ndb/objectify etc facilitate). Then return the doc-ids from GAE-Search to fetch it from memcache.
2 - CloudSQL is the most convenient way. It will work fine if you need geospatial-search just as a condition and ranking or combination with full-text search is not required. And if the data is not expected to grow so large that you see performance issues.
Upvotes: 1
Reputation: 4692
you're going to hit the datastore with computation, so no it is unfortunately impossible. For the same reason you can't use inequality filters on multiple properties, this will also be impossible. You'd need to generate a range of longitude and latitude, filter one via the datastore, and use your code to "filter" the other.
The other way would be to keep a separate table which has "post 1" "post 2" and "distance between posts", but that would make any new put or update a very long task because you'd need to compute distance for everything other point and then write them.... but doing what you want is impossible in datastore.
maybe using couldSQL could help you doing that? it supports multiple inequality and aggregation
Upvotes: 0