I'm trying to use the geolocation search function with the latest version of Lucene (4.0.0), the requirement is simple: getting points inside the circle (center and radius are passed as a query condition). I can not find an API that displays the distance of each result to the center, I have to calculate the distance after I exit the latitude and longitude of each result. can anyone help? The code is shown below:
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);
Easy to get to Lucene 3.X, anyone familiar with geospatial searches with Lucene 4.0.0?
source share