public override bool Match(int docid) { double x = _latIndex[docid]; double y = _lngIndex[docid]; string ck = x + "," + y; double cachedDistance = _distanceLookupCache.ContainsKey(ck) ? _distanceLookupCache[ck] : 0; double d; if (cachedDistance > 0) { d = cachedDistance; } else { d = DistanceUtils.GetInstance().GetDistanceMi(_lat, _lng, x, y); _distanceLookupCache[ck] = d; } if (d < _distance) { // Save distances, so they can be pulled for // sorting after filtering is done: _distances[docid + _docBase] = d; return(true); } return(false); }
public double GetDistance(int docid, double centerLat, double centerLng, double lat, double lng) { // check to see if we have distances // if not calculate the distance if (_distances == null) { return(DistanceUtils.GetInstance().GetDistanceMi(centerLat, centerLng, lat, lng)); } // check to see if the doc id has a cached distance double docd; _distances.TryGetValue(docid, out docd); if (docd > 0) { return(docd); } //check to see if we have a precision code // and if another lat/long has been calculated at // that rounded location if (_precision.HasValue) { double xLat = GetPrecision(lat, _precision); double xLng = GetPrecision(lng, _precision); String k = xLat + "," + xLng; Double d; _distanceLookupCache.TryGetValue(k, out d); if (d > 0) { return(d); } } //all else fails calculate the distances return(DistanceUtils.GetInstance().GetDistanceMi(centerLat, centerLng, lat, lng)); }