summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_geo.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/matcher/expression_geo.h')
-rw-r--r--src/mongo/db/matcher/expression_geo.h255
1 files changed, 133 insertions, 122 deletions
diff --git a/src/mongo/db/matcher/expression_geo.h b/src/mongo/db/matcher/expression_geo.h
index 4dbf1bb65bf..90525521def 100644
--- a/src/mongo/db/matcher/expression_geo.h
+++ b/src/mongo/db/matcher/expression_geo.h
@@ -39,138 +39,149 @@
namespace mongo {
- struct PointWithCRS;
- class GeometryContainer;
+struct PointWithCRS;
+class GeometryContainer;
- // This represents either a $within or a $geoIntersects.
- class GeoExpression {
- MONGO_DISALLOW_COPYING(GeoExpression);
+// This represents either a $within or a $geoIntersects.
+class GeoExpression {
+ MONGO_DISALLOW_COPYING(GeoExpression);
+
+public:
+ GeoExpression();
+ GeoExpression(const std::string& f);
+
+ enum Predicate { WITHIN, INTERSECT, INVALID };
+
+ // parseFrom() must be called before getGeometry() to ensure initialization of geoContainer
+ Status parseFrom(const BSONObj& obj);
+
+ std::string getField() const {
+ return field;
+ }
+ Predicate getPred() const {
+ return predicate;
+ }
+ const GeometryContainer& getGeometry() const {
+ return *geoContainer;
+ }
- public:
- GeoExpression();
- GeoExpression(const std::string& f);
+private:
+ // Parse geospatial query
+ // e.g.
+ // { "$intersect" : { "$geometry" : { "type" : "Point", "coordinates": [ 40, 5 ] } } }
+ Status parseQuery(const BSONObj& obj);
- enum Predicate {
- WITHIN,
- INTERSECT,
- INVALID
- };
+ // Name of the field in the query.
+ std::string field;
+ boost::scoped_ptr<GeometryContainer> geoContainer;
+ Predicate predicate;
+};
- // parseFrom() must be called before getGeometry() to ensure initialization of geoContainer
- Status parseFrom(const BSONObj &obj);
+class GeoMatchExpression : public LeafMatchExpression {
+public:
+ GeoMatchExpression() : LeafMatchExpression(GEO) {}
+ virtual ~GeoMatchExpression() {}
- std::string getField() const { return field; }
- Predicate getPred() const { return predicate; }
- const GeometryContainer& getGeometry() const { return *geoContainer; }
+ /**
+ * Takes ownership of the passed-in GeoExpression.
+ */
+ Status init(const StringData& path, const GeoExpression* query, const BSONObj& rawObj);
+
+ virtual bool matchesSingleElement(const BSONElement& e) const;
+
+ virtual void debugString(StringBuilder& debug, int level = 0) const;
+
+ virtual void toBSON(BSONObjBuilder* out) const;
+
+ virtual bool equivalent(const MatchExpression* other) const;
+
+ virtual LeafMatchExpression* shallowClone() const;
+
+ const GeoExpression& getGeoExpression() const {
+ return *_query;
+ }
+ const BSONObj getRawObj() const {
+ return _rawObj;
+ }
+
+private:
+ BSONObj _rawObj;
+ // Share ownership of our query with all of our clones
+ boost::shared_ptr<const GeoExpression> _query;
+};
+
+
+// TODO: Make a struct, turn parse stuff into something like
+// static Status parseNearQuery(const BSONObj& obj, NearQuery** out);
+class GeoNearExpression {
+ MONGO_DISALLOW_COPYING(GeoNearExpression);
+
+public:
+ GeoNearExpression();
+ GeoNearExpression(const std::string& f);
+
+ Status parseFrom(const BSONObj& obj);
+
+ // The name of the field that contains the geometry.
+ std::string field;
+
+ // The starting point of the near search. Use forward declaration of geometries.
+ boost::scoped_ptr<PointWithCRS> centroid;
+
+ // Min and max distance from centroid that we're willing to search.
+ // Distance is in units of the geometry's CRS, except SPHERE and isNearSphere => radians
+ double minDistance;
+ double maxDistance;
+
+ // Is this a $nearSphere query
+ bool isNearSphere;
+ // $nearSphere with a legacy point implies units are radians
+ bool unitsAreRadians;
+ // $near with a non-legacy point implies a wrapping query, otherwise the query doesn't wrap
+ bool isWrappingQuery;
+
+ std::string toString() const {
+ std::stringstream ss;
+ ss << " field=" << field;
+ ss << " maxdist=" << maxDistance;
+ ss << " isNearSphere=" << isNearSphere;
+ return ss.str();
+ }
+
+private:
+ bool parseLegacyQuery(const BSONObj& obj);
+ Status parseNewQuery(const BSONObj& obj);
+};
+
+class GeoNearMatchExpression : public LeafMatchExpression {
+public:
+ GeoNearMatchExpression() : LeafMatchExpression(GEO_NEAR) {}
+ virtual ~GeoNearMatchExpression() {}
+
+ Status init(const StringData& path, const GeoNearExpression* query, const BSONObj& rawObj);
+
+ // This shouldn't be called and as such will crash. GeoNear always requires an index.
+ virtual bool matchesSingleElement(const BSONElement& e) const;
- private:
- // Parse geospatial query
- // e.g.
- // { "$intersect" : { "$geometry" : { "type" : "Point", "coordinates": [ 40, 5 ] } } }
- Status parseQuery(const BSONObj &obj);
+ virtual void debugString(StringBuilder& debug, int level = 0) const;
- // Name of the field in the query.
- std::string field;
- boost::scoped_ptr<GeometryContainer> geoContainer;
- Predicate predicate;
- };
+ virtual void toBSON(BSONObjBuilder* out) const;
- class GeoMatchExpression : public LeafMatchExpression {
- public:
- GeoMatchExpression() : LeafMatchExpression( GEO ){}
- virtual ~GeoMatchExpression(){}
+ virtual bool equivalent(const MatchExpression* other) const;
- /**
- * Takes ownership of the passed-in GeoExpression.
- */
- Status init( const StringData& path, const GeoExpression* query, const BSONObj& rawObj );
+ virtual LeafMatchExpression* shallowClone() const;
- virtual bool matchesSingleElement( const BSONElement& e ) const;
+ const GeoNearExpression& getData() const {
+ return *_query;
+ }
+ const BSONObj getRawObj() const {
+ return _rawObj;
+ }
- virtual void debugString( StringBuilder& debug, int level = 0 ) const;
-
- virtual void toBSON(BSONObjBuilder* out) const;
-
- virtual bool equivalent( const MatchExpression* other ) const;
-
- virtual LeafMatchExpression* shallowClone() const;
-
- const GeoExpression& getGeoExpression() const { return *_query; }
- const BSONObj getRawObj() const { return _rawObj; }
-
- private:
- BSONObj _rawObj;
- // Share ownership of our query with all of our clones
- boost::shared_ptr<const GeoExpression> _query;
- };
-
-
- // TODO: Make a struct, turn parse stuff into something like
- // static Status parseNearQuery(const BSONObj& obj, NearQuery** out);
- class GeoNearExpression {
- MONGO_DISALLOW_COPYING(GeoNearExpression);
-
- public:
- GeoNearExpression();
- GeoNearExpression(const std::string& f);
-
- Status parseFrom(const BSONObj &obj);
-
- // The name of the field that contains the geometry.
- std::string field;
-
- // The starting point of the near search. Use forward declaration of geometries.
- boost::scoped_ptr<PointWithCRS> centroid;
-
- // Min and max distance from centroid that we're willing to search.
- // Distance is in units of the geometry's CRS, except SPHERE and isNearSphere => radians
- double minDistance;
- double maxDistance;
-
- // Is this a $nearSphere query
- bool isNearSphere;
- // $nearSphere with a legacy point implies units are radians
- bool unitsAreRadians;
- // $near with a non-legacy point implies a wrapping query, otherwise the query doesn't wrap
- bool isWrappingQuery;
-
- std::string toString() const {
- std::stringstream ss;
- ss << " field=" << field;
- ss << " maxdist=" << maxDistance;
- ss << " isNearSphere=" << isNearSphere;
- return ss.str();
- }
-
- private:
- bool parseLegacyQuery(const BSONObj &obj);
- Status parseNewQuery(const BSONObj &obj);
- };
-
- class GeoNearMatchExpression : public LeafMatchExpression {
- public:
- GeoNearMatchExpression() : LeafMatchExpression( GEO_NEAR ){}
- virtual ~GeoNearMatchExpression(){}
-
- Status init( const StringData& path, const GeoNearExpression* query, const BSONObj& rawObj );
-
- // This shouldn't be called and as such will crash. GeoNear always requires an index.
- virtual bool matchesSingleElement( const BSONElement& e ) const;
-
- virtual void debugString( StringBuilder& debug, int level = 0 ) const;
-
- virtual void toBSON(BSONObjBuilder* out) const;
-
- virtual bool equivalent( const MatchExpression* other ) const;
-
- virtual LeafMatchExpression* shallowClone() const;
-
- const GeoNearExpression& getData() const { return *_query; }
- const BSONObj getRawObj() const { return _rawObj; }
- private:
- BSONObj _rawObj;
- // Share ownership of our query with all of our clones
- boost::shared_ptr<const GeoNearExpression> _query;
- };
+private:
+ BSONObj _rawObj;
+ // Share ownership of our query with all of our clones
+ boost::shared_ptr<const GeoNearExpression> _query;
+};
} // namespace mongo