我正在尝试使用最新版本的Lucene(4.0.0)进行地理搜索功能,要求很简单:获取圆内的点(中心和半径作为查询条件传入)。我找不到输出每个结果到中心的距离的API,我必须在得到每个结果的纬度和经度后计算距离。有人可以帮忙吗?代码如下:
SpatialContext sc = SpatialContext.GEO;
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,
sc.makeCircle(lo, la, DistanceUtils.dist2Degrees(dist, DistanceUtils.EARTH_MEAN_RADIUS_KM)));
Filter geo_filter = strategy.makeFilter(args);
try {
Sort chainedSort = new Sort(sfArray).rewrite(searcher);
TopDocs docs = searcher.search(new MatchAllDocsQuery(), geo_filter, 10000, chainedSort);
logger.debug("search finished, num: " + docs.totalHits);
for (ScoreDoc scoreDoc : docs.scoreDocs){
Document doc = searcher.doc(scoreDoc.doc);
double la1 = Double.parseDouble(doc.get("la"));
double lo1 = Double.parseDouble(doc.get("lo"));
double distance = getDistance(la1, lo1, la, lo); // have to calc distance by myself here, not cool
}
} catch (IOException e) {
logger.error("fail to get the search result!", e);
}
使用 Lucene 3.X 很容易获得距离,任何熟悉使用 Lucene 4.0.0 进行地理(空间)搜索的人?