Пример #1
0
        public async Task <Response> Search(Search.Query query)
        {
            var cacheKey     = query.ToString();
            var redisAmadeus = await _cache.GetAsync(cacheKey);

            string serializedAmadeus = "";
            var    amadeusData       = new Response();

            if (redisAmadeus != null)
            {
                serializedAmadeus = Encoding.UTF8.GetString(redisAmadeus);
                amadeusData       = JsonConvert.DeserializeObject <Response>(serializedAmadeus);
            }
            else
            {
                amadeusData = await _amadeus.Search(query);

                serializedAmadeus = JsonConvert.SerializeObject(amadeusData);
                var encoded = Encoding.UTF8.GetBytes(serializedAmadeus);

                var options = new DistributedCacheEntryOptions()
                              .SetAbsoluteExpiration(DateTime.Now.AddMinutes(10))
                              .SetSlidingExpiration(TimeSpan.FromMinutes(2));

                await _cache.SetAsync(cacheKey, encoded, options);
            }

            return(amadeusData);
        }
Пример #2
0
        public async Task <Response> Search(Search.Query query)
        {
            // var url = "https://test.api.amadeus.com/v2/shopping/hotel-offers";
            var url     = getQueryParams(query);
            var request = new HttpRequestMessage(HttpMethod.Get,
                                                 // "https://test.api.amadeus.com/v2/shopping/hotel-offers?cityCode=ZAG&checkInDate=2021-04-22&checkOutDate=2021-04-29&roomQuantity=1&adults=1&radius=100&radiusUnit=KM&paymentPolicy=NONE&includeClosed=false&bestRateOnly=true&view=FULL&sort=NONE");
                                                 url);

            request.Headers.Add("Authorization", "Bearer OLB7JT9SOLVyAn26W6KWcVQluyVL");

            // var params = getQueryParams(query);

            // request.Content = new FormUrlEncodedContent(params);

            var b = request.ToString();

            var client = _clientFactory.CreateClient();

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            var resultJson = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <Response>(resultJson);

            return(result);
        }
Пример #3
0
        public void DoTest()
        {
            if (verbose)
            {
                Console.WriteLine("");
                Console.WriteLine("Query: " + queryText);
            }

            SrndQuery lq = Parser.QueryParser.Parse(queryText);

            /* if (verbose) System.out.println("Srnd: " + lq.toString()); */

            Search.Query query = lq.MakeLuceneQueryField(fieldName, qf);
            /* if (verbose) System.out.println("Lucene: " + query.toString()); */

            TestCollector tc = new TestCollector(this);

            using (IndexReader reader = DirectoryReader.Open(dBase.Db))
            {
                IndexSearcher searcher = new IndexSearcher(reader);

                searcher.Search(query, tc);
            }
            tc.CheckNrHits();
        }
Пример #4
0
 public virtual void AddSpanQueries(SpanNearClauseFactory sncf)
 {
     Search.Query snq = GetSpanNearQuery(sncf.IndexReader,
                                         sncf.FieldName,
                                         Weight,
                                         sncf.BasicQueryFactory);
     sncf.AddSpanQuery(snq);
 }
Пример #5
0
 public virtual Search.Query MakeLuceneQueryField(string fieldName, BasicQueryFactory qf)
 {
     Search.Query q = MakeLuceneQueryFieldNoBoost(fieldName, qf);
     if (IsWeighted)
     {
         q.Boost = (Weight * q.Boost); /* weight may be at any level in a SrndQuery */
     }
     return(q);
 }
Пример #6
0
        private string getQueryParams(Search.Query query)
        {
            var url     = "https://test.api.amadeus.com/v2/shopping/hotel-offers";
            var builder = new UriBuilder(url);

            var queryUrl = HttpUtility.ParseQueryString(builder.Query);

            queryUrl["cityCode"] = query.CityName;

            if (query.CheckInDate != null)
            {
                queryUrl["checkInDate"] = query.CheckInDate;
            }

            if (query.CheckOutDate != null)
            {
                queryUrl["checkOutDate"] = query.CheckOutDate;
            }

            if (query.RoomQuantity != null)
            {
                queryUrl["roomQuantity"] = query.RoomQuantity.ToString();
            }

            if (query.Adults != null)
            {
                queryUrl["adults"] = query.Adults.ToString();
            }

            if (query.Radius != null)
            {
                queryUrl["radius"] = query.Radius.ToString();
            }

            queryUrl["radiusUnit"]    = "KM";
            queryUrl["bestRateOnly"]  = "true";
            queryUrl["includeClosed"] = "true";


            builder.Query = queryUrl.ToString();

            return(builder.ToString());

            // TODO
            // return new Dictionary<string, string>
            // {
            //     { "cityCode", query.CityName },
            //     { "checkInDate", query.CheckInDate },
            //     { "checkOutDate", query.CheckOutDate },
            //     { "roomQuantity", query.RoomQuantity.ToString() },
            //     { "adults", query.Adults.ToString() },
            //     { "radius", query.Radius.ToString() }
            // };
        }
