You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by di...@apache.org on 2011/05/21 23:58:40 UTC
[Lucene.Net] svn commit: r1125826 - in
/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial:
GeoHash/GeoHashDistanceFilter.cs Tier/LatLongDistanceFilter.cs
Author: digy
Date: Sat May 21 21:58:40 2011
New Revision: 1125826
URL: http://svn.apache.org/viewvc?rev=1125826&view=rev
Log:
[LUCENENET-412] broken Contrib.Spatial
Modified:
incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial/GeoHash/GeoHashDistanceFilter.cs
incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial/Tier/LatLongDistanceFilter.cs
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial/GeoHash/GeoHashDistanceFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial/GeoHash/GeoHashDistanceFilter.cs?rev=1125826&r1=1125825&r2=1125826&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial/GeoHash/GeoHashDistanceFilter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial/GeoHash/GeoHashDistanceFilter.cs Sat May 21 21:58:40 2011
@@ -56,33 +56,15 @@ namespace Lucene.Net.Spatial.GeoHash
internal class GeoHashFilteredDocIdSet : FilteredDocIdSet
{
- public GeoHashFilteredDocIdSet(DocIdSet innerSet, string[] geoHashValues, Dictionary<string, double> distanceLookupCache, double lat, double lng, int docBase, double distance, Dictionary<int, double> distances) : base(innerSet)
+ public GeoHashFilteredDocIdSet(DocIdSet innerSet, string[] geoHashValues, Dictionary<string, double> distanceLookupCache, double lat, double lng, int docBase, double distance, Dictionary<int, double> distances)
+ : base(innerSet , (docid) => /* public override Match */
{
- _geoHashValues = geoHashValues;
- _distances = distances;
- _distance = distance;
- _docBase = docBase;
- _lng = lng;
- _lat = lat;
- _distanceLookupCache = distanceLookupCache;
- }
-
- private readonly double _lat;
- private readonly double _lng;
- private readonly int _docBase;
- private readonly string[] _geoHashValues;
- private readonly Dictionary<int, double> _distances;
- private readonly Dictionary<string, double> _distanceLookupCache;
- private readonly double _distance;
-
- public override bool Match(int docid)
- {
- String geoHash = _geoHashValues[docid];
+ String geoHash = geoHashValues[docid];
double[] coords = GeoHashUtils.Decode(geoHash);
double x = coords[0];
double y = coords[1];
- Double cachedDistance = _distanceLookupCache[geoHash];
+ Double cachedDistance = distanceLookupCache[geoHash];
double d;
if (cachedDistance > 0)
@@ -91,18 +73,35 @@ namespace Lucene.Net.Spatial.GeoHash
}
else
{
- d = DistanceUtils.GetInstance().GetDistanceMi(_lat, _lng, x, y);
- _distanceLookupCache[geoHash] = d;
+ d = DistanceUtils.GetInstance().GetDistanceMi(lat, lng, x, y);
+ distanceLookupCache[geoHash] = d;
}
- if (d < _distance)
+ if (d < distance)
{
- _distances[docid + _docBase] = d;
+ distances[docid + docBase] = d;
return true;
}
return false;
+ })
+ {
+ _geoHashValues = geoHashValues;
+ _distances = distances;
+ _distance = distance;
+ _docBase = docBase;
+ _lng = lng;
+ _lat = lat;
+ _distanceLookupCache = distanceLookupCache;
}
+
+ private readonly double _lat;
+ private readonly double _lng;
+ private readonly int _docBase;
+ private readonly string[] _geoHashValues;
+ private readonly Dictionary<int, double> _distances;
+ private readonly Dictionary<string, double> _distanceLookupCache;
+ private readonly double _distance;
}
public override bool Equals(object o)
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial/Tier/LatLongDistanceFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial/Tier/LatLongDistanceFilter.cs?rev=1125826&r1=1125825&r2=1125826&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial/Tier/LatLongDistanceFilter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/contrib/Spatial/Tier/LatLongDistanceFilter.cs Sat May 21 21:58:40 2011
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+using System;
using System.Collections.Generic;
using Lucene.Net.Index;
using Lucene.Net.Search;
@@ -59,7 +60,35 @@ namespace Lucene.Net.Spatial.Tier
private readonly Dictionary<int, double> _distances;
public LatLongFilteredDocIdSet(DocIdSet innerSet, double[] latIndex, double[] lngIndex, Dictionary<string, double> distanceLookupCache, double lat, double lng, double distance, int docBase, Dictionary<int, double> distances)
- : base(innerSet)
+ : base(innerSet, (int docid) => /* public override Match */
+ {
+ 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;
+ })
{
_latIndex = latIndex;
_distances = distances;
@@ -70,37 +99,6 @@ namespace Lucene.Net.Spatial.Tier
_distanceLookupCache = distanceLookupCache;
_lngIndex = lngIndex;
}
-
- 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 override bool Equals(object o)