void GeoSearch::addExactPoints(const GeoPoint& pt, Holder& points, int& before, int& after, bool force){ before = 0; after = 0; if(pt.isExact()){ if(force) points.insert(pt); return; } vector<BSONObj> locs; // last argument is uniqueDocs getPointsFor(pt.key(), pt.obj(), locs, true); GeoPoint nearestPt(pt, -1, true); for(vector<BSONObj>::iterator i = locs.begin(); i != locs.end(); i++){ Point loc(*i); double d; if(! exactDocCheck(loc, d)) continue; if(nearestPt.distance() < 0 || d < nearestPt.distance()){ nearestPt._distance = d; nearestPt._pt = *i; continue; } } if(nearestPt.distance() >= 0){ points.insert(nearestPt); if(nearestPt < pt) before++; else after++; } }
int GeoBrowse::addSpecific(const GeoIndexEntry& node, const Point& keyP, bool onBounds, double keyD, bool potentiallyNewDoc) { int found = 0; // We need to handle every possible point in this method, even those not in the key // value, to avoid us tracking which hashes we've already seen. if(! potentiallyNewDoc){ return 0; } // Final check for new doc // OK to touch, since we're probably returning this object now if(remembered(node.recordLoc.obj())) { //cout << "remembered\n"; return 0; } if(_uniqueDocs && ! onBounds) { //log() << "Added ind to " << _type << endl; _stack.push_front(GeoPoint(node)); found++; } else { // We now handle every possible point in the document, even those not in the key // value, since we're iterating through them anyway - prevents us from having to // save the hashes we've seen per-doc // If we're filtering by hash, get the original vector< BSONObj > locs; getPointsFor(node._key, node.recordLoc.obj(), locs, true); for(vector< BSONObj >::iterator i = locs.begin(); i != locs.end(); ++i){ double d = -1; Point p(*i); // We can avoid exact document checks by redoing approx checks, // if the exact checks are more expensive. bool needExact = true; if(! needExact || exactDocCheck(p, d)){ //log() << "Added mult to " << _type << endl; _stack.push_front(GeoPoint(node)); found++; // If returning unique, just exit after first point is added if(_uniqueDocs) break; } } } while(_cur.isEmpty() && _stack.size() > 0){ _cur = _stack.front(); _stack.pop_front(); } return found; }