public IHttpActionResult GetPinsByAddress(PinSearchQueryParams queryParams) { try { AwsBoundingBox awsBoundingBox = null; Boolean areAllBoundingBoxParamsPresent = _finderService.areAllBoundingBoxParamsPresent(queryParams.BoundingBox); if (areAllBoundingBoxParamsPresent) { awsBoundingBox = _awsCloudsearchService.BuildBoundingBox(queryParams.BoundingBox); } var originCoords = _finderService.GetMapCenterForResults(queryParams.UserLocationSearchString, queryParams.CenterGeoCoords, queryParams.FinderType); var pinsInRadius = _finderService.GetPinsInBoundingBox(originCoords, queryParams.UserKeywordSearchString, awsBoundingBox, queryParams.FinderType, queryParams.ContactId, queryParams.UserFilterString); pinsInRadius = _finderService.RandomizeLatLongForNonSitePins(pinsInRadius); var result = new PinSearchResultsDto(new GeoCoordinates(originCoords.Latitude, originCoords.Longitude), pinsInRadius); return(Ok(result)); } catch (InvalidAddressException ex) { var apiError = new ApiErrorDto("Invalid Address", ex, HttpStatusCode.PreconditionFailed); throw new HttpResponseException(apiError.HttpResponseMessage); } catch (Exception ex) { var apiError = new ApiErrorDto("Get Pin By Address Failed", ex); throw new HttpResponseException(apiError.HttpResponseMessage); } }
public AwsBoundingBox BuildBoundingBox(MapBoundingBox mapBox) { var awsMapBoundingBox = new AwsBoundingBox { UpperLeftCoordinates = new GeoCoordinates(mapBox.UpperLeftLat, mapBox.UpperLeftLng), BottomRightCoordinates = new GeoCoordinates(mapBox.BottomRightLat, mapBox.BottomRightLng) }; return(awsMapBoundingBox); }
public SearchResponse SearchConnectAwsCloudsearch(string querystring, string returnFields, int returnSize = 10000, GeoCoordinate originCoords = null, AwsBoundingBox boundingBox = null) { var cloudSearch = new AmazonCloudSearchDomainClient(AwsAccessKeyId, AwsSecretAccessKey, AmazonSearchUrl); var searchRequest = new SearchRequest { Query = querystring, QueryParser = QueryParser.Structured, Size = returnSize, Return = returnFields + ",_score" }; if (boundingBox != null) { searchRequest.FilterQuery = $"latlong:['{boundingBox.UpperLeftCoordinates.Lat},{boundingBox.UpperLeftCoordinates.Lng}','{boundingBox.BottomRightCoordinates.Lat},{boundingBox.BottomRightCoordinates.Lng}']"; } if (originCoords != null) { searchRequest.Expr = $"{{'distance':'haversin({originCoords.Latitude},{originCoords.Longitude},latlong.latitude,latlong.longitude)'}}"; // use to sort by proximity searchRequest.Sort = "distance asc"; searchRequest.Return += ",distance"; } var response = cloudSearch.Search(searchRequest); return(response); }
public void ShouldReturnAListOfPinsWhenSearching() { const string address = "123 Main Street, Walton, KY"; var originCoords = new GeoCoordinate() { Latitude = 39.2844738, Longitude = -84.319614 }; var searchresults = new SearchResponse(); searchresults.Hits = new Hits(); searchresults.Hits.Found = 1; searchresults.Hits.Start = 0; searchresults.Hits.Hit = new List <Hit>(); var hit = new Hit(); var fields = new Dictionary <string, List <string> >(); fields.Add("city", new List <string>() { "Union" }); fields.Add("zip", new List <string>() { "41091" }); fields.Add("firstname", new List <string>() { "Robert" }); fields.Add("lastname", new List <string>() { "Smith" }); fields.Add("latlong", new List <string>() { "38.94526,-84.661275" }); hit.Fields = fields; searchresults.Hits.Hit.Add(hit); _awsCloudsearchService.Setup( mocked => mocked.SearchConnectAwsCloudsearch(It.IsAny <string>(), "_all_fields", It.IsAny <int>(), It.IsAny <GeoCoordinate>(), It.IsAny <AwsBoundingBox>())) .Returns(searchresults); _mpGroupToolService.Setup(m => m.SearchGroups(It.IsAny <int[]>(), null, It.IsAny <string>(), null, originCoords)).Returns(new List <GroupDTO>()); _mpFinderRepository.Setup(mocked => mocked.GetPinsInRadius(originCoords)).Returns(new List <SpPinDto>()); _addressGeocodingService.Setup(mocked => mocked.GetGeoCoordinates(address)).Returns(originCoords); _addressProximityService.Setup(mocked => mocked.GetProximity(address, new List <AddressDTO>(), originCoords)).Returns(new List <decimal?>()); _addressProximityService.Setup(mocked => mocked.GetProximity(address, new List <string>(), originCoords)).Returns(new List <decimal?>()); var boundingBox = new AwsBoundingBox { UpperLeftCoordinates = new GeoCoordinates(61.21, -149.9), BottomRightCoordinates = new GeoCoordinates(21.52, -77.78) }; List <PinDto> pins = _fixture.GetPinsInBoundingBox(originCoords, address, boundingBox, "CONNECT", 0, "filterstring"); Assert.IsInstanceOf <List <PinDto> >(pins); }