Exemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="xvals">array of x coordinate values for docid</param>
 /// <param name="yvals">array of y coordinate values for docid</param>
 /// <param name="zvals">array of z coordinate values for docid</param>
 /// <param name="lat">target latitude</param>
 /// <param name="lon">target longitude</param>
 /// <param name="radius">target radius</param>
 /// <param name="maxdoc">max doc in the docid set</param>
 /// <param name="miles">variable to specify if the geo distance calculations are in miles.
 /// False indicates distance calculation is in kilometers</param>
 internal GeoDocIdSet(BigSingleArray xvals, BigSingleArray yvals, BigSingleArray zvals, float lat, float lon,
                      float radius, int maxdoc, bool miles)
 {
     m_xvals = xvals;
     m_yvals = yvals;
     m_zvals = zvals;
     m_miles = miles;
     if (m_miles)
     {
         m_radius = GeoMatchUtil.GetMilesRadiusCosine(radius);
     }
     else
     {
         m_radius = GeoMatchUtil.GetKMRadiusCosine(radius);
     }
     float[] coords = GeoMatchUtil.GeoMatchCoordsFromDegrees(lat, lon);
     m_targetX = coords[0];
     m_targetY = coords[1];
     m_targetZ = coords[2];
     if (m_miles)
     {
         m_delta = (float)(radius / GeoMatchUtil.EARTH_RADIUS_MILES);
     }
     else
     {
         m_delta = (float)(radius / GeoMatchUtil.EARTH_RADIUS_KM);
     }
     m_maxDoc = maxdoc;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="docid">The docid for which the facet counts are to be calculated</param>
        public virtual void Collect(int docid)
        {
            float docX = _xvals.Get(docid);
            float docY = _yvals.Get(docid);
            float docZ = _zvals.Get(docid);

            float radius, targetX, targetY, targetZ, delta;
            float xu, xl, yu, yl, zu, zl;
            int countIndex = -1;
            foreach (GeoRange range in _ranges)
            {
                // the countIndex for the count array should increment with the range index of the _ranges array
                countIndex++;
                if (_miles)
                    radius = GeoMatchUtil.GetMilesRadiusCosine(range.Rad);
                else
                    radius = GeoMatchUtil.GetKMRadiusCosine(range.Rad);

                float[] coords = GeoMatchUtil.GeoMatchCoordsFromDegrees(range.Lat, range.Lon);
                targetX = coords[0];
                targetY = coords[1];
                targetZ = coords[2];

                if (_miles)
                    delta = (float)(range.Rad / GeoMatchUtil.EARTH_RADIUS_MILES);
                else
                    delta = (float)(range.Rad / GeoMatchUtil.EARTH_RADIUS_KM);

                xu = targetX + delta;
                xl = targetX - delta;

                // try to see if the range checks can short circuit the actual inCircle check
                if (docX > xu || docX < xl) continue;

                yu = targetY + delta;
                yl = targetY - delta;

                if (docY > yu || docY < yl) continue;

                zu = targetZ + delta;
                zl = targetZ - delta;

                if (docZ > zu || docZ < zl) continue;

                if (GeoFacetFilter.InCircle(docX, docY, docZ, targetX, targetY, targetZ, radius))
                {
                    // if the lat, lon values of this docid match the current user-specified range, then increment the
                    // appropriate count[] value
                    _count.Add(countIndex, _count.Get(countIndex) + 1);
                    // do not break here, since one document could lie in multiple user-specified ranges
                }
            }
        }