public async Task<ActionResult> RefreshSearchIndex()
 {
     var azureIndexer = new BlogPostSearchIndex(Config.AzureSearchService, Config.AzureSearchApiKey);
     using (var blogPostRepo = new BlogPostRepo())
     {
         var blogPostsToIndex = blogPostRepo.PublishedPosts.Select(x => new IndexBlogPost { BlogPostBody = x.Body, Id = x.UrlSlug }).ToArray();
         await azureIndexer.AddToIndex(blogPostsToIndex);
     }
     return RedirectToRoute("Front");
 }
 public async Task SyncAzureIndex(IEnumerable<BlogPost> newOrUpdates, IEnumerable<string> deletedPostSlugs)
 {
     var azureIndexer = new BlogPostSearchIndex(Config.AzureSearchService, Config.AzureSearchApiKey);
     await azureIndexer.AddToIndex(newOrUpdates.Select(x => new IndexBlogPost { Id = x.UrlSlug, BlogPostBody = x.Body }).ToArray());
     await azureIndexer.RemoveFromIndex(deletedPostSlugs.ToArray());
 }
        public async Task<ActionResult> SearchBlogPosts(string keywords)
        {
            keywords = keywords.RemoveSlugSeparators();
            ViewBag.SearchKeywords = keywords;
            var matchingPosts = new List<BlogPost>();
            var azureIndexer = new BlogPostSearchIndex(Config.AzureSearchService, Config.AzureSearchApiKey);

            using (var repo = new BlogPostRepo())
            {
                var results = await azureIndexer.SearchIndex(keywords);
                foreach (var result in results.OrderByDescending(x => x.Score))
                {
                    matchingPosts.Add(repo.GetPost(result.Document.Id));
                }
            }
            return View("SearchResults", new Search_vm { SearchKeywords = keywords, MatchingBlogPosts = matchingPosts });
        }