Permalink
Browse files

$maxDistance for $near SERVER-813

  • Loading branch information...
1 parent d42bd9a commit 9c8fa4b93548c6c6e1113e9b66d2400e3eacfdd1 @erh erh committed Apr 1, 2010
Showing with 16 additions and 3 deletions.
  1. +7 −1 db/index_geo2d.cpp
  2. +6 −2 db/jsobj.cpp
  3. +1 −0 db/jsobj.h
  4. +1 −0 db/matcher.cpp
  5. +1 −0 jstests/geo2.js
View
@@ -1478,7 +1478,8 @@ namespace mongo {
switch ( e.embeddedObject().firstElement().getGtLtOp() ){
case BSONObj::opNEAR: {
- e = e.embeddedObject().firstElement();
+ BSONObj n = e.embeddedObject();
+ e = n.firstElement();
double maxDistance = numeric_limits<double>::max();
if ( e.isABSONObj() && e.embeddedObject().nFields() > 2 ){
BSONObjIterator i(e.embeddedObject());
@@ -1488,6 +1489,11 @@ namespace mongo {
if ( e.isNumber() )
maxDistance = e.numberDouble();
}
+ {
+ BSONElement e = n["$maxDistance"];
+ if ( e.isNumber() )
+ maxDistance = e.numberDouble();
+ }
shared_ptr<GeoSearch> s( new GeoSearch( this , _tohash(e) , numWanted , query , maxDistance ) );
s->exec();
auto_ptr<Cursor> c;
View
@@ -434,8 +434,12 @@ namespace mongo {
if ( fn[3] == 'a' && fn[4] == 'r' && fn[5] == 0 )
return BSONObj::opNEAR;
}
- else if ( fn[1] == 'm' && fn[2] == 'o' && fn[3] == 'd' && fn[4] == 0 )
- return BSONObj::opMOD;
+ else if ( fn[1] == 'm' ){
+ if ( fn[2] == 'o' && fn[3] == 'd' && fn[4] == 0 )
+ return BSONObj::opMOD;
+ if ( fn[2] == 'a' && fn[3] == 'x' && fn[4] == 'D' && fn[5] == 'i' && fn[6] == 's' && fn[7] == 't' && fn[8] == 'a' && fn[9] == 'n' && fn[10] == 'c' && fn[11] == 'e' && fn[12] == 0 )
+ return BSONObj::opMAX_DISTANCE;
+ }
else if ( fn[1] == 't' && fn[2] == 'y' && fn[3] == 'p' && fn[4] == 'e' && fn[5] == 0 )
return BSONObj::opTYPE;
else if ( fn[1] == 'i' && fn[2] == 'n' && fn[3] == 0 )
View
@@ -986,6 +986,7 @@ namespace mongo {
opELEM_MATCH = 0x12,
opNEAR = 0x13,
opWITHIN = 0x14,
+ opMAX_DISTANCE=0x15
};
};
ostream& operator<<( ostream &s, const BSONObj &o );
View
@@ -283,6 +283,7 @@ namespace mongo {
}
case BSONObj::opNEAR:
case BSONObj::opWITHIN:
+ case BSONObj::opMAX_DISTANCE:
break;
default:
uassert( 10069 , (string)"BUG - can't operator for: " + fn , 0 );
View
@@ -43,6 +43,7 @@ printjson( t.find( { loc : { $near : [ 50 , 50 ] } } ).explain() )
assert.lt( 3 , a( t.find( { loc : { $near : [ 50 , 50 ] } } ).limit(50) ) , "C1" )
assert.gt( 3 , a( t.find( { loc : { $near : [ 50 , 50 , 3 ] } } ).limit(50) ) , "C2" )
+assert.gt( 3 , a( t.find( { loc : { $near : [ 50 , 50 ] , $maxDistance : 3 } } ).limit(50) ) , "C3" )

0 comments on commit 9c8fa4b

Please sign in to comment.