public static async Task <AzSearchResultModel <T> > GetDocListAsync <T>(AzSearchModel azSearch) where T : IAzResutValueModel { LOGGER.Info("Calling Azure Search API started "); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json"); client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); client.DefaultRequestHeaders.TryAddWithoutValidation("api-key", APIKey); string apirURL = ""; if (typeof(T) == typeof(DocumentModel)) { apirURL = BaseURL + docIndex; } else { apirURL = BaseURL + videoIndex; } LOGGER.Info("Calling Azure Search API parameters apirurl" + apirURL + " parameters " + Dump(azSearch)); HttpResponseMessage response = await client.PostAsJsonAsync(apirURL, azSearch); LOGGER.Info("Response from Azure Search API parameters apirurl" + apirURL + " parameters " + Dump(azSearch) + " is " + response.StatusCode); response.EnsureSuccessStatusCode(); var results = await response.Content.ReadAsAsync <AzSearchResultModel <T> >(); LOGGER.Info("Calling Azure Search API Completed successfully "); return(results); }
public async Task <ActionResult> Search(SearchDocModel searchmodel) { AzSearchModel azSearchModel = new AzSearchModel { search = searchmodel.search, skip = searchmodel.pageNo * pageSize, top = pageSize }; var items = await SearchAPI.GetDocListAsync(azSearchModel); ViewData["pageNo"] = searchmodel.pageNo; ViewData["IsSearchQuery"] = (searchmodel.search == null) ? string.Empty : searchmodel.search; ViewData["pageSize"] = pageSize; ViewData["totalRemainingPageSize"] = (int)Math.Ceiling((double)items.odatacount / pageSize) - searchmodel.pageNo; return(View(items.value)); }
public static async Task <RootObject> GetDocListAsync(AzSearchModel azSearch) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json"); client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); client.DefaultRequestHeaders.TryAddWithoutValidation("api-key", "C52E071F066CAE05B3941D94DAAE5AF5"); var jsonstring = JsonConvert.SerializeObject(azSearch); var content = new StringContent(jsonstring, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("https://localhacksearch.search.windows.net/indexes/localhack-tweet-index/docs/search?api-version=2019-05-06", content); response.EnsureSuccessStatusCode(); var results = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <RootObject>(results)); }
public async Task <ActionResult> Search(string search, int pageNo = 0, VideoType videoType = VideoType.Resume) { ClaimsPrincipal cp = ClaimsPrincipal.Current; string email = cp.Identity.Name.ToString(); LOGGER.Info("Search video link called by " + email + "parameters are " + search + "page number " + pageNo); AzSearchModel azSearchModel = new AzSearchModel { search = search, skip = pageNo * pageSize, top = pageSize }; var items = await GetAzureSearchResults.GetDocListAsync <VideoModel>(azSearchModel); ViewData["VideopageNo"] = pageNo; ViewData["VideopageSize"] = pageSize; ViewData["VideototalRemainingPageSize"] = (int)Math.Ceiling((double)items.odatacount / pageSize) - pageNo; LOGGER.Info("Search video link called by " + email + "parameters are " + search + "page number " + pageNo + "completed sucessfully"); return(View(items.value)); }