Пример #1
0
        private void add_dic_word(HttpContext context)
        {
            //检查权限
            if (!new BLL.manager_role().Exists(adminInfo.role_id, "lucene_pangu", DTEnums.ActionEnum.Add.ToString()))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"您没有操作权限!\"}");
                return;
            }
            int    pos       = DTRequest.GetFormInt("p");
            int    frequency = DTRequest.GetFormInt("f");
            string key       = DTRequest.GetFormString("k");

            if (string.IsNullOrEmpty(key))
            {
                context.Response.Write("{\"status\":0 ,\"msg\":\"关键词不能为空!\"}");
                return;
            }

            PanguHelper dic = new PanguHelper();

            if (dic.InsertWord(key, (double)frequency, pos))
            {
                dic.Save(DateTime.Now.ToString("yyMMddhh"));
                context.Response.Write("{\"status\":1 ,\"msg\":\"添加成功!\"}");
            }
            else
            {
                context.Response.Write("{\"status\":0 ,\"msg\":\"添加失败!\"}");
            }
        }
Пример #2
0
        private void add_dic_word_all(HttpContext context)
        {
            //检查权限
            if (!new BLL.manager_role().Exists(adminInfo.role_id, "lucene_pangu", DTEnums.ActionEnum.Add.ToString()))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"您没有操作权限!\"}");
                return;
            }

            int    pos       = DTRequest.GetFormInt("p");
            int    frequency = DTRequest.GetFormInt("f");
            string key       = DTRequest.GetFormString("k");

            int sucCount   = 0;
            int errorCount = 0;

            if (string.IsNullOrEmpty(key))
            {
                context.Response.Write("{\"status\":0 ,\"msg\":\"关键词不能为空!\"}");
                return;
            }

            key = Regex.Replace(key, @"\W+", ",");
            string[]    valArr = key.Split(',');
            PanguHelper dic    = new PanguHelper();

            if (valArr.Length > 0)
            {
                foreach (string k in valArr)
                {
                    if (dic.InsertWord(k, (double)frequency, pos))
                    {
                        sucCount++;
                    }
                    else
                    {
                        errorCount++;
                    }
                }
                dic.Save(DateTime.Now.ToString("yyMMddhh"));
                context.Response.Write("{\"status\":1 ,\"msg\":\"" + string.Format("添加成功{0}条,失败{1}条!", sucCount, errorCount) + "\"}");
                return;
            }
            context.Response.Write("{\"status\":0 ,\"msg\":\"添加失败!\"}");
        }