The default implementation of a spatial query sorts results by distance already. It's only when you use a non-spatial query that you need to specify a custom Sort for that to happen, and it's pretty trivial to implement.
See: https://github.com/ayende/ravendb/blob/master/Raven.Database/Indexing/Sorting/SpatialDistanceSortField.cs On Fri, Nov 16, 2012 at 11:19 AM, Albert Clemente Peláez < [email protected]> wrote: > Hello, > > > > A few days ago I started using spatial searches with 3.0.3 release and the > Spatial Contrib + Spatial4N. > > > > Although I found some starting problems, It finally worked great when I > understood that the Spatial Contrib was based on the new Spatial of Lucene > 4 for Java. > > > > > > My problem now is that although I can search by proximity, I cannot order > by distance, and that is due to it hasn't been ported the type > SortField.REWRITABLE and the ValueSourceComparatorSource and > ValueSourceComparator that able to order by distance on spatial searches. > > > > > > I'm just trying that these staff works (sample from java): > > > > //--Match all, order by distance > > { > > Point pt = ctx.makePoint(60, -50); > > ValueSource valueSource = strategy.makeDistanceValueSource(pt);//the > distance (in degrees) > > Sort reverseDistSort = new > sort(valueSource.getSortField(false)).rewrite(indexSearcher);//true=asc dist > > TopDocs docs = indexSearcher.search(new MatchAllDocsQuery(), 10, > reverseDistSort); > > assertDocMatchedIds(indexSearcher, docs, 4, 20, 2); > > > > > > > > If I port this java classes and functions to Lucene.net and > Contrib.Spatial, I'd like that it would be include in the final release, > just to be sure we will be able to continue upgrading to future Lucene.net > releases without recoding our apps. > > > > > Please let me know If I'm not right or If you know a better aproach for > ording by distance. > > > > > > Regards, > > > > > > Albert Clemente > > > > > > > >
