internal IEnumerable <GroupedDetailView> GetGroupedDetailViews(SearchQuery searchQuery, int userSearchTypeId, out int totalHits, out bool more) { var searchResults = SearchController.Instance.SiteSearch(searchQuery); totalHits = searchResults.TotalHits; more = searchResults.Results.Count == searchQuery.PageSize; var groups = new List <GroupedDetailView>(); var tabGroups = new Dictionary <string, IList <SearchResult> >(); foreach (var result in searchResults.Results) { //var key = result.TabId + result.Url; var key = result.Url; if (!tabGroups.ContainsKey(key)) { tabGroups.Add(key, new List <SearchResult> { result }); } else { //when the result is a user search type, we should only show one result // and if duplicate, we should also reduce the totalHit number. if (result.SearchTypeId != userSearchTypeId || tabGroups[key].All(r => r.Url != result.Url)) { tabGroups[key].Add(result); } else { totalHits--; } } } foreach (var results in tabGroups.Values) { var group = new GroupedDetailView(); //first entry var first = results[0]; group.Title = first.Title; group.DocumentUrl = first.Url; //Find a different title for multiple entries with same url if (results.Count > 1) { if (first.TabId > 0) { var tab = TabController.Instance.GetTab(first.TabId, first.PortalId, false); if (tab != null) { group.Title = tab.TabName; } } else if (first.ModuleId > 0) { var tabTitle = GetTabTitleFromModuleId(first.ModuleId); if (!string.IsNullOrEmpty(tabTitle)) { group.Title = tabTitle; } } } else if (first.ModuleDefId > 0 && first.ModuleDefId == HtmlModuleDefitionId) //special handling for Html module { var tabTitle = GetTabTitleFromModuleId(first.ModuleId); if (!string.IsNullOrEmpty(tabTitle)) { group.Title = tabTitle; if (first.Title != "Enter Title" && first.Title != "Text/HTML") { group.Title += " > " + first.Title; } first.Title = group.Title; } } foreach (var result in results) { var detail = new DetailedView { Title = result.Title, DocumentTypeName = InternalSearchController.Instance.GetSearchDocumentTypeDisplayName(result), DocumentUrl = result.Url, Snippet = result.Snippet, DisplayModifiedTime = result.DisplayModifiedTime, Tags = result.Tags.ToList(), AuthorProfileUrl = result.AuthorUserId > 0 ? Globals.UserProfileURL(result.AuthorUserId) : string.Empty, AuthorName = result.AuthorName }; group.Results.Add(detail); } groups.Add(group); } return(groups); }
internal static IEnumerable <GroupedDetailView> GetGroupedDetailViews(SearchQuery searchQuery, int userSearchTypeId, out int totalHits, out bool more) { SearchResults searchResults = SearchController.Instance.SiteSearch(searchQuery); totalHits = searchResults.TotalHits; more = totalHits > searchQuery.PageSize * searchQuery.PageIndex; List <GroupedDetailView> groups = new List <GroupedDetailView>(); Dictionary <string, IList <DotNetNukeSearch.SearchResult> > tabGroups = new Dictionary <string, IList <DotNetNukeSearch.SearchResult> >(); foreach (DotNetNukeSearch.SearchResult result in searchResults.Results) { //var key = result.TabId + result.Url; string key = result.Url; if (!tabGroups.ContainsKey(key)) { tabGroups.Add(key, new List <DotNetNukeSearch.SearchResult> { result }); } else { //when the result is a user search type, we should only show one result // and if duplicate, we should also reduce the totalHit number. if (result.SearchTypeId != userSearchTypeId || tabGroups[key].All(r => r.Url != result.Url)) { tabGroups[key].Add(result); } else { totalHits--; } } } bool showFriendlyTitle = false; //ActiveModule == null // || !ActiveModule.ModuleSettings.ContainsKey("ShowFriendlyTitle") // || Convert.ToBoolean(ActiveModule.ModuleSettings["ShowFriendlyTitle"]); foreach (IList <DotNetNukeSearch.SearchResult> results in tabGroups.Values) { GroupedDetailView group = new GroupedDetailView(); //first entry DotNetNukeSearch.SearchResult first = results[0]; group.Title = showFriendlyTitle ? GetFriendlyTitle(first) : first.Title; group.DocumentUrl = first.Url; //Find a different title for multiple entries with same url if (results.Count > 1) { if (first.TabId > 0) { TabInfo tab = TabController.Instance.GetTab(first.TabId, first.PortalId, false); if (tab != null) { group.Title = showFriendlyTitle && !string.IsNullOrEmpty(tab.Title) ? tab.Title : tab.TabName; } } else if (first.ModuleId > 0) { string tabTitle = GetTabTitleFromModuleId(first.ModuleId); if (!string.IsNullOrEmpty(tabTitle)) { group.Title = tabTitle; } } } else if (first.ModuleDefId > 0 && first.ModuleDefId == HtmlModuleDefitionId) //special handling for Html module { string tabTitle = GetTabTitleFromModuleId(first.ModuleId); if (!string.IsNullOrEmpty(tabTitle)) { group.Title = tabTitle; if (first.Title != "Enter Title" && first.Title != "Text/HTML") { group.Title += " > " + first.Title; } first.Title = group.Title; } } foreach (DotNetNukeSearch.SearchResult result in results) { string title = showFriendlyTitle ? GetFriendlyTitle(result) : result.Title; DetailedView detail = new DetailedView { Title = title != null && title.Contains("<") ? HttpUtility.HtmlEncode(title) : title, DocumentTypeName = InternalSearchController.Instance.GetSearchDocumentTypeDisplayName(result), DocumentUrl = result.Url, Snippet = result.Snippet, Description = result.Description, DisplayModifiedTime = result.DisplayModifiedTime, Tags = result.Tags.ToList(), AuthorProfileUrl = result.AuthorUserId > 0 ? Globals.UserProfileURL(result.AuthorUserId) : string.Empty, AuthorName = result.AuthorName }; group.Results.Add(detail); } groups.Add(group); } return(groups); }