public async Task<dynamic> SearchAsync(string query, string scope, string fields, int count = 10, int start = 0) { string url = _baseUrl + "/search/query?q=" + HttpUtility.UrlEncode(query) + "&count=" + count + "&start" + start; if (!string.IsNullOrEmpty(scope)) { url += "&scope=" + scope; } if (!string.IsNullOrEmpty(fields)) { url += "&fields=" + fields; } return await GetAsync(url); }
public async Task<ActionResult> Search(SearchModel model) { PIWebAPIClient client = new PIWebAPIClient("https://myserver/piwebapi"); string query = model.Option.Equals("all") ? model.Query : model.Option + ":" + model.Query; int count = model.Count.HasValue ? (int)model.Count : 10; try { dynamic result = await client.SearchAsync(query, null, "name;itemtype;webid", count); List<SearchResult> searchResults = new List<SearchResult>(); for (int i = 0; i < result.Items.Count; i++) { SearchResult searchResult = new SearchResult(); searchResult.Name = result.Items[i].Name.Value; searchResult.ItemType = result.Items[i].ItemType.Value; searchResult.WebId = result.Items[i].WebID.Value; searchResults.Add(searchResult); } return View(searchResults); } catch (Exception) { return View("Error"); throw; } finally { client.Dispose(); } }