Skip to content

Commit

Permalink
de-dup results in a shell in s2nearcursor.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Hari Khalsa committed Jan 7, 2013
1 parent 8d4aeec commit fb217cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jstests/geo_s2dedupnear.js
@@ -0,0 +1,11 @@
// Make sure that we don't return several of the same result due to faulty
// assumptions about the btree cursor.
t = db.geo_s2dan
t.drop()

t.ensureIndex( { geo : "2dsphere" } )
var x = { "type" : "Polygon",
"coordinates" : [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]}
t.insert({geo: x})
res = t.find({geo: {$near: {"type" : "Point", "coordinates" : [31, 41]}}})
assert.eq(res.itcount(), 1)
18 changes: 18 additions & 0 deletions src/mongo/db/geo/s2nearcursor.cpp
Expand Up @@ -170,11 +170,29 @@ namespace mongo {
scoped_ptr<BtreeCursor> cursor(BtreeCursor::make(nsdetails(_details->parentNS()),
*_details, frv, 0, 1));

// The cursor may return the same obj more than once for a given
// FRS, so we make sure to only consider it once in any given annulus.
//
// We don't want this outside of the 'do' loop because the covering
// for an annulus may return an object whose distance to the query
// point is actually contained in a subsequent annulus. If we
// didn't consider every object in a given annulus we might miss
// the point.
//
// We don't use a global 'seen' because we get that by requiring
// the distance from the query point to the indexed geo to be
// within our 'current' annulus, and I want to dodge all yield
// issues if possible.
set<DiskLoc> seen;

// Do the actual search through this annulus.
size_t considered = 0;
for (; cursor->ok(); cursor->advance()) {
++considered;

if (seen.end() != seen.find(cursor->currLoc())) { continue; }
seen.insert(cursor->currLoc());

MatchDetails details;
bool matched = _matcher->matchesCurrent(cursor.get(), &details);
if (!matched) { continue; }
Expand Down

0 comments on commit fb217cf

Please sign in to comment.