/// <summary>
 /// 设置关键字高亮
 /// </summary>
 /// <param name="dicKeywords">关键字列表</param>
 /// <param name="model">返回的数据模型</param>
 /// <returns></returns>
 private 供应商读出Lucene SetHighlighter(Dictionary<string, string> dicKeywords, 供应商读出Lucene model)
 {
     SimpleHTMLFormatter simpleHTMLFormatter = new PanGu.HighLight.SimpleHTMLFormatter("<font color=\"red\">", "</font>");
     Highlighter highlighter = new PanGu.HighLight.Highlighter(simpleHTMLFormatter, new Segment());
     highlighter.FragmentSize = 50;
     string strTitle = string.Empty;
     dicKeywords.TryGetValue("title", out strTitle);
     if (!string.IsNullOrEmpty(strTitle))
     {
         string title = highlighter.GetBestFragment(strTitle, model.供应商.企业基本信息.企业名称);
         if (!string.IsNullOrEmpty(title))
             model.供应商.企业基本信息.企业名称 = title;
     }
     return model;
 }
        public ActionResult Part_GysSelect_pagechange(int? page)
        {
            if (-1 != HttpContext.检查登录())
            {
                ViewData["已登录"] = "1";
            }
            else
            {
                ViewData["已登录"] = "0";
            }

            TopDocs serchalllist = null;

            PanGu.Segment.Init(PanGuXmlPath);

            string provence = Request.Params["provence"];//所在省份
            string city = Request.Params["city"];//所在城市
            string area = Request.Params["area"];//所在区县
            string industry = Request.Params["industry"];//所属行业
            string comname = Request.Params["comname"];//企业名称

            if (provence == "不限省份" && industry == "请选择行业" && string.IsNullOrEmpty(comname))
            {
                return Content("0");
            }

            try
            {
                BooleanQuery bQuery = new BooleanQuery();
                if (provence != "不限省份")
                {
                    //Lucene.Net.Search.Query query = new QueryParser("Province", PanGuAnalyzer).Parse(provence);
                    Lucene.Net.Search.Query query = new TermQuery(new Term("Province", provence));
                    bQuery.Add(query, BooleanClause.Occur.MUST);//其中的MUST、SHOULD、MUST_NOT表示与、或、非

                    if (city != "不限城市")
                    {
                        //query = new QueryParser("City", PanGuAnalyzer).Parse(city);
                        query = new TermQuery(new Term("City", city));
                        bQuery.Add(query, BooleanClause.Occur.MUST);

                        if (area != "不限区县")
                        {
                            //query = new QueryParser("Area", PanGuAnalyzer).Parse(area);
                            //query = new TermQuery(new Term("Area", area));
                            query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Area", PanGuAnalyzer).Parse(area);
                            bQuery.Add(query, BooleanClause.Occur.MUST);
                        }
                    }
                }


                if (industry != "请选择行业")
                {
                    Lucene.Net.Search.Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Industry", PanGuAnalyzer).Parse(industry);
                    //Lucene.Net.Search.Query query = new TermQuery(new Term("Industry", industry));
                    bQuery.Add(query, BooleanClause.Occur.MUST);
                }

                Dictionary<string, string> dic = new Dictionary<string, string>();
                if (!string.IsNullOrEmpty(comname))
                {
                    //bQuery1.Add(query5, BooleanClause.Occur.MUST);
                    //bQuery.Add(bQuery1, BooleanClause.Occur.MUST);

                    string title = GetKeyWordsSplitBySpace(comname);
                    Lucene.Net.Search.Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Name", PanGuAnalyzer).Parse(title);
                    bQuery.Add(query, BooleanClause.Occur.MUST);
                    dic.Add("title", comname);
                }

                if (bQuery != null && bQuery.GetClauses().Length > 0)
                {
                    serchalllist = GetSearchResult(bQuery, dic, "/Lucene.Net/IndexDic/Gys");
                }

                int listcount = serchalllist.totalHits > 1000 ? 1000 : serchalllist.totalHits;
                int maxpage = Math.Max((listcount + PAGESIZE - 1) / PAGESIZE, 1);
                if (string.IsNullOrEmpty(page.ToString()) || page < 0 || page > maxpage)
                {
                    page = 1;
                }

                IList<供应商读出Lucene> serchlist = new List<供应商读出Lucene>();
                if (serchalllist != null && listcount > 0)
                {
                    int length = PAGESIZE;
                    if (maxpage == page && listcount % PAGESIZE != 0)
                        length = listcount % PAGESIZE;

                    int count = PAGESIZE * ((int)page - 1);
                    //IndexSearcher search = new IndexSearcher(IndexDic("/Lucene.Net/IndexDic/Gys"), true);
                    IndexSearcher search = new IndexSearcher(new Lucene.Net.Store.SimpleFSDirectory(new System.IO.DirectoryInfo(IndexDic("/Lucene.Net/IndexDic/Gys"))), true);
                    for (int i = count; i < count + length; i++)
                    {
                        供应商 model = new 供应商();
                        model.Id = long.Parse(search.Doc(serchalllist.scoreDocs[i].doc).Get("NumId"));
                        model.企业基本信息.企业名称 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Name");

                        model.企业基本信息.所属行业 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Industry");

                        ////可提供商品类别
                        //供应商._产品类别 lb = new 供应商._产品类别();
                        //lb.一级分类 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Industry");
                        //model.可提供产品类别列表.Add(lb);

                        model.所属地域.省份 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Province");
                        model.所属地域.城市 = search.Doc(serchalllist.scoreDocs[i].doc).Get("City");
                        model.所属地域.区县 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Area");
                        model.企业联系人信息.联系人固定电话 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Telephone");
                        model.企业联系人信息.联系人姓名 = search.Doc(serchalllist.scoreDocs[i].doc).Get("P_Name");


                        var Rzjb = search.Doc(serchalllist.scoreDocs[i].doc).Get("Rzjb");
                        model.供应商用户信息.认证级别 = Rzjb == null ? 供应商.认证级别.未设置 : (供应商.认证级别)(int.Parse(Rzjb));

                        ///////////////////图标拆分
                        var 图标 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Level_Flage").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        if (图标[0] == "1")
                        {
                            model.供应商用户信息.年检列表.Add(DateTime.Now.Year.ToString(), new 操作数据());
                        }
                        model.供应商用户信息.应急供应商 = 图标[1] == "1";
                        model.供应商用户信息.协议供应商 = 图标[2] == "1";
                        model.供应商用户信息.入库级别 = (供应商.入库级别)(int.Parse(图标[3]));
                        ///////////////////图标拆分

                        //员工人数
                        model.企业基本信息.员工人数 = (供应商.员工人数)Enum.Parse(typeof(供应商.员工人数), search.Doc(serchalllist.scoreDocs[i].doc).Get("People_Count"));

                        供应商读出Lucene m = new 供应商读出Lucene();
                        m.供应商 = model;
                        m.登记商品数 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Pro_Count");
                        m.历史参标次数 = search.Doc(serchalllist.scoreDocs[i].doc).Get("History_Count");
                        m.经营类型 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Management");
                        m.主营产品 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Pro_Industry");
                        m.资质证书 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Zzzs_Pic");
                        m.厂房及设备图 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Gys_Pic");

                        //////////////////////////////////////////右边商品图片
                        var pro = search.Doc(serchalllist.scoreDocs[i].doc).Get("Show_Product");
                        if (!string.IsNullOrWhiteSpace(pro))
                        {
                            var prolist = pro.Split(new[] { "||||" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var item in prolist)
                            {
                                商品 sp = new 商品();
                                var itemlist = item.Split(new[] { "****" }, StringSplitOptions.RemoveEmptyEntries);
                                sp.商品信息.商品图片.Add(itemlist[0]);
                                sp.商品信息.商品名 = itemlist[1];
                                sp.销售信息.价格 = decimal.Parse(itemlist[2]);
                                sp.Id = long.Parse(itemlist[3]);
                                m.商品列表.Add(sp);
                            }
                        }
                        //判断会员类别
                        var 服务记录 = 供应商服务记录管理.查询供应商服务记录(0, 0, Query<供应商服务记录>.Where(o => o.所属供应商.用户ID == model.Id));
                        if (服务记录.Any())
                        {
                            var 已开通服务 = 服务记录.First().已开通的服务;
                            if (已开通服务.Any())
                            {
                                if (已开通服务.Where(o => o.所申请项目名.Contains("商务会员") && o.结束时间 > DateTime.Now).Any())
                                {
                                    m.会员类别 = "商务会员";
                                }
                                else if (已开通服务.Where(o => o.所申请项目名.Contains("标准会员") && o.结束时间 > DateTime.Now).Any())
                                {
                                    m.会员类别 = "标准会员";
                                }
                                else if (已开通服务.Where(o => o.所申请项目名.Contains("基础会员") && o.结束时间 > DateTime.Now).Any())
                                {
                                    m.会员类别 = "基础会员";
                                }
                            }
                        }
                        //判断会员类别
                        serchlist.Add(SetHighlighter(dic, m));
                    }
                }
                ViewData["供应商列表"] = serchlist;

                //ViewData["listcount"] = listcount;
                //ViewData["pagesize"] = 2;
                ViewData["currentpage"] = page;
                ViewData["pagecount"] = maxpage;
            }
            catch
            {
                ViewData["供应商列表"] = new List<供应商读出Lucene>();

                ViewData["currentpage"] = 1;
                ViewData["pagecount"] = 1;
            }


            ViewBag.Provence = provence;
            ViewBag.City = city;
            ViewBag.Area = area;
            ViewBag.Industry = industry;
            ViewBag.Comname = comname;

            return PartialView("Part_Gys/Part_GysSelect_Page");
        }
        public ActionResult Part_GysList() //供应商列表
        {
            if (-1 != HttpContext.检查登录())
            {
                ViewData["已登录"] = "1";
            }
            else
            {
                ViewData["已登录"] = "0";
            }
            ViewData["行业列表"] = 商品分类管理.查找子分类();
            var name = Request.QueryString["name"];
            if (!string.IsNullOrWhiteSpace(name))
            {
                string comname = name;//企业名称
                try
                {
                    TopDocs serchalllist = null;
                    int page = 1;

                    PanGu.Segment.Init(PanGuXmlPath);
                    BooleanQuery bQuery = new BooleanQuery();

                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    if (!string.IsNullOrEmpty(comname))
                    {
                        string title = GetKeyWordsSplitBySpace(comname);
                        Lucene.Net.Search.Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Name", PanGuAnalyzer).Parse(title);
                        bQuery.Add(query, BooleanClause.Occur.MUST);
                        dic.Add("title", comname);
                    }

                    if (bQuery != null && bQuery.GetClauses().Length > 0)
                    {
                        serchalllist = GetSearchResult(bQuery, dic, "/Lucene.Net/IndexDic/Gys");
                    }
                    var serchlist = new List<供应商读出Lucene>();
                    int listcount = serchalllist.totalHits > 1000 ? 1000 : serchalllist.totalHits;
                    int maxpage = Math.Max((listcount + PAGESIZE - 1) / PAGESIZE, 1);
                    if (serchalllist != null && listcount > 0)
                    {

                        int length = PAGESIZE;
                        if (maxpage == page && listcount % PAGESIZE != 0)
                            length = listcount % PAGESIZE;

                        //IndexSearcher search = new IndexSearcher(IndexDic("/Lucene.Net/IndexDic/Gys"), true);
                        IndexSearcher search = new IndexSearcher(new Lucene.Net.Store.SimpleFSDirectory(new System.IO.DirectoryInfo(IndexDic("/Lucene.Net/IndexDic/Gys"))), true);

                        for (int i = 0; i < length; i++)
                        {
                            供应商 model = new 供应商();
                            model.Id = long.Parse(search.Doc(serchalllist.scoreDocs[i].doc).Get("NumId"));
                            model.企业基本信息.企业名称 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Name");
                            model.企业基本信息.所属行业 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Industry");
                            model.所属地域.省份 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Province");
                            model.所属地域.城市 = search.Doc(serchalllist.scoreDocs[i].doc).Get("City");
                            model.所属地域.区县 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Area");
                            model.企业联系人信息.联系人固定电话 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Telephone");
                            model.企业联系人信息.联系人姓名 = search.Doc(serchalllist.scoreDocs[i].doc).Get("P_Name");

                            var Rzjb = search.Doc(serchalllist.scoreDocs[i].doc).Get("Rzjb");
                            model.供应商用户信息.认证级别 = Rzjb == null ? 供应商.认证级别.未设置 : (供应商.认证级别)(int.Parse(Rzjb));

                            ///////////////////图标拆分
                            var 图标 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Level_Flage").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            if (图标[0] == "1")
                            {
                                model.供应商用户信息.年检列表.Add(DateTime.Now.Year.ToString(), new 操作数据());
                            }
                            model.供应商用户信息.应急供应商 = 图标[1] == "1";
                            model.供应商用户信息.协议供应商 = 图标[2] == "1";
                            model.供应商用户信息.入库级别 = (供应商.入库级别)(int.Parse(图标[3]));
                            ///////////////////图标拆分

                            //员工人数
                            model.企业基本信息.员工人数 = (供应商.员工人数)Enum.Parse(typeof(供应商.员工人数), search.Doc(serchalllist.scoreDocs[i].doc).Get("People_Count"));

                            供应商读出Lucene m = new 供应商读出Lucene();
                            m.供应商 = model;
                            m.登记商品数 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Pro_Count");
                            m.历史参标次数 = search.Doc(serchalllist.scoreDocs[i].doc).Get("History_Count");
                            m.经营类型 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Management");
                            m.主营产品 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Pro_Industry");
                            m.资质证书 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Zzzs_Pic");
                            m.厂房及设备图 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Gys_Pic");


                            //////////////////////////////////////////右边商品图片
                            var pro = search.Doc(serchalllist.scoreDocs[i].doc).Get("Show_Product");
                            if (!string.IsNullOrWhiteSpace(pro))
                            {
                                var prolist = pro.Split(new[] { "||||" }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (var item in prolist)
                                {
                                    商品 sp = new 商品();
                                    var itemlist = item.Split(new[] { "****" }, StringSplitOptions.RemoveEmptyEntries);
                                    sp.商品信息.商品图片.Add(itemlist[0]);
                                    sp.商品信息.商品名 = itemlist[1];
                                    sp.销售信息.价格 = decimal.Parse(itemlist[2]);
                                    sp.Id = long.Parse(itemlist[3]);
                                    m.商品列表.Add(sp);
                                }
                            }
                            //判断会员类别
                            var 服务记录 = 供应商服务记录管理.查询供应商服务记录(0, 0, Query<供应商服务记录>.Where(o => o.所属供应商.用户ID == model.Id));
                            if (服务记录.Any())
                            {
                                var 已开通服务 = 服务记录.First().已开通的服务;
                                if (已开通服务.Any())
                                {
                                    if (已开通服务.Where(o => o.所申请项目名.Contains("商务会员") && o.结束时间 > DateTime.Now).Any())
                                    {
                                        m.会员类别 = "商务会员";
                                    }
                                    else if (已开通服务.Where(o => o.所申请项目名.Contains("标准会员") && o.结束时间 > DateTime.Now).Any())
                                    {
                                        m.会员类别 = "标准会员";
                                    }
                                    else if (已开通服务.Where(o => o.所申请项目名.Contains("基础会员") && o.结束时间 > DateTime.Now).Any())
                                    {
                                        m.会员类别 = "基础会员";
                                    }
                                }
                            }
                            //判断会员类别
                            serchlist.Add(SetHighlighter(dic, m));
                        }
                    }

                    ViewData["供应商列表"] = serchlist;
                    ViewData["currentpage"] = page;
                    ViewData["pagecount"] = maxpage;
                }
                catch
                {
                    ViewData["供应商列表"] = new List<供应商读出Lucene>();

                    ViewData["currentpage"] = 1;
                    ViewData["pagecount"] = 1;
                }

                ViewBag.Provence = "不限省份";
                ViewBag.City = "不限城市";
                ViewBag.Area = "不限区县";
                ViewBag.Industry = "请选择行业";
                ViewBag.Comname = comname;

                return PartialView("Part_Gys/Part_GysList_SearchBox");


            }
            else
            {
                //未付费
                var q = MongoDB.Driver.Builders.Query<供应商>.Where(o => o.审核数据.审核状态 == 审核状态.审核通过||o.入网审核数据.审核状态== 审核状态.审核通过);
                long listcount = (int)用户管理.计数用户<供应商>(0, 0, q, false);
                long maxpagesize = Math.Max((listcount + PAGESIZE - 1) / PAGESIZE, 1);
                ViewData["currentpage"] = 1;
                ViewData["pagecount"] = maxpagesize;

                ViewData["供应商列表"] = 用户管理.查询用户<供应商>(0, PAGESIZE, q, false, SortBy<供应商>.Descending(o => o.供应商用户信息.认证级别).Descending(o => o.基本数据.修改时间), false);
                return PartialView("Part_Gys/Part_GysList");
            }



        }