public void GetSearchResults_ShouldPassRequestToGateway_NoResultsFound() { var list = new List <Feature>(); var searchTerm = "searchTerm"; _elasticSearchGateway.Search(searchTerm, Languages.ENGLISH).Returns(list); var results = _controller.GetSearchResults(searchTerm, Languages.ENGLISH).Result; Assert.IsNotNull(results); Assert.AreEqual(list.Count, results.Count()); }
public async Task <IEnumerable <SearchResultsPointOfInterest> > GetSearchResults(string term, string language) { var coordinates = GetCoordinates(term.Trim()); if (coordinates != null) { return(new[] { ConvertFromCoordinates(term, coordinates) }); } if (term.Count(c => c == ',') == 1) { var splitted = term.Split(','); var place = splitted.Last().Trim(); term = splitted.First().Trim(); var placesFeatures = await _elasticSearchGateway.SearchPlaces(place, language); if (placesFeatures.Any()) { var envolope = placesFeatures.First().Geometry.EnvelopeInternal; var featuresWithinPlaces = await _elasticSearchGateway.SearchByLocation( new Coordinate(envolope.MaxX, envolope.MaxY), new Coordinate(envolope.MinX, envolope.MinY), term, language); return(await Task.WhenAll(featuresWithinPlaces.OfType <IFeature>().ToList().Select(f => ConvertFromFeature(f, language)))); } } var features = await _elasticSearchGateway.Search(term, language); return(await Task.WhenAll(features.OfType <IFeature>().ToList().Select(f => ConvertFromFeature(f, language)))); }
public async Task <FeatureCollection> GetSearchResults(string term, string language = null) { var coordinates = GetCoordinates(term.Trim()); if (coordinates != null) { return(GetFeatureCollectionFromCoordinates(term, coordinates)); } var fieldName = string.IsNullOrWhiteSpace(language) ? "name" : "name:" + language; if (term.Count(c => c == ',') == 1) { var splitted = term.Split(','); var place = splitted.Last().Trim(); term = splitted.First().Trim(); var placesFeatures = await _elasticSearchGateway.SearchPlaces(place, fieldName); if (placesFeatures.Any()) { var envolope = placesFeatures.First().Geometry.EnvelopeInternal; var featuresWithinPlaces = await _elasticSearchGateway.SearchByLocation( new Coordinate(envolope.MaxX, envolope.MaxY), new Coordinate(envolope.MinX, envolope.MinY), term, fieldName); return(new FeatureCollection(new Collection <IFeature>(featuresWithinPlaces.OfType <IFeature>().ToList()))); } } var features = await _elasticSearchGateway.Search(term, fieldName); return(new FeatureCollection(new Collection <IFeature>(features.OfType <IFeature>().ToList()))); }
public void GetSearchResults_ShouldPassRequestToGateway_NoResultsFound() { var list = new List <Feature>(); _elasticSearchGateway.Search("searchTerm", "name:en").Returns(list); var results = _controller.GetSearchResults("searchTerm", "en").Result; Assert.IsNotNull(results); Assert.AreEqual(list.Count, results.Features.Count); }
public async Task <FeatureCollection> GetSearchResults(string term, string language = null) { var coordinates = GetCoordinates(term.Trim()); if (coordinates != null) { return(GetFeatureCollectionFromCoordinates(term, coordinates)); } var fieldName = string.IsNullOrWhiteSpace(language) ? "name" : "name:" + language; var features = await _elasticSearchGateway.Search(term, fieldName); return(new FeatureCollection(new Collection <IFeature>(features.OfType <IFeature>().ToList()))); }