private IEnumerable <GroupedBasicView> GetGroupBasicViewResults(SearchQuery query) { var userSearchContentSource = new SearchContentSource { SearchTypeId = UrlSearchTypeId, SearchTypeName = UrlSearchTypeName, SearchResultClass = FakeResultControllerClass, LocalizedName = UserSearchTypeName, ModuleDefinitionId = 0 }; var results = _searchServiceController.GetGroupedBasicViews(query, userSearchContentSource, PortalId0); return(results); }
internal List <GroupedBasicView> GetGroupedBasicViews(SearchQuery query, SearchContentSource userSearchSource, int portalId) { int totalHists; var results = new List <GroupedBasicView>(); var previews = GetBasicViews(query, out totalHists); foreach (var preview in previews) { //if the document type is user, then try to add user pic into preview's custom attributes. if (userSearchSource != null && preview.DocumentTypeName == userSearchSource.LocalizedName) { var match = GroupedBasicViewRegex.Match(preview.DocumentUrl); if (match.Success) { var userid = Convert.ToInt32(match.Groups[2].Value); var user = UserController.Instance.GetUserById(portalId, userid); if (user != null) { preview.Attributes.Add("Avatar", user.Profile.PhotoURL); } } } var groupedResult = results.SingleOrDefault(g => g.DocumentTypeName == preview.DocumentTypeName); if (groupedResult != null) { if (!groupedResult.Results.Any(r => string.Equals(r.DocumentUrl, preview.DocumentUrl))) { groupedResult.Results.Add(new BasicView { Title = preview.Title.Contains("<") ? HttpUtility.HtmlEncode(preview.Title) : preview.Title, Snippet = preview.Snippet, Description = preview.Description, DocumentUrl = preview.DocumentUrl, Attributes = preview.Attributes }); } } else { results.Add(new GroupedBasicView(preview)); } } return(results); }
public ActionResult Preview(string keywords) { ActionResult actionResult = new ActionResult(); string culture = PortalSettings.CultureCode; int forceWild = 1; int portal = -1; keywords = (keywords ?? string.Empty).Trim(); IList <string> tags = SearchQueryStringParser.Instance.GetTags(keywords, out string cleanedKeywords); DateTime beginModifiedTimeUtc = SearchQueryStringParser.Instance.GetLastModifiedDate(cleanedKeywords, out cleanedKeywords); IList <string> searchTypes = SearchQueryStringParser.Instance.GetSearchTypeList(keywords, out cleanedKeywords); IList <SearchContentSource> contentSources = SearchInputManager.GetSearchContentSources(searchTypes); System.Collections.Hashtable settings = SearchInputManager.GetSearchModuleSettings(); List <int> searchTypeIds = SearchInputManager.GetSearchTypeIds(settings, contentSources); IEnumerable <int> moduleDefids = SearchInputManager.GetSearchModuleDefIds(settings, contentSources); List <int> portalIds = SearchInputManager.GetSearchPortalIds(settings, portal); int userSearchTypeId = SearchHelper.Instance.GetSearchTypeByName("user").SearchTypeId; SearchContentSource userSearchSource = contentSources.FirstOrDefault(s => s.SearchTypeId == userSearchTypeId); List <GroupedBasicView> results = new List <GroupedBasicView>(); if (portalIds.Any() && searchTypeIds.Any() && (!string.IsNullOrEmpty(cleanedKeywords) || tags.Any())) { SearchQuery query = new SearchQuery { KeyWords = cleanedKeywords, Tags = tags, PortalIds = portalIds, SearchTypeIds = searchTypeIds, ModuleDefIds = moduleDefids, BeginModifiedTimeUtc = beginModifiedTimeUtc, PageIndex = 1, PageSize = 5, TitleSnippetLength = 40, BodySnippetLength = 100, CultureCode = culture, WildCardSearch = forceWild > 0 }; try { results = SearchInputManager.GetGroupedBasicViews(query, userSearchSource, PortalSettings.PortalId); if (results.Count <= 0) { //var basicView = new List<BasicView>(); List <GroupedBasicView> NotFound = new List <GroupedBasicView> { new GroupedBasicView(new BasicView { Description = Localization.GetString("NoSearchResultFound", Components.Constants.LocalResourcesFile), Title = "NoSearchResultFound" }) }; results = NotFound; } } catch (Exception ex) { List <GroupedBasicView> NotFound = new List <GroupedBasicView> { new GroupedBasicView(new BasicView { Description = Localization.GetString("NoSearchResultFound", Components.Constants.LocalResourcesFile), Title = "NoSearchResultFound" }) }; results = NotFound; DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } } actionResult.Data = results; return(actionResult); }