Hi David, thanks for these hints! Unfortunately that didn't change anything yet. I made the fixes that you suggested:
val queryPoint = spatialCtx.makePoint(lon, lat) val args = new SpatialArgs(SpatialOperation.IsWithin, spatialCtx.makeCircle(queryPoint, DistanceUtils.dist2Degrees(20, DistanceUtils.EARTH_MEAN_RADIUS_KM))) But while the swapped lon/lat would have been an explanation, it turns out that it doesn't matter what I set as the query point when defining the valueSource. No effect on the sorting. I wonder if I'm doing something wrong when indexing the shapes. The circle filter seems to work perfectly, though. The only difference I could spot to the SpatialExample is that I'm using the JtsSpatialContext.GEO rather than the SpatialContext.GEO. Still puzzled :-( Cheers, Rainer ________________________________________ Von: david.w.smi...@gmail.com [david.w.smi...@gmail.com] Gesendet: Mittwoch, 25. Februar 2015 16:25 An: java-user@lucene.apache.org Betreff: Re: Can't get distance sorting to work in Lucene Spatial 4.10.3 Hi Rainer, I see two issues. One is that you call makePoint with latitude (Y) then longitude (X). Spatial4j is X then Y order. The second issue is more stylistic (but in this case it may explain your symptom due to the X & Y mixup) is that, since you already have a ‘point’, when you call makeCircle you ought to provide it (it’s overloaded) instead of re-referencing X & Y. I suggest renaming “point” to “queryPoint” to help clarify what it’s for. Without me spending more time trying your code, I’m not sure if what I found fixes what you see or if there is another bug. If there is still a bug, perhaps start with the SpatialExample.java in a working state and iteratively modify it to work how you want it to, testing each time that the sort works. ~ David On Wed, Feb 25, 2015 at 7:18 AM, Simon Rainer <rainer.si...@ait.ac.at> wrote: > Hi! > > I have problems getting distance sorting to work in Lucene Spatial. (I'm > using v4.10.3.) I'm following the SpatialExample.java from the Lucene docs. > My code is below (it's Scala, but translates 1:1 into Java). When I run the > query, results don't seem to be affected by the sorting at all. Changing > the sort order from ascending to descending has no effect either. > > I can't see any difference between what I'm doing and the offical example > (except the use of the SearcherManager, but I've checked and that doesn't > make a difference). Any hints appreciated! > > Cheers, > Rainer > > > --- Code > > Here's my code (Scala - but translates 1:1 into Java): > > val searcher = placeSearcherManager.acquire() > val point = spatialCtx.makePoint(lat, lon) > val args = > new SpatialArgs(SpatialOperation.Intersects, > spatialCtx.makeCircle(lon, lat, > DistanceUtils.dist2Degrees(100, > DistanceUtils.EARTH_MEAN_RADIUS_KM))) > > val filter = spatialStrategy.makeFilter(args) > > // Here's what's supposed to set up distance sorting > val valueSource = spatialStrategy.makeDistanceValueSource(point) > val distanceSort = new > Sort(valueSource.getSortField(false)).rewrite(searcher) > > try { > val topDocs = searcher.search(new MatchAllDocsQuery(), filter, > limit, distanceSort) > val scoreDocs = topDocs.scoreDocs > > // Print the results > scoreDocs.foreach(scoreDoc => { > val doc = searcher.doc(scoreDoc.doc) > val docPoint = > spatialCtx.readShape(doc.get(spatialStrategy.getFieldName())).asInstanceOf[Point] > val distance = > spatialCtx.getDistCalc().distance(args.getShape.getCenter, docPoint) > val distanceKM = DistanceUtils.degrees2Dist(distance, > DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM) > Logger.info("distance: " + distanceKM) > }) > } finally { > placeSearcherManager.release(searcher) > } > > --- Log output > > [info] application - distance: 406.01578203364323 > [info] application - distance: 327.67269076509876 > [info] application - distance: 218.94951150657565 > [info] application - distance: 251.37927074183852 > [info] application - distance: 140.6570939383426 > [info] application - distance: 460.47502999630586 > [info] application - distance: 462.37676932762116 > [info] application - distance: 489.49001138999256 > [info] application - distance: 392.0773262500455 > [info] application - distance: 227.8864179949065 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org