Beispiel #1
0
        internal virtual object SearchContentSourceCallback(CacheItemArgs cacheItem)
        {
            var searchTypes = CBO.FillCollection <SearchType>(DataProvider.GetAllSearchTypes());

            var results = new List <SearchContentSource>();

            foreach (var crawler in searchTypes)
            {
                switch (crawler.SearchTypeName)
                {
                case "module":     // module crawler

                    // get searchable module definition list
                    var portalId         = int.Parse(cacheItem.CacheKey.Split('-')[1]);
                    var moduleController = new ModuleController();
                    var modules          = moduleController.GetSearchModules(portalId);
                    var modDefIds        = new HashSet <int>();

                    foreach (ModuleInfo module in modules)
                    {
                        if (!modDefIds.Contains(module.ModuleDefID))
                        {
                            modDefIds.Add(module.ModuleDefID);
                        }
                    }

                    var list = modDefIds.Select(ModuleDefinitionController.GetModuleDefinitionByID).ToList();

                    foreach (var def in list)
                    {
                        var text = Localization.Localization.GetSafeJSString("Module_" + def.DefinitionName, LocalizedResxFile);
                        if (string.IsNullOrEmpty(text))
                        {
                            text = def.FriendlyName;
                        }
                        var result = new SearchContentSource
                        {
                            SearchTypeId       = crawler.SearchTypeId,
                            SearchTypeName     = crawler.SearchTypeName,
                            IsPrivate          = crawler.IsPrivate,
                            ModuleDefinitionId = def.ModuleDefID,
                            LocalizedName      = text
                        };

                        results.Add(result);
                    }

                    break;

                default:

                    var localizedName = Localization.Localization.GetSafeJSString("Crawler_" + crawler.SearchTypeName, LocalizedResxFile);
                    if (string.IsNullOrEmpty(localizedName))
                    {
                        localizedName = crawler.SearchTypeName;
                    }

                    results.Add(new SearchContentSource
                    {
                        SearchTypeId       = crawler.SearchTypeId,
                        SearchTypeName     = crawler.SearchTypeName,
                        IsPrivate          = crawler.IsPrivate,
                        ModuleDefinitionId = 0,
                        LocalizedName      = localizedName
                    });
                    break;
                }
            }

            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 = Regex.Match(preview.DocumentUrl, "userid(/|\\|=)(\\d+)", RegexOptions.IgnoreCase);
                    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,
                            Snippet = preview.Snippet,
                            DocumentUrl = preview.DocumentUrl,
                            Attributes = preview.Attributes
                        });
                }
                else
                {
                    results.Add(new GroupedBasicView(preview));
                }
            }

            return results;
        }
        internal virtual object SearchContentSourceCallback(CacheItemArgs cacheItem)
        {
            var searchTypes = CBO.FillCollection<SearchType>(DataProvider.GetAllSearchTypes());

            var results = new List<SearchContentSource>();

            foreach (var crawler in searchTypes)
            {
                switch (crawler.SearchTypeName)
                {
                    case "module": // module crawler

                        // get searchable module definition list
                        var portalId = int.Parse(cacheItem.CacheKey.Split('-')[1]);
                        var modules = ModuleController.Instance.GetSearchModules(portalId);
                        var modDefIds = new HashSet<int>();

                        foreach (ModuleInfo module in modules)
                        {
                            if (!modDefIds.Contains(module.ModuleDefID)) modDefIds.Add(module.ModuleDefID);
                        }
                        
                        var list = modDefIds.Select(ModuleDefinitionController.GetModuleDefinitionByID).ToList();

                        foreach (var def in list)
                        {
                            var text = Localization.Localization.GetSafeJSString("Module_" + def.DefinitionName, LocalizedResxFile);
                            if (string.IsNullOrEmpty(text))
                            {
                                text = def.FriendlyName;
                            }
                            var result = new SearchContentSource
                            {
                                SearchTypeId = crawler.SearchTypeId,
                                SearchTypeName = crawler.SearchTypeName,
                                IsPrivate = crawler.IsPrivate,
                                ModuleDefinitionId =  def.ModuleDefID,
                                LocalizedName = text
                            };

                            results.Add(result);
                        }

                        break;

                    default:

                        var localizedName = Localization.Localization.GetSafeJSString("Crawler_" + crawler.SearchTypeName, LocalizedResxFile);
                        if (string.IsNullOrEmpty(localizedName))
                        {
                            localizedName = crawler.SearchTypeName;
                        }

                        results.Add(new SearchContentSource
                        {
                            SearchTypeId = crawler.SearchTypeId,
                            SearchTypeName = crawler.SearchTypeName,
                            IsPrivate = crawler.IsPrivate,
                            ModuleDefinitionId = 0,
                            LocalizedName = localizedName
                        });
                        break;
                }
            }

            return results;

        }
  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;
 }