【问题标题】:Category Tile View: Showing wrong Reply Count类别磁贴视图:显示错误的回复计数
【发布时间】:2015-12-22 22:10:39
【问题描述】:

在 SharePoint 社区网站中,类别磁贴视图显示错误的回复计数。一般来说,类别总回复数为 5,但在类别图块视图中显示为 3。这种行为我们能够在我们的测试和生产环境中复制。我们也等了一天,如果这个问题与 Crawl 有关但问题仍然存在。

请对此提出一些建议。

谢谢, 单张

【问题讨论】:

    标签: sharepoint-2013


    【解决方案1】:

    我遇到了完全相同的问题,但没有可用的修复程序。在我看来,这些计数器是通过事件接收器更新的,因此这与搜索抓取无关。

    我通过代码设置正确的字段解决了这个问题:

    先用这个 SSOM 代码统计主题和回复

            /// <summary>
        /// Dictionary: categId, nr disc
        /// </summary>
        public Dictionary<int, int> CategoryTopicCount
        {
            get
            {
                var categoriesDiscussionsCount = new Dictionary<int, int>();
                foreach (int categId in Categories)
                {
                    var spquery = new SPQuery();
                    spquery.Query = ""
                      + " <Where>"
                      + " <And> "
                      + "     <IsNull>"
                      + "       <FieldRef Name='ParentFolderId' />"
                      + "     </IsNull>"
                      + "     <Eq>"
                      + "       <FieldRef Name='CategoriesLookup' LookupId='TRUE' />"
                      + "       <Value Type='Lookup'>" + categId + "</Value>"
                      + "     </Eq>"
                      + " </And> "
                      + " </Where>";
                    spquery.ViewAttributes = "Scope='RecursiveAll'";
    
                    categoriesDiscussionsCount.Add(categId, _discussionList.GetItems(spquery).Count);
                }
                return categoriesDiscussionsCount;
            }
        }
    
        /// <summary>
        /// Dictionary: categId, nr replies
        /// </summary>
        public Dictionary<int, int> CategoryReplyCount
        {
            get
            {
                var categoriesDiscussionsCount = new Dictionary<int, int>();
                foreach (int categId in Categories)
                {
                    //get topics of this category
                    var spquery = new SPQuery();
                    spquery.Query = ""
                      + " <Where>"
                      + " <And> "
                      + "     <IsNull>"
                      + "       <FieldRef Name='ParentFolderId' />"
                      + "     </IsNull>"
                      + "     <Eq>"
                      + "       <FieldRef Name='CategoriesLookup' LookupId='TRUE' />"
                      + "       <Value Type='Lookup'>" + categId + "</Value>"
                      + "     </Eq>"
                      + " </And> "
                      + " </Where>";
                    spquery.ViewAttributes = "Scope='RecursiveAll'";
                    SPListItemCollection topicsOfThisCategory = _discussionList.GetItems(spquery);
    
                    //get nr of replies for each topic of this category
                    var totalRepliesCategory = 0;
                    foreach (SPListItem topic in topicsOfThisCategory)
                    {
                        var spqueryreplies = new SPQuery();
                        spqueryreplies.Query = ""
                          + " <Where>"
                          + " <And> "
                          + "     <IsNotNull>"
                          + "       <FieldRef Name='ParentFolderId' />"
                          + "     </IsNotNull>"
                          + "     <Eq>"
                          + "       <FieldRef Name='ParentFolderId' />"
                          + "       <Value Type='Number'>" + topic.ID + "</Value>"
                          + "     </Eq>"
                          + " </And> "
                          + " </Where>";
                        spqueryreplies.ViewAttributes = "Scope='RecursiveAll'";
                        totalRepliesCategory += _discussionList.GetItems(spqueryreplies).Count;
                    }
    
                    categoriesDiscussionsCount.Add(categId, totalRepliesCategory);
                }
    
                return categoriesDiscussionsCount;
            }
        }
    

    然后使用此 SSOM 代码更新计数器:

    /// <summary>
        /// Update number of topics and replies for each category
        /// </summary>
        public void UpdateCategoriesCounts()
        {
            Dictionary<int, int> categoryTopicCount = this.CategoryTopicCount;
            Dictionary<int, int> categoryReplyCount = this.CategoryReplyCount;
            SPListItemCollection categories = _categoryList.Items;
    
            foreach (SPListItem category in categories)
            {
                Console.WriteLine("Handling " + category.DisplayName);
                int topicCount = category["TopicCount"] == null ? 0 : Convert.ToInt32(category["TopicCount"]);
                int replyCount = category["ReplyCount"] == null ? 0 : Convert.ToInt32(category["ReplyCount"]);
                Console.WriteLine("Topics: " + categoryTopicCount[category.ID] + " || Replies: " + categoryReplyCount[category.ID]);
                _web.AllowUnsafeUpdates = true;
    
                if (categoryTopicCount[category.ID] != topicCount)
                    category["TopicCount"] = categoryTopicCount[category.ID];
    
                if (categoryReplyCount[category.ID] != replyCount)
                    category["ReplyCount"] = categoryReplyCount[category.ID];
                category.SystemUpdate(false);
    
                _web.AllowUnsafeUpdates = false;
                Console.WriteLine("Saved...");
            }
            Console.WriteLine("Finished");
        }
    

    希望对您有所帮助!

    PS:“我的会员”计数器可能会出现同样的问题。这里我们也可以通过代码来调整数值。检查这个:SharePoint 'my membership' webpart counters in community site

    【讨论】:

      猜你喜欢
      • 2013-02-08
      • 1970-01-01
      • 1970-01-01
      • 2021-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多