public async Task <ActionResult> SearchAsync(string searchText = "") { if (string.IsNullOrWhiteSpace(searchText)) { searchText = "*"; } var searchResults = _postSearch.Search(searchText); var userPosts = new List <UserPost>(); if (searchResults != null) { foreach (var p in searchResults.Results) { var fields = p.Document.ToArray(); var userPost = new UserPost() { PostId = fields[0].Value.ToString(), Heading = fields[1].Value.ToString(), Content = fields[2].Value.ToString(), Tag = fields[3].Value.ToString(), CreatedOn = fields[4].Value.ToString(), Author = fields[5].Value.ToString() }; userPosts.Add(userPost); } } return(View(userPosts)); }