2010-02-23 16:41:07 +01:00
|
|
|
|
|
|
|
t = db.geo2
|
|
|
|
t.drop();
|
|
|
|
|
|
|
|
n = 1
|
|
|
|
for ( var x=-100; x<100; x+=2 ){
|
|
|
|
for ( var y=-100; y<100; y+=2 ){
|
|
|
|
t.insert( { _id : n++ , loc : [ x , y ] } )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.ensureIndex( { loc : "2d" } )
|
|
|
|
|
2010-02-26 20:40:09 +01:00
|
|
|
fast = db.runCommand( { geoNear : t.getName() , near : [ 50 , 50 ] , num : 10 } );
|
|
|
|
slow = db.runCommand( { geoNear : t.getName() , near : [ 50 , 50 ] , num : 10 , start : "11" } );
|
2010-02-23 16:41:07 +01:00
|
|
|
|
2010-02-23 17:44:10 +01:00
|
|
|
printjson(fast.stats);
|
2010-02-23 18:49:24 +01:00
|
|
|
printjson(slow.stats);
|
2010-02-23 17:44:10 +01:00
|
|
|
|
2010-02-23 18:49:24 +01:00
|
|
|
v = "\n" + tojson( fast ) + "\n" + tojson( slow );
|
|
|
|
|
|
|
|
assert.lt( fast.stats.nscanned * 10 , slow.stats.nscanned , "A1" + v );
|
|
|
|
assert.lt( fast.stats.objectsLoaded , slow.stats.objectsLoaded , "A2" + v );
|
|
|
|
assert.eq( fast.stats.avgDistance , slow.stats.avgDistance , "A3" + v );
|
2010-02-23 16:41:07 +01:00
|
|
|
|
2010-02-26 05:34:01 +01:00
|
|
|
function a( cur ){
|
|
|
|
var total = 0;
|
|
|
|
var outof = 0;
|
|
|
|
while ( cur.hasNext() ){
|
2010-03-01 22:50:03 +01:00
|
|
|
var o = cur.next();
|
2010-03-02 04:06:30 +01:00
|
|
|
total += Geo.distance( [ 50 , 50 ] , o.loc );
|
2010-02-26 05:34:01 +01:00
|
|
|
outof++;
|
|
|
|
}
|
|
|
|
return total/outof;
|
2010-02-23 16:41:07 +01:00
|
|
|
}
|
|
|
|
|
2010-03-01 04:15:57 +01:00
|
|
|
assert.close( fast.stats.avgDistance , a( t.find( { loc : { $near : [ 50 , 50 ] } } ).limit(10) ) , "B1" )
|
2010-02-26 06:06:26 +01:00
|
|
|
assert.close( 1.33333 , a( t.find( { loc : { $near : [ 50 , 50 ] } } ).limit(3) ) , "B2" );
|
|
|
|
assert.close( fast.stats.avgDistance , a( t.find( { loc : { $near : [ 50 , 50 ] } } ).limit(10) ) , "B3" );
|
2010-02-25 22:24:34 +01:00
|
|
|
|
2010-02-26 16:37:17 +01:00
|
|
|
printjson( t.find( { loc : { $near : [ 50 , 50 ] } } ).explain() )
|
|
|
|
|
|
|
|
|
2010-04-01 21:32:52 +02:00
|
|
|
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" )
|
2010-04-01 23:17:32 +02:00
|
|
|
assert.gt( 3 , a( t.find( { loc : { $near : [ 50 , 50 ] , $maxDistance : 3 } } ).limit(50) ) , "C3" )
|
2010-04-01 21:32:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
|