Exemplo n.º 1
0
        // GET: Blog
        public ActionResult Index(int id = 1, string bcategory = "技术博文")
        {
            //获取控制器名称
            ViewBag.controllername = RouteData.Values["controller"].ToString().ToLower();
            int pagesize        = 6;
            var blogArticleList = TopicServive.QueryOrderBy(a => !a.tIsDelete, a => a.tCreatetime, false).ToPagedList(id, pagesize);

            return(View(blogArticleList));
        }
Exemplo n.º 2
0
        public ActionResult Search(string wd)
        {
            var content   = wd;
            var str       = "";
            var segmenter = new JiebaSegmenter();

            str += ($"原检索语句: {content}<br >");

            if (!string.IsNullOrEmpty(content))
            {
                //PanGuLuceneHelper.instance.DeleteAll();
                var segments4 = segmenter.CutForSearch(content); // 搜索引擎模式
                str += ($"【搜索引擎模式】:{ string.Join("/ ", segments4)}<br >");
                var topicList       = TopicServive.QueryOrderBy(a => !a.tIsDelete, a => a.tCreatetime, false);
                var topicDetailList = TopicDetailServive.QueryOrderBy(a => !a.tdIsDelete, a => a.tdCreatetime, false);
                var blogArticleList = BlogArticleServive.QueryOrderBy(a => true, a => a.bCreateTime, false);

                List <MySearchUnit> list = new List <MySearchUnit>();
                foreach (var item in topicList)
                {
                    list.Add(new MySearchUnit("Topic" + item.Id, item.tName, item.tDetail, new Random().Next(1, 100).ToString(), "", item.tCreatetime.ToString("yyyy年MM月dd日")));
                }
                foreach (var item in topicDetailList)
                {
                    item.tdContent = Tools.ReplaceHtmlTag(item.tdContent);
                    list.Add(new MySearchUnit("TopicDetail" + item.Id, item.tdName, item.tdContent, new Random().Next(1, 100).ToString(), "", item.tdCreatetime.ToString("yyyy年MM月dd日")));
                }
                foreach (var item in blogArticleList)
                {
                    item.bcontent = Tools.ReplaceHtmlTag(item.bcontent);
                    list.Add(new MySearchUnit("BlogArtic" + item.bID, item.btitle, item.bcontent, new Random().Next(1, 100).ToString(), "", item.bCreateTime.ToString("yyyy年MM月dd日")));
                }

                PanGuLuceneHelper.instance.CreateIndex(list);//添加索引


                int    count                   = 0;
                int    PageIndex               = 1;
                int    PageSize                = 100;
                string html_content            = "";
                List <MySearchUnit> searchlist = PanGuLuceneHelper.instance.Search("", string.Join(" ", segments4.Where(d => d.Length >= 2)), PageIndex, PageSize, out count);
                List <string>       idList     = new List <string>();
                if (searchlist == null || searchlist.Count == 0)
                {
                    html_content += ("未查询到数据。<br/>");
                }
                else
                {
                    foreach (MySearchUnit data in searchlist)
                    {
                        if (!idList.Contains(data.id))
                        {
                            //html_content += (string.Format("id:{0},title:{1},content:{2},flag:{3},updatetime:{4}<br/>", data.id, data.title, data.content, data.flag, data.updatetime));
                            html_content += GetSearchHtml(data.id, data.title, data.content, data.updatetime);
                            idList.Add(data.id);
                        }
                    }
                }
                html_content += ("查询结果:" + idList.Count + "条数据<br/>");
                str          += html_content;
            }
            else
            {
                return(View("Home"));
            }


            ViewBag.html = str;
            return(View());
        }