summaryrefslogtreecommitdiff
path: root/src/mongo/db/geo/geoparser.cpp
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2014-06-17 19:22:05 -0400
committerGreg Studer <greg@10gen.com>2014-07-09 07:36:48 -0400
commit3c5246b1fb2ec2f9c34ba1cb5083b2745d7bdf89 (patch)
tree088174498bb033730c280f8121a2f6bd9d80b40e /src/mongo/db/geo/geoparser.cpp
parenta76bfecf5bb7a173d2c79f4877fe07a6b0bf1f80 (diff)
downloadmongo-3c5246b1fb2ec2f9c34ba1cb5083b2745d7bdf89.tar.gz
SERVER-9986 refactor near search for 2D and S2
Adds progressive search functionality for $geoNear operations, allowing better integration with other cursors.
Diffstat (limited to 'src/mongo/db/geo/geoparser.cpp')
-rw-r--r--src/mongo/db/geo/geoparser.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/mongo/db/geo/geoparser.cpp b/src/mongo/db/geo/geoparser.cpp
index bcc6ca177dc..a0e956d5315 100644
--- a/src/mongo/db/geo/geoparser.cpp
+++ b/src/mongo/db/geo/geoparser.cpp
@@ -77,7 +77,7 @@ namespace mongo {
return isValidLngLat(lng, lat);
}
- static bool isLegacyPoint(const BSONObj &obj) {
+ static bool isLegacyPoint(const BSONObj &obj, bool allowAddlFields) {
BSONObjIterator it(obj);
if (!it.more()) { return false; }
BSONElement x = it.next();
@@ -85,7 +85,7 @@ namespace mongo {
if (!it.more()) { return false; }
BSONElement y = it.next();
if (!y.isNumber()) { return false; }
- if (it.more()) { return false; }
+ if (it.more() && !allowAddlFields) { return false; }
return true;
}
@@ -269,7 +269,7 @@ namespace mongo {
while (coordIt.more()) {
BSONElement coord = coordIt.next();
if (!coord.isABSONObj()) { return false; }
- if (!isLegacyPoint(coord.Obj())) { return false; }
+ if (!isLegacyPoint(coord.Obj(), false)) { return false; }
++vertices;
}
if (vertices < 3) { return false; }
@@ -285,7 +285,7 @@ namespace mongo {
BSONObjIterator objIt(type.embeddedObject());
BSONElement center = objIt.next();
if (!center.isABSONObj()) { return false; }
- if (!isLegacyPoint(center.Obj())) { return false; }
+ if (!isLegacyPoint(center.Obj(), false)) { return false; }
if (!objIt.more()) { return false; }
BSONElement radius = objIt.next();
if (!radius.isNumber()) { return false; }
@@ -301,7 +301,7 @@ namespace mongo {
BSONObjIterator objIt(type.embeddedObject());
BSONElement center = objIt.next();
if (!center.isABSONObj()) { return false; }
- if (!isLegacyPoint(center.Obj())) { return false; }
+ if (!isLegacyPoint(center.Obj(), false)) { return false; }
// Check to make sure the points are valid lng/lat.
BSONObjIterator coordIt(center.Obj());
BSONElement lng = coordIt.next();
@@ -316,7 +316,11 @@ namespace mongo {
/** exported **/
bool GeoParser::isPoint(const BSONObj &obj) {
- return isGeoJSONPoint(obj) || isLegacyPoint(obj);
+ return isGeoJSONPoint(obj) || isLegacyPoint(obj, false);
+ }
+
+ bool GeoParser::isIndexablePoint(const BSONObj &obj) {
+ return isGeoJSONPoint(obj) || isLegacyPoint(obj, true);
}
bool GeoParser::parsePoint(const BSONObj &obj, PointWithCRS *out) {
@@ -327,7 +331,7 @@ namespace mongo {
out->oldPoint.x = coords[0].Number();
out->oldPoint.y = coords[1].Number();
out->crs = SPHERE;
- } else if (isLegacyPoint(obj)) {
+ } else if (isLegacyPoint(obj, true)) {
BSONObjIterator it(obj);
BSONElement x = it.next();
BSONElement y = it.next();
@@ -379,11 +383,11 @@ namespace mongo {
BSONObjIterator coordIt(type.embeddedObject());
BSONElement minE = coordIt.next();
if (!minE.isABSONObj()) { return false; }
- if (!isLegacyPoint(minE.Obj())) { return false; }
+ if (!isLegacyPoint(minE.Obj(), false)) { return false; }
if (!coordIt.more()) { return false; }
BSONElement maxE = coordIt.next();
if (!maxE.isABSONObj()) { return false; }
- if (!isLegacyPoint(maxE.Obj())) { return false; }
+ if (!isLegacyPoint(maxE.Obj(), false)) { return false; }
// XXX: VERIFY AREA >= 0
return true;
}