Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

WithinDistanceFrom only accept integer for

Vote:
 

We have a web API that passes the distance as a float value which is used by Episerver find below the method

 

publicstatic DelegateFilterBuilder WithinDistanceFrom(this GeoLocation value, GeoLocation fromLocation, GeoDistance distance);

but the GeoLocation  and GeoDistance  only accepting integer, so any float value converted to the nearest integer kilomteres that could cause inaccurate result some time

is there any way to in Epi find to search the distance with the actual float value

 

GeoLocation

GeoDistance

WithinDistanceFrom

#265704
Oct 27, 2021 1:41
Vote:
 

GeoLocation is a double for lat/long as expected but GeoDistance is an Abstract class with the int value that seems to have 2 implementations.

// Decompiled with JetBrains decompiler
// Type: EPiServer.Find.Api.Querying.Filters.Miles
// Assembly: EPiServer.Find, Version=13.4.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7
// MVID: B8987D14-EA4E-414B-843A-06C36F6AAF0C
// Assembly location: D:\Niteco\ThinkMax\Repo\StewMac-Episerver\.packages\EPiServer.Find.13.4.1\lib\net461\EPiServer.Find.dll

namespace EPiServer.Find.Api.Querying.Filters
{
  public class Miles : GeoDistance
  {
    public Miles(int value)
      : base(value)
    {
    }

    internal override string Unit => "mi";
  }
}
// Decompiled with JetBrains decompiler
// Type: EPiServer.Find.Api.Querying.Filters.Kilometers
// Assembly: EPiServer.Find, Version=13.4.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7
// MVID: B8987D14-EA4E-414B-843A-06C36F6AAF0C
// Assembly location: D:\Niteco\ThinkMax\Repo\StewMac-Episerver\.packages\EPiServer.Find.13.4.1\lib\net461\EPiServer.Find.dll

namespace EPiServer.Find.Api.Querying.Filters
{
  public class Kilometers : GeoDistance
  {
    public Kilometers(int value)
      : base(value)
    {
    }

    internal override string Unit => "km";
  }
}

If these are not accurate enough for you I think you can create you're own classes that Inhert GeoDistance and set different Unit values. To match what Elastic can do

https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/distance-units.html 

#265715
Edited, Oct 27, 2021 13:02
Vote:
 

Thanks Scott, it might be the solution

what is the different between Kilometers & Kilometer , miles and mile? 

#265758
Oct 27, 2021 22:17
Scott Reed - Oct 28, 2021 12:21
Are you referring to the name of the classes? Not sure what the question is related to?
Vahid - Oct 29, 2021 2:20
Yes, those class names, what the different between them if I use Kilometers or Kilometer?
Scott Reed - Oct 29, 2021 8:52
where are you seeing a class name called Kilometer / Mile? Can you provide some details of what class you're referring to?
Vahid - Oct 29, 2021 9:09
hi Scott
I can see them here in GeoExtensions calss
Vote:
 
#region Assembly EPiServer.Find, Version=13.4.3.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7
namespace EPiServer.Find
{
    public static class GeoExtensions
    {
        public static GeoDistance Kilometer(this int distance);
        public static GeoDistance Kilometers(this int distance);
        public static GeoDistance Mile(this int distance);
        public static GeoDistance Miles(this int distance);
    }
}
#265878
Oct 29, 2021 9:09
Vote:
 

When you decompile them you see they are just extension methods for creating the types. Really not sure why there's 2 as they both do the same thing.

  public static class GeoExtensions
  {
    public static GeoDistance Kilometer(this int distance) => distance.Kilometers();

    public static GeoDistance Kilometers(this int distance) => (GeoDistance) new EPiServer.Find.Api.Querying.Filters.Kilometers(distance);

    public static GeoDistance Mile(this int distance) => distance.Miles();

    public static GeoDistance Miles(this int distance) => (GeoDistance) new EPiServer.Find.Api.Querying.Filters.Miles(distance);
  }

If you've not used it I'd suggest downloading https://github.com/icsharpcode/ILSpy from here or the Windows store. You can add any assemblies in and decompile to see this. Also if you're company is willing to pay the Resharper tools also have it built in with native Visual Studio integration. I use a combination of the 2 for getting to the bottom of these things.

#265880
Oct 29, 2021 9:16
Scott Reed - Oct 29, 2021 9:18
either way these are int values so if miles / kilometres isn't accurate enough you'll have to create your own versions for set metres or feet (or any of the other in the list I linked to)
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.