You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by Albert Clemente Peláez <al...@anuntis.com> on 2012/11/21 15:37:41 UTC

Order by distance (Project Test attached)

Hello,

Here you have a demo where you can see the order of the results in a spatial search it's not ordered by proximity as expected.

http://www.coches.net/staticpages/lucene/spatialdemo.zip 

I hope it helps! ;)

Albert


-----Mensaje original-----
De: Albert Clemente Peláez
Enviado el: lunes, 19 de noviembre de 2012 17:27
Para: dev@lucenenet.apache.org
Asunto: RE: Order by distance on Spatial Searches (porting from Lucene4 Java)

Hello,

I attach you a Test in C# where you can see there should be a bug in a spatial search (it's not ordered by distance).

I hope it helps ;)

Regards


-----Mensaje original-----
De: itamar.synhershko@gmail.com [mailto:itamar.synhershko@gmail.com] En nombre de Itamar Syn-Hershko Enviado el: sábado, 17 de noviembre de 2012 20:09
Para: dev@lucenenet.apache.org
Asunto: Re: Order by distance on Spatial Searches (porting from Lucene4 Java)

hits = lucene_searcher.Search(strategy.MakeQuery(spatialargs), 100)

Should work

If it doesn't, please provide a full failing test in C#


On Fri, Nov 16, 2012 at 1:41 PM, Albert Clemente Peláez < albert.clemente@anuntis.com> wrote:

> Hi Itamar,
>
> When I search for a Spatial field without specifying a sort field the 
> result is not ordered by distance.
>
> This is a very simple sample of my search:
>
>
>
> Private Shared context As New SpatialContext(True) Private Shared 
> strategy As New RecursivePrefixTreeStrategy(New 
> GeohashPrefixTree(context, GeohashPrefixTree.GetMaxLevelsPossible()),
> "geofield")
>
> Dim pquery As BooleanQuery
>
> Dim spatialargs As New SpatialArgs(SpatialOperation.Intersects,
> Context.MakeCircle(39.452834, -0.386697, 
> Distance.DistanceUtils.Dist2Degrees(300,
> Distance.DistanceUtils.EARTH_MEAN_RADIUS_KM)))
>
> pquery.Add(strategy.MakeQuery(spatialargs), Occur.MUST)
>
> hits = lucene_searcher.Search(pquery, 100)
>
>
>
>
> -----Mensaje original-----
> De: itamar.synhershko@gmail.com [mailto:itamar.synhershko@gmail.com]
> En nombre de Itamar Syn-Hershko Enviado el: viernes, 16 de noviembre 
> de 2012 10:34
> Para: dev@lucenenet.apache.org
> Asunto: Re: Order by distance on Spatial Searches (porting from
> Lucene4
> Java)
>
> 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 < 
> albert.clemente@anuntis.com> 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=
> > as
> > c 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
> >
> >
> >
> >
> >
> >
> >
> >
>
>