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 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 void GetSearchResults_WithPlaceNameThatDoNotExist_ShouldReturnRegularResults() { var place = "place"; var searchTerm = "searchTerm, " + place; var featureLocation = new Coordinate(0.5, 0.5); var featureInPlace = new Feature(new Point(featureLocation), new AttributesTable { { FeatureAttributes.NAME, "name" }, { FeatureAttributes.GEOLOCATION, new AttributesTable { { FeatureAttributes.LAT, featureLocation.Y }, { FeatureAttributes.LON, featureLocation.X } } }, { FeatureAttributes.POI_CATEGORY, Categories.HISTORIC }, { FeatureAttributes.POI_SOURCE, Sources.OSM }, { FeatureAttributes.ICON, string.Empty }, { FeatureAttributes.ICON_COLOR, "black" }, { FeatureAttributes.ID, "id" } }); featureInPlace.SetTitles(); var featuresInsidePlace = new List <Feature> { featureInPlace }; _elasticSearchGateway.SearchPlaces(place, Languages.ENGLISH).Returns(new List <Feature>()); _elasticSearchGateway.Search("searchTerm", Languages.ENGLISH).Returns(new List <Feature> { featureInPlace }); _elasticSearchGateway.GetContainers(featureLocation).Returns(new List <Feature>()); var results = _controller.GetSearchResults(searchTerm, Languages.ENGLISH).Result.ToList(); Assert.IsNotNull(results); Assert.AreEqual(featuresInsidePlace.Count, results.Count); Assert.IsFalse(results.First().DisplayName.Contains(place)); }