Ejemplo n.º 1
0
        //赋值
        private void ShowInfo()
        {
            BLL.channel bll = new BLL.channel();
            DataTable   dt  = bll.GetList(0, "", "sort_id asc,id desc").Tables[0];

            if (dt.Rows.Count > 0)
            {
                BLL.luceneconfig xml = new BLL.luceneconfig();
                foreach (DataRow dr in dt.Rows)
                {
                    CheckBox cbControl   = FindControl("control_checkbox_" + dr["id"].ToString()) as CheckBox;
                    TextBox  txtLastId   = FindControl("control_lastid_" + dr["id"].ToString()) as TextBox;
                    TextBox  txtLastTime = FindControl("control_lasttime_" + dr["id"].ToString()) as TextBox;
                    if (null != cbControl && null != txtLastId && null != txtLastTime)
                    {
                        string status = xml.GetText("Lucene/" + dr["name"].ToString() + "/status");

                        if (status == "1")
                        {
                            cbControl.Checked = true;

                            txtLastId.Text   = xml.GetText("Lucene/" + dr["name"].ToString() + "/lastid");
                            txtLastTime.Text = xml.GetText("Lucene/" + dr["name"].ToString() + "/lasttime");
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //保存配置
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("lucene_index", DTEnums.ActionEnum.Edit.ToString());

            List <Model.luceneconfig> list = GetDicValues();

            //字典
            BLL.luceneconfig bll = new BLL.luceneconfig();
            if (bll.Save(list))
            {
                JscriptMsg("保存成功!", "builder_index.aspx");
            }
            else
            {
                JscriptMsg("保存过程中发生错误!", "");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 索引数据
        /// </summary>
        private void CreateSearchIndex(HttpContext context)
        {
            //检查权限
            if (!new BLL.manager_role().Exists(adminInfo.role_id, "lucene_index", DTEnums.ActionEnum.Build.ToString()))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"您没有确认订单的权限!\"}");
                return;
            }
            bool   hasnew    = false;
            int    is_create = DTRequest.GetQueryInt("create");
            int    is_lock   = is_create;
            string strWhere  = "status=0";

            BLL.article               bll  = new BLL.article();
            BLL.channel               chl  = new BLL.channel();
            BLL.luceneconfig          xml  = new BLL.luceneconfig();
            List <Model.luceneconfig> list = xml.Load();

            foreach (Model.luceneconfig model in list)
            {
                if (!chl.Exists(model.name))
                {
                    continue;
                }
                if (is_create == 0)
                {
                    strWhere += " and id >" + model.id.ToString();
                }
                if (model.status == 1)
                {
                    DataTable dt     = bll.GetList(model.name, 1000, strWhere, "id asc").Tables[0];
                    int       _count = dt.Rows.Count;
                    if (_count > 0)
                    {
                        int count = 0;
                        hasnew = true;
                        LuceneHelper.CreateIndex(LuceneHelper.INDEX_DIR, is_lock);
                        LuceneHelper.MaxMergeFactor = 301;
                        LuceneHelper.MinMergeDocs   = 301;
                        string     _maxid = dt.Rows[_count - 1]["ID"].ToString();
                        SearchItem item   = null;
                        if (is_lock > 0)
                        {
                            is_lock = 0;
                        }
                        for (int j = 0; j < dt.Rows.Count; j++)
                        {
                            item             = new SearchItem();
                            item.id          = Utils.StrToInt(dt.Rows[j]["id"].ToString(), 0);
                            item.site_id     = Utils.StrToInt(dt.Rows[j]["site_id"].ToString(), 0);
                            item.channel_id  = Utils.StrToInt(dt.Rows[j]["channel_id"].ToString(), 0);
                            item.category_id = Utils.StrToInt(dt.Rows[j]["category_id"].ToString(), 0);
                            item.title       = dt.Rows[j]["title"].ToString();
                            //if (dt.Columns.Contains("sub_title"))
                            //{
                            //    item.sub_title = dt.Rows[j]["sub_title"].ToString();
                            //}
                            //else
                            //{
                            //    item.sub_title = "";
                            //}
                            item.call_index = dt.Rows[j]["call_index"].ToString();
                            item.tags       = dt.Rows[j]["tags"].ToString();
                            item.img_url    = dt.Rows[j]["img_url"].ToString();
                            //item.zhaiyao = dt.Rows[j]["zhaiyao"].ToString();
                            item.zhaiyao = Utils.DropHTML(dt.Rows[j]["content"].ToString());
                            //if (dt.Columns.Contains("market_price"))
                            //{
                            //    item.market_price = Utils.StrToDecimal(dt.Rows[j]["market_price"].ToString(), 0);
                            //}
                            //else
                            //{
                            //    item.market_price = 0;
                            //}
                            //if (dt.Columns.Contains("sell_price"))
                            //{
                            //    item.sell_price = Utils.StrToInt(dt.Rows[j]["sell_price"].ToString(), 0);
                            //}
                            //else
                            //{
                            //    item.sell_price = 0;
                            //}
                            //item.is_top = Utils.StrToInt(dt.Rows[j]["is_top"].ToString(), 0);
                            //item.is_red = Utils.StrToInt(dt.Rows[j]["is_red"].ToString(), 0);
                            //item.is_hot = Utils.StrToInt(dt.Rows[j]["is_hot"].ToString(), 0);
                            item.add_time    = DateTime.Parse(dt.Rows[j]["add_time"].ToString());
                            item.update_time = Utils.StrToDateTime(dt.Rows[j]["update_time"].ToString(), item.add_time);
                            LuceneHelper.IndexString(LuceneHelper.INDEX_DIR, item).ToString();
                            count++;
                            if (count % 300 == 0)
                            {
                                LuceneHelper.CloseWithoutOptimize();
                                LuceneHelper.CreateIndex(LuceneHelper.INDEX_DIR, 0);
                                LuceneHelper.MaxMergeFactor = 301;
                                LuceneHelper.MinMergeDocs   = 301;
                            }
                        }
                        xml.Update("Lucene/" + model.name + "/lastid", _maxid);
                        xml.Update("Lucene/" + model.name + "/lasttime", System.DateTime.Now.ToString());
                        xml.Save();
                        LuceneHelper.Close();
                    }
                }
            }
            if (hasnew)
            {
                JsonHelper.WriteJson(context, new
                {
                    status = 2,
                    msg    = "再去追加一次吧"
                });
            }
            else
            {
                JsonHelper.WriteJson(context, new
                {
                    status = 1,
                    msg    = "索引更新完成"
                });
            }
        }