I have a NoSQL system for storing real estate houses.
One piece of information I have in my key-value store for each house is the longitude
and latitude
.
If I wanted to retrieve all houses within a geo-lat/long box, like the SQL below:
SELECT * from houses
WHERE latitude IS BETWEEN xxx AND yyy
AND longitude IS BETWEEN www AND zzz
Question:
How would I do this type of retrieval with NoSQL ... using just a key-va开发者_JAVA技巧lue store system?
Even if I could do this with NoSQL, would it even be efficient or would simply going back to using a tradition database retrieve this type of information faster?
Sql or no sql is not the problem -- the problem is, strictly, what kind of indices do you have on your key. spatial indices, which is what you'd need to satisfy your query efficiently, have nothing to do with Sql, or even more generally with relational databases -- they're totally orthogonal to relational vs non-relational issues. Unfortunately, I don't know of any publicly available spatial-indexing systems for Cassandra or other popular non-relational DBs (indeed, the only GIS-oriented DB engine I know well is PostGIS, which happens to be built as an extension of the powerful open-source PostGres... which is relational;-).
If you don't have a spatial index but only a plain one (e.g., one sorted by Lat, then Long), then you'll have to scan through all records with suitable Lat, to discard those with unsuitable Long -- just as a relational engine would have to do for you under the same circumstances (when you select with a couple of BETWEEN
s and all it has to go on is a plain sorted index of the two fields thus constrained). Nothing to do with relational-ness... everything to do with indexing;-).
MongoDB is the only NoSQL database I know of that supports geospatial indexes. If you're using MongoDB, you should look at the documentation, but basically you'd create a geospatial index with:
db.houses.ensureIndex({house : "2d"})
You'd insert points like:
db.houses.insert({house : {latitude : y, longitude : x}})
and then query for it with:
db.houses.find({house : {$within : {$box : [[xxx, yyy], [www, zzz]]}}})
MongoDB also lets you search within a given radius and just for the nearest matches to a point.
Lucene also has something called Local Lucene. It can be reached over REST HTTP with Local Solr : http://www.gissearch.com/geo_search_intro http://wiki.apache.org/solr/SpatialSearch
精彩评论