private async Task<IEnumerable<AssetLocation>> GetNearestAssetLocations(AssetSearchRequest assetRequest) { var geoNearOptions = new BsonDocument { { "near", new BsonDocument { { "type", "Point" }, { "coordinates", new BsonArray(assetRequest.Location.Point.coordinates) }, } }, { "distanceField", "Distance" }, { "maxDistance", assetRequest.Radius }, { "limit" , assetRequest.Limit }, { "spherical" , true } }; var pipeline = new List<BsonDocument>(); pipeline.Add(new BsonDocument { { "$geoNear", geoNearOptions } }); var result = new List<AssetLocationWithDistance>(); using (var cursor = await _dbContext.AssetLocations.AggregateAsync<BsonDocument>(pipeline)) { while (await cursor.MoveNextAsync()) { result.AddRange(cursor.Current.Select(x => BsonSerializer.Deserialize<AssetLocationWithDistance>(x))); } } return result; }
private async Task <IEnumerable <AssetLocation> > GetNearestAssetLocations(AssetSearchRequest assetRequest) { var geoNearOptions = new BsonDocument { { "near", new BsonDocument { { "type", "Point" }, { "coordinates", new BsonArray(assetRequest.Location.Point.coordinates) }, } }, { "distanceField", "Distance" }, { "maxDistance", assetRequest.Radius }, { "limit", assetRequest.Limit }, { "spherical", true } }; var pipeline = new List <BsonDocument>(); pipeline.Add(new BsonDocument { { "$geoNear", geoNearOptions } }); var result = new List <AssetLocationWithDistance>(); using (var cursor = await _dbContext.AssetLocations.AggregateAsync <BsonDocument>(pipeline)) { while (await cursor.MoveNextAsync()) { result.AddRange(cursor.Current.Select(x => BsonSerializer.Deserialize <AssetLocationWithDistance>(x))); } } return(result); }
public async Task<IEnumerable<AssetWithLocationModel>> FindEligibleAssets(AssetSearchRequest assetRequest) { if (assetRequest.Location.Point == null) throw new NotImplementedException("Blank point with address is not supported yet"); if (assetRequest.Strategy == SearchStrategy.DEEP) throw new NotImplementedException("Deep search is not implemented yet"); var nearestAssets = await GetNearestAssetLocations(assetRequest); var result = await nearestAssets.Populate(x => x.Asset_Id, _dbContext.Assets); return result.Select(x => new AssetWithLocationModel(x.TDoc, x.FDoc)); }
public async Task<IHttpActionResult> Search( double lat, double lon, string address, double? radius, int limit = AppConstants.DefaultAssetSearchLimit, SearchStrategy strategy = SearchStrategy.QUICK) { var request = new AssetSearchRequest() { Location = new DefaultAddress(address, new Data.Model.GeoJson.Point(new double[] { lon, lat }.ToList())), Limit = limit, Radius = radius, Strategy = strategy }; var result = await provider.FindEligibleAssets(request); return Ok(result); }
public async Task <IHttpActionResult> Search( double lat, double lon, string address, double?radius, int limit = AppConstants.DefaultAssetSearchLimit, SearchStrategy strategy = SearchStrategy.QUICK) { var request = new AssetSearchRequest() { Location = new DefaultAddress(address, new Data.Model.GeoJson.Point(new double[] { lon, lat }.ToList())), Limit = limit, Radius = radius, Strategy = strategy }; var result = await provider.FindEligibleAssets(request); return(Ok(result)); }
public async Task <IEnumerable <AssetWithLocationModel> > FindEligibleAssets(AssetSearchRequest assetRequest) { if (assetRequest.Location.Point == null) { logger.Error("assetRequest.Location.Point is null"); throw new NotImplementedException("Blank point with address is not supported yet"); } if (assetRequest.Strategy == SearchStrategy.DEEP) { logger.Error("Deep search is not implemented yet"); throw new NotImplementedException("Deep search is not implemented yet"); } var nearestAssets = await GetNearestAssetLocations(assetRequest); var result = await nearestAssets.Populate(x => x.Asset_Id, _dbContext.Assets); return(result.Select(x => new AssetWithLocationModel(x.TDoc, x.FDoc))); }