public SearchIndexViewModel(string query, SearchBy searchBy = SearchBy.FullText | SearchBy.Tag, SearchWhat searchWhat = SearchWhat.Groups | SearchWhat.Content) { if (!string.IsNullOrWhiteSpace(query)) { Query = query; if (searchBy.HasFlag(SearchBy.FullText)) { if (searchWhat.HasFlag(SearchWhat.Content)) { var comments = DataService.PerThread.GetCommentsByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)); var posts = DataService.PerThread.GetPostsByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)); var petitions = DataService.PerThread.GetPetitionsByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)); var polls = DataService.PerThread.GetPollsByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)); var surveys = DataService.PerThread.GetSurveysByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)); Content = comments.Union(posts.Union(petitions.Union(polls.Union(surveys)))).ToList(); } if (searchWhat.HasFlag(SearchWhat.Groups)) { Groups = DataService.PerThread.GetGroupsByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)).ToList(); } } if (searchBy.HasFlag(SearchBy.Tag)) { var tags = DataService.PerThread.TagSet.Where(x => x.Title.Contains(query) || query.Contains(x.Title)).ToList(); if (searchWhat.HasFlag(SearchWhat.Content)) { IEnumerable <SearchIndex_ResultViewModel> tagedContent = new List <SearchIndex_ResultViewModel>(); foreach (var c in tags.Where(x => x.Contents.Count != 0).Select(x => x.Contents)) { tagedContent = tagedContent.Union(c.Select(x => new SearchIndex_ResultViewModel(x)).ToList()); } Content = Content.Union(tagedContent).ToList(); } if (searchWhat.HasFlag(SearchWhat.Groups)) { var tagedGroups = tags.Where(x => x.GroupId.HasValue).Select(x => new SearchIndex_ResultViewModel(x.Group)).ToList(); Groups = Groups.Union(tagedGroups).ToList(); } } } }
public SearchIndexViewModel(string query, SearchBy searchBy = SearchBy.FullText | SearchBy.Tag, SearchWhat searchWhat = SearchWhat.Groups | SearchWhat.Content) { if (!string.IsNullOrWhiteSpace(query)) { Query = query; if (searchBy.HasFlag(SearchBy.FullText)) { if (searchWhat.HasFlag(SearchWhat.Content)) { var comments = DataService.PerThread.GetCommentsByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)); var posts = DataService.PerThread.GetPostsByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)); var petitions = DataService.PerThread.GetPetitionsByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)); var polls = DataService.PerThread.GetPollsByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)); var surveys = DataService.PerThread.GetSurveysByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)); Content = comments.Union(posts.Union(petitions.Union(polls.Union(surveys)))).ToList(); } if (searchWhat.HasFlag(SearchWhat.Groups)) Groups = DataService.PerThread.GetGroupsByFullText(query, 100).Select(x => new SearchIndex_ResultViewModel(x)).ToList(); } if (searchBy.HasFlag(SearchBy.Tag)) { var tags = DataService.PerThread.TagSet.Where(x => x.Title.Contains(query) || query.Contains(x.Title)).ToList(); if (searchWhat.HasFlag(SearchWhat.Content)) { IEnumerable<SearchIndex_ResultViewModel> tagedContent = new List<SearchIndex_ResultViewModel>(); foreach (var c in tags.Where(x => x.Contents.Count != 0).Select(x => x.Contents)) tagedContent = tagedContent.Union(c.Select(x => new SearchIndex_ResultViewModel(x)).ToList()); Content = Content.Union(tagedContent).ToList(); } if (searchWhat.HasFlag(SearchWhat.Groups)) { var tagedGroups = tags.Where(x => x.GroupId.HasValue).Select(x => new SearchIndex_ResultViewModel(x.Group)).ToList(); Groups = Groups.Union(tagedGroups).ToList(); } } } }