Пример #1
0
        public async Task <List <Location> > GetAllLocations()
        {
            var client   = _elasticSearchClient.CreateElasticClient(_elasticsearchConfig.Value.Url);
            var response = await client.SearchAsync <Location>(loc => loc
                                                               .Index(_elasticsearchConfig.Value.LocationIndex)
                                                               .Size(150)
                                                               .Query(q => q.MatchAll()));

            return(response.Documents?.Select(loc => new Location {
                Region = loc.Region,
                Country = loc.Country
            }).ToList());
        }
Пример #2
0
        public async Task <List <Airline> > GetAllAirlines()
        {
            var client   = _elasticSearchClient.CreateElasticClient(_elasticsearchConfig.Value.Url);
            var response = await client.SearchAsync <Airline>(loc => loc
                                                              .Index(_elasticsearchConfig.Value.AirlineIndex)
                                                              .Size(100)
                                                              .Query(q => q.MatchAll()));

            return(response.Documents?.Select(air => new Airline
            {
                Name = air.Name,
                Code = air.Code,
                Country = air.Country
            }).ToList());
        }
        public async Task <List <Hotel> > GetAllHotels()
        {
            var client   = _elasticSearchClient.CreateElasticClient(_elasticsearchConfig.Value.Url);
            var response = await client.SearchAsync <Hotel>(loc => loc
                                                            .Index(_elasticsearchConfig.Value.HotelIndex)
                                                            .Size(2000)
                                                            .Query(q => q.MatchAll()));

            return(response.Documents?.Select(hot => new Hotel
            {
                Id = hot.Id,
                Name = hot.Name,
                Code = hot.Code,
                Country = hot.Country
            }).ToList());
        }
        public async Task <List <HotelAvailability> > SearchHotelAvailability(SearchHotelAvailabilityQuery hotelAvailabilityRequest)
        {
            var client   = _elasticSearchClient.CreateElasticClient(_elasticsearchConfig.Value.Url);
            var response = await client.SearchAsync <HotelAvailability>(har =>
                                                                        har.Index(_elasticsearchConfig.Value.HotelAvailabilityIndex)
                                                                        .Size(60)
                                                                        .Query(q => q
                                                                               .Bool(bq => bq
                                                                                     .Must(
                                                                                         fq => fq.Match(m => m.Field(f => f.Available).Query("true")),
                                                                                         fq => fq.Range(r => r.Field(f => f.Infants).GreaterThanOrEquals(hotelAvailabilityRequest.Infants)),
                                                                                         fq => fq.Range(r => r.Field(f => f.Children).GreaterThanOrEquals(hotelAvailabilityRequest.Children)),
                                                                                         fq => fq.Range(r => r.Field(f => f.Adults).GreaterThanOrEquals(hotelAvailabilityRequest.Adults)),
                                                                                         fq => fq.Match(m => m.Field(f => f.StayDate).Query(hotelAvailabilityRequest.StayDate.ToString("yyyy'-'MM'-'dd"))),
                                                                                         fq => fq.MatchPhrase(mp => mp.Field(f => f.Region).Query(hotelAvailabilityRequest.Region)),
                                                                                         fq => fq.MatchPhrase(mp => mp.Field(f => f.Country).Query(hotelAvailabilityRequest.Country)),
                                                                                         fq => fq.MatchPhrase(mp => mp.Field(f => f.HotelName).Query(hotelAvailabilityRequest.HotelName)),
                                                                                         fq => fq.Range(r => r.Field(f => f.NetPrice).LessThanOrEquals(hotelAvailabilityRequest.NetPrice))
                                                                                         )
                                                                                     )
                                                                               )
                                                                        );

            return(response.Documents?.Select(d => new HotelAvailability
            {
                Adults = d.Adults,
                AirportCode = d.AirportCode,
                Children = d.Children,
                Country = d.Country,
                CurrencyCode = d.CurrencyCode,
                EndDate = d.EndDate,
                HotelId = d.HotelId,
                HotelName = d.HotelName,
                Id = d.Id,
                Infants = d.Infants,
                Meal = d.Meal,
                NetPrice = d.NetPrice,
                Region = d.Region,
                Room = d.Room,
                StayDate = d.StayDate,
                Available = d.Available
            }).ToList());
        }
        public async Task <List <FlightAvailability> > SearchFlightAvailability(SearchFlightAvailabilityQuery flightAvailabilityRequest)
        {
            var client = _elasticSearchClient.CreateElasticClient(_elasticsearchConfig.Value.Url);
            ISearchResponse <FlightAvailability> inboundResponse = null;
            var response = await client.SearchAsync <FlightAvailability>(far =>
                                                                         far.Index(_elasticsearchConfig.Value.FlightAvailabilityIndex)
                                                                         .From(0)
                                                                         .Size(6)
                                                                         .Sort(s => s
                                                                               .Ascending(f => f.Id))
                                                                         .Query(q => q
                                                                                .Bool(bq => bq
                                                                                      .Filter(
                                                                                          fq => fq.Range(r => r.Field(f => f.Seats).GreaterThanOrEquals(flightAvailabilityRequest.Seats)),
                                                                                          fq => fq.Match(m => m.Field(f => f.Scheduled).Query(flightAvailabilityRequest.Scheduled.ToString("yyyy'-'MM'-'dd"))),
                                                                                          fq => fq.MatchPhrase(mp => mp.Field(f => f.ArrivalAirportCode).Query(flightAvailabilityRequest.ArrivalAirportCode))
                                                                                          )
                                                                                      )
                                                                                )
                                                                         );

            if (flightAvailabilityRequest.RoundTrip && response.Documents.Any())
            {
                var airlines = String.Join(",", response.Documents.Select(d => d.AirlineIata.ToLower()));
                inboundResponse = await client.SearchAsync <FlightAvailability>(far =>
                                                                                far.Index(_elasticsearchConfig.Value.FlightAvailabilityIndex)
                                                                                .From(0)
                                                                                .Size(6)
                                                                                .Sort(s => s
                                                                                      .Ascending(f => f.Id))
                                                                                .Query(q => q
                                                                                       .Bool(bq => bq
                                                                                             .Filter(
                                                                                                 fq => fq.Range(r => r.Field(f => f.Seats).GreaterThanOrEquals(flightAvailabilityRequest.Seats)),
                                                                                                 fq => fq.Match(m => m.Field(f => f.Scheduled).Query(flightAvailabilityRequest.Departure.ToString("yyyy'-'MM'-'dd"))),
                                                                                                 fq => fq.MatchPhrase(mp => mp.Field(f => f.DepartureAirportCode).Query(flightAvailabilityRequest.ArrivalAirportCode))
                                                                                                 ).Should(s => s.Terms(t => t.Field(f => f.AirlineIata).Terms(airlines)))
                                                                                             )
                                                                                       )
                                                                                );
            }

            var availability = new List <FlightAvailability>();

            if (response?.Documents != null)
            {
                availability = response.Documents?.Select(d => new FlightAvailability
                {
                    Id                       = d.Id,
                    Scheduled                = d.Scheduled,
                    ScheduledTimeDate        = d.ScheduledTimeDate,
                    Arrival                  = d.Arrival,
                    ArrivalTimeDate          = d.ArrivalTimeDate,
                    FlightIdentifier         = d.FlightIdentifier,
                    DepartureAirportCode     = d.DepartureAirportCode,
                    DepartureAirport         = d.DepartureAirport,
                    DepartureAirportTimezone = d.DepartureAirportTimezone,
                    ArrivalAirportCode       = d.ArrivalAirportCode,
                    ArrivalAirport           = d.ArrivalAirport,
                    ArrivalAirportTimezone   = d.ArrivalAirportTimezone,
                    AirportCity              = d.AirportCity,
                    AirportCountry           = d.AirportCountry,
                    Terminal                 = d.Terminal,
                    Seats                    = d.Seats,
                    Gate                     = d.Gate,
                    AirlineIata              = d.AirlineIata,
                    AirlineName              = d.AirlineName,
                    FlightBound              = d.FlightBound
                }).ToList();

                if (inboundResponse?.Documents != null)
                {
                    availability.AddRange(inboundResponse.Documents?.Select(d => new FlightAvailability
                    {
                        Id                       = d.Id,
                        Scheduled                = d.Scheduled,
                        ScheduledTimeDate        = d.ScheduledTimeDate,
                        Arrival                  = d.Arrival,
                        ArrivalTimeDate          = d.ArrivalTimeDate,
                        FlightIdentifier         = d.FlightIdentifier,
                        DepartureAirportCode     = d.DepartureAirportCode,
                        DepartureAirport         = d.DepartureAirport,
                        DepartureAirportTimezone = d.DepartureAirportTimezone,
                        ArrivalAirportCode       = d.ArrivalAirportCode,
                        ArrivalAirport           = d.ArrivalAirport,
                        ArrivalAirportTimezone   = d.ArrivalAirportTimezone,
                        AirportCity              = d.AirportCity,
                        AirportCountry           = d.AirportCountry,
                        Terminal                 = d.Terminal,
                        Seats                    = d.Seats,
                        Gate                     = d.Gate,
                        AirlineIata              = d.AirlineIata,
                        AirlineName              = d.AirlineName,
                        FlightBound              = d.FlightBound
                    }).ToList());
                }
            }
            return(availability);
        }