Пример #7
0
 public virtual void AddSpanQuery(Search.Query q)
 {
     if (q == SrndQuery.TheEmptyLcnQuery)
     {
         return;
     }
     if (!(q is SpanQuery))
     {
         throw AssertionError.Create("Expected SpanQuery: " + q.ToString(FieldName));
     }
     AddSpanQueryWeighted((SpanQuery)q, q.Boost);
 }
Пример #8
0
 public virtual void AddSpanQuery(Search.Query q)
 {
     if (q == SrndQuery.TheEmptyLcnQuery)
     {
         return;
     }
     if (!(q is SpanQuery))
     {
         throw new InvalidOperationException("Expected SpanQuery: " + q.ToString(FieldName));
     }
     AddSpanQueryWeighted((SpanQuery)q, q.Boost);
 }
        public async Task <IActionResult> Search([FromQuery] Search.Query query, CancellationToken cancellationToken)
        {
            var result = await Mediator.Send(query, cancellationToken);

            if (result?.Count > 0)
            {
                return(Ok(result));
            }
            else
            {
                return(NoContent());
            }
        }
Пример #10
0
        // Make sure the documents returned by the search match the expected list
        // Copied from TestSort.java
        private void AssertMatches(IndexSearcher searcher, Search.Query query, Sort sort, string expectedResult)
        {
            ScoreDoc[]    result = searcher.Search(query, null, 1000, sort).ScoreDocs;
            StringBuilder buff   = new StringBuilder(10);
            int           n      = result.Length;

            for (int i = 0; i < n; ++i)
            {
                Document         doc = searcher.Doc(result[i].Doc);
                IndexableField[] v   = doc.GetFields("tracer");
                for (int j = 0; j < v.Length; ++j)
                {
                    buff.Append(v[j].StringValue);
                }
            }
            Assert.AreEqual(expectedResult, buff.ToString());
        }
Пример #11
0
        public Search.Model Handle(Search.Query query)
        {
            var results = new Search.Model();

            // Just some test data to prove this works, if you try to create an account with "*****@*****.**" you'll get a validation error...
            if (query.Email == "*****@*****.**")
            {
                results.Accounts = new[] { new Search.Model.SearchResult {
                                               Created = DateTime.Now, Id = 1
                                           } };
            }
            else
            {
                results.Accounts = Enumerable.Empty <Search.Model.SearchResult>();
            }

            return(results);
        }
Пример #12
0
        public override Search.Query MakeLuceneQueryFieldNoBoost(string fieldName, BasicQueryFactory qf)
        {
            var          luceneSubQueries = MakeLuceneSubQueriesField(fieldName, qf);
            BooleanQuery bq = new BooleanQuery
            {
                { luceneSubQueries.Count > 0 ? luceneSubQueries[0] : null, Occur.MUST }
            };

            // LUCENENET: SubList() is slow, so we do an array copy operation instead
            var luceneSubQueriesArray = new Search.Query[luceneSubQueries.Count - 1];

            for (int i = 1, j = 0; i < luceneSubQueries.Count; i++, j++)
            {
                luceneSubQueriesArray[j] = luceneSubQueries[i];
            }

            SrndBooleanQuery.AddQueriesToBoolean(bq,
                                                 // FIXME: do not allow weights on prohibited subqueries.
                                                 luceneSubQueriesArray,
                                                 // later subqueries: not required, prohibited
                                                 Occur.MUST_NOT);
            return(bq);
        }
Пример #13
0
 public Task <Domain.CardEnvelope> SelectByCardNumber([FromBody] Search.Query query, CancellationToken cancellationToken)
 {
     return(_mediator.Send(query, cancellationToken));
 }
 public Task <AuditEnvelope> Search([FromBody] Search.Query query, CancellationToken cancellationToken)
 {
     return(_mediator.Send(query, cancellationToken));
 }
Пример #15
0
        public async Task <IActionResult> Find([FromQuery] Search.Query query)
        {
            var post = await _mediator.Send(query);

            return(Ok(post));
        }
 // Search
 public async Task <ActionResult <Search.Model> > Search([FromQuery] Search.Query query)
 {
     return(Ok(_fakeSearch.Handle(query)));
 }
 public async Task <ActionResult <FilteredSearchDTO> > Filter([FromQuery] Search.Query query)
 {
     return(await mediator.Send(new Search.Query {
         AdvertiseId = query.AdvertiseId, Category = query.Category
     }));
 }
Пример #18
0
 public async Task <IActionResult> GetHotelSearch([FromBody] Search.Query query)
 {
     return(HandleResult(await Mediator.Send(query)));
 }
Пример #19
0
 public override void Add(Search.Query query, Occur occur)
 {
     throw new NotSupportedException();
 }