public async Task <ActionResult> SearchAsync(string searchText = "") { if (string.IsNullOrWhiteSpace(searchText)) { searchText = "*"; } var results = azureSearch.Search(searchText); var items = new List <BlogItemViewModel>(); if (results != null) { foreach (var p in results.Results) { var fields = p.Document.ToArray(); var blogpost = new BlogPostViewModel() { Title = fields[1].Value.ToString(), CreatedDate = fields[5].Value.ToString(), Author = fields[2].Value.ToString(), Post = fields[4].Value.ToString(), Tags = fields[3].Value.ToString() }; items.Add(new BlogItemViewModel() { Id = fields[0].Value.ToString(), Post = blogpost }); } } return(View(items)); }
private IList <SearchResult <Book> > GetCachedBooks(string query) { IList <SearchResult <Book> > books; IDatabase cache = redisConnection.GetDatabase(); RedisValue serializedBooks = cache.StringGet("books|" + query); if (!serializedBooks.IsNullOrEmpty) { books = JsonConvert.DeserializeObject <IList <SearchResult <Book> > >(serializedBooks); } else { books = azureSearch.Search(query); cache.StringSetAsync("books|" + query, JsonConvert.SerializeObject(books), TimeSpan.FromSeconds(30)); } return(books); }