public async Task <IEnumerable <NewCreativeModel> > SearchCreatives(SearchViewModel model) { var results = new List <Creative>(); var writer = new CreativeWriter(dataFolder); var searcher = new CreativeSearcher(dataFolder); writer.AddUpdateCreativesToIndex(db.Creatives.GetAll().ToList()); var searchResults = GetSearchResults(model, searcher); foreach (var searchResult in searchResults) { foreach (var item in searchResult.SearchResultItems) { var creative = await db.Creatives.Get(item.Id); if (creative != null && !results.Contains(creative)) { results.Add(creative); } } } return(InitCreativesModel(results)); }
private IEnumerable <SearchResult> GetSearchResults(SearchViewModel model, CreativeSearcher searcher) { var searchResults = new List <SearchResult>(); if (model.ChapterText && model.CommentAuthor && model.CommentText && model.CreativeAuthor && model.CreativeDescription && model.CreativeName && model.TagName && model.ChapterName) { searchResults.Add(searcher.SearchCreative(model.Pattern, string.Empty)); return(searchResults); } if (model.ChapterName) { searchResults.Add(searcher.SearchCreative(model.Pattern, "ChapterNames")); } if (model.ChapterText) { searchResults.Add(searcher.SearchCreative(model.Pattern, "ChapterBodies")); } if (model.CommentAuthor) { searchResults.Add(searcher.SearchCreative(model.Pattern, "CommentsUserName")); } if (model.CommentText) { searchResults.Add(searcher.SearchCreative(model.Pattern, "Comments")); } if (model.CreativeAuthor) { searchResults.Add(searcher.SearchCreative(model.Pattern, "UserName")); } if (model.CreativeDescription) { searchResults.Add(searcher.SearchCreative(model.Pattern, "Description")); } if (model.CreativeName) { searchResults.Add(searcher.SearchCreative(model.Pattern, "Name")); } if (model.TagName) { searchResults.Add(searcher.SearchCreative(model.Pattern, "Tags")); } return(searchResults); }