public SuggestionQueryResult Map(IEnumerable <GeoDataEntry> results, SuggestionQuery suggestionQuery, ILinkBuilder linkBuilder) { if (linkBuilder == null) { throw new ArgumentNullException(nameof(linkBuilder)); } IEnumerable <Suggestion> suggestions = null; if (results?.Count() > 0) { suggestions = CertaintyRanker.Rank(results, suggestionQuery.Q, suggestionQuery.Coordinates()) .OrderByDescending(o => o.Certainty) .Take(suggestionQuery.MaxResults) .Select(c => new Suggestion() { Certainty = c.Certainty, Longitude = c.Entry.Longitude, Latitude = c.Entry.Latitude, Name = c.Entry.Name, Links = linkBuilder.BuildLinks(c.Entry) }).OrderByDescending(r => r.Certainty); } //if suggestions are null, return an empty array return(new SuggestionQueryResult() { Suggestions = suggestions ?? new Suggestion[] {} }); }
public IHttpActionResult Get([FromUri] SuggestionQuery query) { if (query == null) { throw new NullQueryStringException(); } query.Validate(); Coordinates sourceCoordinates = query.Coordinates(); IEnumerable <GeoDataEntry> results = null; try { if (sourceCoordinates == null) { results = DataProvider.Search(query?.Q, query.MaxResults); } else { results = DataProvider.SearchNear(query?.Q, new BoundingBox(sourceCoordinates, Defaults.defaultRadiusKm), query.MaxResults); } } catch (Exception ex) { AppLogger.Error("error querying hospitals", ex); throw new DataProviderException(ex); } return(Ok(ResultsMapper.Map(results, query, new LinkBuilder(this)))); }