Geolocation Lucene.net近距离搜索

Geolocation Lucene.net近距离搜索,geolocation,lucene.net,Geolocation,Lucene.net,有没有人有过lucene.net索引纬度和经度值然后根据与单个点的距离返回一组有序结果的经验 Lucene.Net.Spatial library会帮我做这件事吗?派对有点晚了,但是是的,Spatial library是开始做这件事的地方。其背后的基础是: 1) 将Lat和Long字段添加到文档中 doc.Add(new Field("Latitude", NumericUtils.DoubleToPrefixCoded(Latitude),

有没有人有过lucene.net索引纬度和经度值然后根据与单个点的距离返回一组有序结果的经验


Lucene.Net.Spatial library会帮我做这件事吗?

派对有点晚了,但是是的,Spatial library是开始做这件事的地方。其背后的基础是:

1) 将Lat和Long字段添加到文档中

doc.Add(new Field("Latitude", 
                  NumericUtils.DoubleToPrefixCoded(Latitude), 
                  Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.Add(new Field("Longitude", 
                  NumericUtils.DoubleToPrefixCoded(Longitude), 
                  Field.Store.YES, Field.Index.NOT_ANALYZED));
2) 为搜索需要支持的每一层粒度创建绘图仪

IProjector projector = new SinusoidalProjector();
var ctp = new CartesianTierPlotter(0, projector, 
                                   Fields.LocationTierPrefix);
StartTier = ctp.BestFit(MaxKms);
EndTier = ctp.BestFit(MinKms);

Plotters = new Dictionary<int, CartesianTierPlotter>();
for (var tier = StartTier; tier <= EndTier; tier++)
{
    Plotters.Add(tier, new CartesianTierPlotter(tier, 
                                            projector, 
                                            Fields.LocationTierPrefix));
}

所有这些都是从我刚刚写的一篇博客文章中摘取的,当时我正在研究一个类似的问题。你可以在

好问题上看到它。我也想知道。谢谢你的好例子。我对边界区域部分有问题。。。有一点不对劲,就是它只提供彼此非常接近但远离我要求的坐标的文档,所以LatLongDistanceFilter检查它们,发现它们太远了,所以没有返回结果。我在我们的博客()中添加了另一个工作示例。这有所有的代码,你需要看到一个演示应用程序的运作,所以希望能帮助你。
private static void AddCartesianTiers(double latitude, 
                                      double longitude, 
                                      Document document)
{
    for (var tier = StartTier; tier <= EndTier; tier++)
    {
        var ctp = Plotters[tier];
        var boxId = ctp.GetTierBoxId(latitude, longitude);
        document.Add(new Field(ctp.GetTierFieldName(),
                        NumericUtils.DoubleToPrefixCoded(boxId),
                        Field.Store.YES,
                        Field.Index.NOT_ANALYZED_NO_NORMS));
    }
}
/*  Builder allows us to build a polygon which we will use to limit  
 * search scope on our cartesian tiers, this is like putting a grid 
 * over a map */
var builder = new CartesianPolyFilterBuilder(Fields.LocationTierPrefix);

/*  Bounding area draws the polygon, this can be thought of as working  
 * out which squares of the grid over a map to search */
var boundingArea = builder.GetBoundingArea(Latitude, 
                Longitude, 
                DistanceInKilometres * ProductSearchEngine.KmsToMiles);

/*  We refine, this is the equivalent of drawing a circle on the map,  
 *  within our grid squares, ignoring the parts the squares we are  
 *  searching that aren't within the circle - ignoring extraneous corners 
 *  and such */
var distFilter = new LatLongDistanceFilter(boundingArea, 
                                    DistanceInKilometres * KmsToMiles,
                                    Latitude, 
                                    Longitude, 
                                    ProductSearchEngine.Fields.Latitude,
                                    ProductSearchEngine.Fields.Longitude);

/*  We add a query stating we will only search against products that have 
 * GeoCode information */
var query = new TermQuery(new Term(Fields.HasGeoCode, 
                                   FieldFlags.HasField));

/*  Add our filter, this will stream through our results and 
 * determine eligibility */
masterQuery.Add(new ConstantScoreQuery(distanceFilter), 
                BooleanClause.Occur.MUST);