std::unique_ptr<GeoMatchExpression> makeGeoMatchExpression(const BSONObj& locQuery) { std::unique_ptr<GeoExpression> gq(new GeoExpression); ASSERT_OK(gq->parseFrom(locQuery)); std::unique_ptr<GeoMatchExpression> ge = stdx::make_unique<GeoMatchExpression>("a", gq.release(), locQuery); return ge; }
TEST(ExpressionGeoTest, Geo1) { BSONObj query = fromjson("{loc:{$within:{$box:[{x: 4, y:4},[6,6]]}}}"); std::unique_ptr<GeoExpression> gq(new GeoExpression); ASSERT_OK(gq->parseFrom(query["loc"].Obj())); GeoMatchExpression ge("a", gq.release(), query); ASSERT(!ge.matchesBSON(fromjson("{a: [3,4]}"))); ASSERT(ge.matchesBSON(fromjson("{a: [4,4]}"))); ASSERT(ge.matchesBSON(fromjson("{a: [5,5]}"))); ASSERT(ge.matchesBSON(fromjson("{a: [5,5.1]}"))); ASSERT(ge.matchesBSON(fromjson("{a: {x: 5, y:5.1}}"))); }
StatusWithMatchExpression expressionParserGeoCallbackReal( const char* name, int type, const BSONObj& section ) { if (BSONObj::opWITHIN == type || BSONObj::opGEO_INTERSECTS == type) { auto_ptr<GeoQuery> gq(new GeoQuery(name)); if ( !gq->parseFrom( section ) ) return StatusWithMatchExpression( ErrorCodes::BadValue, "bad geo query" ); auto_ptr<GeoMatchExpression> e( new GeoMatchExpression() ); // Until the index layer accepts non-BSON predicates, or special indices are moved into // stages, we have to clean up the raw object so it can be passed down to the index // layer. BSONObjBuilder bob; bob.append(name, section); Status s = e->init( name, gq.release(), bob.obj() ); if ( !s.isOK() ) return StatusWithMatchExpression( s ); return StatusWithMatchExpression( e.release() ); } else { verify(BSONObj::opNEAR == type); NearQuery nq(name); Status s = nq.parseFrom( section ); if ( !s.isOK() ) { return StatusWithMatchExpression( s ); } auto_ptr<GeoNearMatchExpression> e( new GeoNearMatchExpression() ); // Until the index layer accepts non-BSON predicates, or special indices are moved into // stages, we have to clean up the raw object so it can be passed down to the index // layer. BSONObjBuilder bob; bob.append(name, section); s = e->init( name, nq, bob.obj() ); if ( !s.isOK() ) return StatusWithMatchExpression( s ); return StatusWithMatchExpression( e.release() ); } }
forceinline ModEvent IntView::gr(Space& home, double n) { return gq(home,n+1.0); }