예제 #1
0
        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());
        }
예제 #2
0
        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))));
        }
예제 #3
0
        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())));
        }
예제 #4
0
        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);
        }
예제 #5
0
        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())));
        }