lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Itamar Syn-Hershko <ita...@code972.com>
Subject Re: Order by distance on Spatial Searches (porting from Lucene4 Java)
Date Sat, 17 Nov 2012 19:09:04 GMT
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
> >
> >
> >
> >
> >
> >
> >
> >
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message