예제 #1
0
        public IActionResult Index(string defaultOperator, string query)
        {
            List <QueryTerm> queryTerms = QueryUtils.GetQueryTerms(query);

            using (var client = new HttpClient())
            {
                query = query.Replace(CommonConstants.SEPARATOR_COMMA, CommonConstants.SEPARATOR_PLUS);

                string url = _configuration.GetSection("ElasticsearchScorecardIndexRoute").Value
                             + string.Format(CommonConstants.ROUTE_SCORECARD_SEARCH, defaultOperator, query);

                var uri = new Uri(url);

                var    result = client.GetAsync(uri).GetAwaiter().GetResult();
                string data   = result.Content.ReadAsStringAsync().GetAwaiter().GetResult();

                var elasticResponse = JsonConvert.DeserializeObject <ElasticSearchResponse>(data);

                List <Source> searchResults = new List <Source>();

                foreach (InnerHit hit in elasticResponse.Hits.Hits)
                {
                    searchResults.Add(hit.Source);
                }

                RegisterSearch(queryTerms);

                SearchModel model = new SearchModel(searchResults, queryTerms, defaultOperator);

                return(View(model));
            }
        }