Esempio n. 1
0
        /// <summary>
        /// 根据新增,修改情况 热词分析 分词 发文/修改统计
        /// </summary>
        public void DataAnalyse()
        {
            var startTime = DateTime.Now;///开始运行时间

            Console.Title = "文档维护进程进程 启动时间:" + startTime;
            while (true)
            {
                ///遍历写入数据
                var dbName         = CONST.DB.DBName_DocService;
                var collectionName = CONST.DB.CollectionName_ModifyLogItem;
                var db             = DataStorage.GetInstance(DBType.MongoDB);
                db.EventTraverse += (object sender, EventArgs e) =>
                {
                    EventProcEventArgs ee = e as EventProcEventArgs;
                    var dict                 = ee.Default as Dictionary <string, object>;
                    var targetDbName         = dict["DatabaseName"].ToString();
                    var targetCollectionName = dict["CollectionName"].ToString();
                    var targetID             = (ObjectId)dict["TargetID"];
                    var id = dict["_id"].ToString();

                    if (targetCollectionName == CONST.DB.CollectionName_DocItem)
                    {
                        ///重新分词,聚类
                        var doc       = new DocItem();
                        var plainText = doc.PlainText;
                        var res       = FenCi.GetResult(plainText);
                        var queryDel  = "{'TargetID':ObjectId('" + targetID.ToString() + "')}";
                        db.Remove(dbName, collectionName, queryDel);
                        foreach (var item in res)
                        {
                            var svItem = new
                            {
                                DbName           = targetDbName,
                                CollectionName   = targetCollectionName,
                                TargetID         = targetID,
                                Word             = item.Key,
                                Count            = item.Value,
                                CreateTime       = DateTime.Now,
                                TargetCreateTime = dict["CreateTime"]
                            };

                            db.Save3(CONST.DB.DBName_DocService, CONST.DB.CollectionName_FenCi, svItem);
                        }
                    }
                    else if (targetCollectionName == CONST.DB.CollectionName_CategoryItem)
                    {
                        ///重新统计,当前目录的子目录数量 , 每一级文档数量
                        var subCategoryList = CategoryManager.GetInstance().GetSubCategory(targetID.ToString());
                        var category        = CategoryItem.Load(targetID.ToString());
                        category.SubCategoryCount = subCategoryList.Count;
                        category.Save();
                    }

                    //ModifyLogItem.Remove(id);
                };
                db.Traverse(dbName, collectionName, "{}");
                ThreadManager.Pause(minutes: 2);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 计算分词结果
        /// </summary>
        /// <param name="content"></param>
        /// <param name="MD5"></param>
        public void SaveFenCi(string content, string url)
        {
            if (!string.IsNullOrWhiteSpace(content) && !string.IsNullOrWhiteSpace(content))
            {
                var dbName         = CONST.DB.DBName_StockService;
                var collectionName = CONST.DB.CollectionName_FenCi;

                var res   = FenCi.GetResult(content);
                var mongo = DataStorage.GetInstance(DBType.MongoDB);

                foreach (var item in res)
                {
                    var svItem = new {
                        Url        = url,
                        Word       = item.Key,
                        Count      = item.Value,
                        CreateTime = DateTime.Now
                    };
                    var filter = "{\"Url\":\"" + url.Trim() + "\",\"Word\":\"" + svItem.Word + "\"}";

                    mongo.Save3(dbName, collectionName, svItem, filter);
                }
            }
        }