Skip to content

Commit

Permalink
$maxDistance for $near SERVER-813
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Apr 1, 2010
1 parent d42bd9a commit 9c8fa4b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion db/index_geo2d.cpp
Expand Up @@ -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());
Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions db/jsobj.cpp
Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions db/jsobj.h
Expand Up @@ -986,6 +986,7 @@ namespace mongo {
opELEM_MATCH = 0x12,
opNEAR = 0x13,
opWITHIN = 0x14,
opMAX_DISTANCE=0x15
};
};
ostream& operator<<( ostream &s, const BSONObj &o );
Expand Down
1 change: 1 addition & 0 deletions db/matcher.cpp
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions jstests/geo2.js
Expand Up @@ -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.