allpublicopinionHandler.ashx处理程序:
public class allpublicopinionHandler : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request; HttpResponse response = context.Response; int userId = UserSession.GetUserId(); string flag = request.Form["flag"].ToString().Trim(); if (flag == "GetSentimentList") { GetSentimentList(response, request, userId); } } public void GetSentimentList(HttpResponse response, HttpRequest request, int userId) { int Currentpage = JSSDW.Utils.StringUtils.ToInt32(request.Form["Currentpage"], 0); int Pagesize = 8; int recCount=0; string grpId = request.Form["grpId"].ToString(); string keywords = request.Form["keywords"].ToString().Trim(); string date = request.Form["date"].ToString().Trim(); DateTime endTime = JSSDW.Utils.StringUtils.ToDateTime(request.Form["endTime"], DateTime.Now); int Ttype = JSSDW.Utils.StringUtils.ToInt32(request.Form["rrsType"], 0); int Tflag = JSSDW.Utils.StringUtils.ToInt32(request.Form["Tflag"], 0); int SortType = JSSDW.Utils.StringUtils.ToInt32(request.Form["SortType"],0); DateTime endTime1 = endTime; DateTime begionTime = endTime1.AddMonths(-1); string[] tempDates = date.Split('-'); if (tempDates.Length == 2) { begionTime = DateTime.Parse(tempDates[0]); if (DateTime.Parse(tempDates[1]) >= DateTime.Parse(endTime.ToShortDateString())) { endTime1 = endTime; } else { endTime1 = DateTime.Parse(tempDates[1]).AddDays(1).AddMinutes(-1); } } int begion = (Currentpage-1) * Pagesize; int end = Currentpage * Pagesize; string strSort = "recordDate desc,recordtime desc"; if (SortType == 1) strSort = "Score desc,recordtime desc"; else if (SortType == 2) strSort = "mstexposure desc,recordtime desc"; PublicOpinion publicOpinionBiz = new PublicOpinion(); IList<Interface.PublicOpnion.M_KeyWord> listKeywords = new List<Interface.PublicOpnion.M_KeyWord>(); if (keywords != "" && keywords!=null) { string[] listKey = keywords.Split(','); foreach (string key in listKey) { listKeywords.Add(new Interface.PublicOpnion.M_KeyWord() { GrpID = 0, ID = 0, Name = key, RecordTime = DateTime.Now }); } } else { listKeywords = publicOpinionBiz.GetKeyWordListByGrpId(int.Parse(grpId), userId); } IList<Interface.PublicOpnion.V_Sentiment> listSentiment = publicOpinionBiz.Search(Ttype, Tflag, listKeywords, strSort, begion, end,begionTime,endTime1, out recCount); if (listSentiment != null) { response.Write("{\"RecordCount\":" + recCount.ToString() + ",\"ListSentiment\":" + listSentiment.ToJson() + "}"); } else { response.Write("{\"RecordCount\":0,\"ListSentiment\":[]}"); } } }
首先要引用 <link href="/css/pagination.css" rel="stylesheet" type="text/css" />
<script src="/scripts/jquery.pagination.js" type="text/javascript"></script>
<script src="http://www.cnblogs.com/../scripts/pagging.js" type="text/javascript"></script>
var sentiment = { initPage: function () { sentiment.loadSentimentList(); }, loadSentimentList: function () { sentiment.GetSentimentList(1, 8); }, createPage: function (count, pagesize) { if (count > pagesize) { $('#page').pagination(count, { callback: sentiment.PageCallback, prev_text: '上一页', //上一页按钮里text next_text: '下一页', //下一页按钮里text items_per_page: pagesize, //显示条数 num_display_entries: 6, //连续分页主体部分分页条目数 current_page: 0, //当前页索引 num_edge_entries: 1 //两侧首尾分页条目数 }); } }, PageCallback: function (index, jq) { sentiment.GetSentimentList(index + 1, 8); }, GetSentimentList: function (Currentpage, Pagesize) { var grpId = sentiment.grpId; var rrsType = sentiment.Flag; var Tflag = sentiment.Tflag; var keywords = sentiment.Keywords; var sortType = sentiment.sortType; var date = sentiment.selectDate; var endTime = sentiment.endTime; $.ajax({ url: '/plat/publicopinion/allpublicopinion/allpublicopinionHandler.ashx', type: 'post', dataType: 'json', data: { flag: 'GetSentimentList', grpId: grpId, rrsType: rrsType, Tflag: Tflag, Keywords: keywords, date: date, endTime: endTime, currentPage: Currentpage, pageSize: Pagesize, SortType: sortType }, success: function (data) { var sentimentList = data.ListSentiment; var recordCount = data.RecordCount; if ($(sentimentList).length > 0) { var html = ""; $(sentimentList).each(function (i, n) { var table = "<table width='550' border='0' cellspacing='0' cellpadding='0'>"; table += "<tr><td><h2><a href='" + n.Url + "' target='_blank'>" + n.Title + "</a></h2></td></tr>"; table += "<tr><td>" + n.Content1 + "</td></tr>"; table += "<tr><td>" + n.Msexposure + " " + n.RecordTime + " 共有" + n.Samecount + "个相同文章 综合曝光度:" + n.Mstexposure + "</td></tr>"; table += "</table>"; html += table; }); $("#sentimentContent").html(html); } else { $("#sentimentContent").html("暂无舆情!"); $("#page").html(""); } if (Currentpage == 1) { sentiment.createPage(recordCount, 8); $("#sentimentSort span:first").html("所有<b>“" + keywords + "”</b>信息共<b>" + recordCount + "</b>条"); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); } }); } }
WebBiz 层处理数据层:
#region 得到分词搜索类别信息 private static string _TitleAnalyzerName = null; private static string _ContentAnalyzerName = null; private static void GetAnalyzerName(HubbleAsyncConnection conn, string tableName) { if (_TitleAnalyzerName != null && _ContentAnalyzerName != null) { return; } string sql = string.Format("exec SP_Columns '{0}'", tableName.Replace("'", "''")); HubbleCommand cmd = new HubbleCommand(sql, conn); foreach (System.Data.DataRow row in cmd.Query().Tables[0].Rows) { if (row["FieldName"].ToString().Equals("Title", StringComparison.CurrentCultureIgnoreCase)) { _TitleAnalyzerName = row["Analyzer"].ToString(); } if (row["FieldName"].ToString().Equals("Content1", StringComparison.CurrentCultureIgnoreCase)) { _ContentAnalyzerName = row["Analyzer"].ToString(); } } } /// <summary> /// 返回按照关键词查询得到列表集合 /// </summary> /// <param name="Flag">新闻博客论坛</param> /// <param name="Tflag">文字图片视频</param> /// <param name="KeyWords">关键词集合/param> /// <param name="sortby">排序字段</param> /// <param name="pageLen">开始纪录ID号</param> /// <param name="pageNo">结束纪录ID号</param> /// <param name="recCount">总行书</param> public List<PublicOpnion.V_Sentiment> Search(int Flag, int TFlag, IList<PublicOpnion.M_KeyWord> KeyWords, string sortby, int begion, int end,DateTime begionDate,DateTime endDate, out int recCount) { List<PublicOpnion.V_Sentiment> result = new List<PublicOpnion.V_Sentiment>(); System.Data.DataSet ds; string temp = string.Empty; foreach (PublicOpnion.M_KeyWord xx in KeyWords)//循环查询关键词匹配的文章 { temp +=" " + xx.Name; } if (temp.Length > 0) temp = temp.Remove(0, 1); using (HubbleAsyncConnection conn = new HubbleAsyncConnection("Data Source=192.168.2.199;Initial Catalog=Rss;")) { conn.Open(); GetAnalyzerName(conn, "ViewRss"); if (string.IsNullOrEmpty(sortby)) { sortby = "recordDate desc,recordtime desc"; } HubbleCommand matchCmd = new HubbleCommand(conn); HubbleDataAdapter adapter = new HubbleDataAdapter(); if (Flag == 0 && TFlag == 0) { adapter.SelectCommand = new HubbleCommand("select between @begin to @end * from ViewRss where (content1^3 match @Content1matchString or Title^2000 match @Titlematchstring) and (recordTime>=@begionTime and recordTime<=@endTime) order by " + sortby, conn); } else if (Flag == 0 && TFlag!=0) { adapter.SelectCommand = new HubbleCommand("select between @begin to @end * from ViewRss where (content1^3 match @Content1matchString or Title^2000 match @Titlematchstring) and (recordTime>=@begionTime and recordTime<=@endTime) and TFlag=@TFlag order by " + sortby, conn); adapter.SelectCommand.Parameters.Add("@TFlag", TFlag); } else if (Flag != 0 && TFlag == 0) { adapter.SelectCommand = new HubbleCommand("select between @begin to @end * from ViewRss where (content1^3 match @Content1matchString or Title^2000 match @Titlematchstring) and (recordTime>=@begionTime and recordTime<=@endTime) and Flag=@Flag order by " + sortby, conn); adapter.SelectCommand.Parameters.Add("@Flag", Flag); } else { adapter.SelectCommand = new HubbleCommand("select between @begin to @end * from ViewRss where (content1^3 match @Content1matchString or Title^2000 match @Titlematchstring) and (recordTime>=@begionTime and recordTime<=@endTime) and TFlag=@TFlag and Flag=@Flag order by " + sortby, conn); adapter.SelectCommand.Parameters.Add("@TFlag", TFlag); adapter.SelectCommand.Parameters.Add("@Flag", Flag); } adapter.SelectCommand.Parameters.Add("@begin", begion);//返回当前页行数 adapter.SelectCommand.Parameters.Add("@end", end); adapter.SelectCommand.Parameters.Add("@begionTime", begionDate.ToString());//返回当前页行数 adapter.SelectCommand.Parameters.Add("@endTime", endDate.ToString()); adapter.SelectCommand.Parameters.Add("@Content1matchString", temp); adapter.SelectCommand.Parameters.Add("@Titlematchstring", temp); string sql = adapter.SelectCommand.Sql; HubbleCommand cmd = new HubbleCommand(sql, conn); ds = cmd.Query(); } recCount = ds.Tables[0].MinimumCapacity;//返回总行书 foreach (System.Data.DataRow row in ds.Tables[0].Rows) { PublicOpnion.V_Sentiment V_Sentiment = new PublicOpnion.V_Sentiment(); V_Sentiment.Title = row["Title"].ToString(); V_Sentiment.Content1 = row["Content1"].ToString(); V_Sentiment.DocID = JSSDW.Utils.StringUtils.ToInt64(row["DocId"].ToString(), 0); V_Sentiment.ID = JSSDW.Utils.StringUtils.ToInt64(row["ID"].ToString(), 0); V_Sentiment.Flag = JSSDW.Utils.StringUtils.ToInt32(row["Flag"].ToString(),0); V_Sentiment.IDFlag = JSSDW.Utils.StringUtils.ToInt64(row["IDFlag"].ToString(), 0); V_Sentiment.IDFlag1 = JSSDW.Utils.StringUtils.ToInt64(row["IDFlag1"].ToString(), 0); V_Sentiment.Msexposure = row["Msexposure"].ToString(); V_Sentiment.Mstexposure = JSSDW.Utils.StringUtils.ToInt32(row["Mstexposure"].ToString(), 0); V_Sentiment.RecordDate = JSSDW.Utils.StringUtils.ToDateTime(row["RecordDate"].ToString(),DateTime.Now); V_Sentiment.RecordTime = JSSDW.Utils.StringUtils.ToDateTime(row["RecordTime"].ToString(), DateTime.Now); V_Sentiment.Rev = row["Rev"].ToString(); V_Sentiment.Samecount = JSSDW.Utils.StringUtils.ToInt32(row["Samecount"].ToString(),0); V_Sentiment.Score = JSSDW.Utils.StringUtils.ToInt64(row["Score"].ToString(), 0); V_Sentiment.Tflag = JSSDW.Utils.StringUtils.ToInt32(row["Tflag"].ToString(), 0); V_Sentiment.Url = row["Url"].ToString(); SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<font color=\"red\">", "</font>"); Highlighter titleHighlighter; Highlighter contentHighlighter; if (_TitleAnalyzerName.Equals("PanGuSegment", StringComparison.CurrentCultureIgnoreCase)) { titleHighlighter = new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer()); } else if (_TitleAnalyzerName.Equals("EnglishAnalyzer", StringComparison.CurrentCultureIgnoreCase)) { titleHighlighter = new Highlighter(simpleHTMLFormatter, new Hubble.Core.Analysis.EnglishAnalyzer()); } else { titleHighlighter = new Highlighter(simpleHTMLFormatter, new Hubble.Core.Analysis.SimpleAnalyzer()); } if (_ContentAnalyzerName.Equals("PanGuSegment", StringComparison.CurrentCultureIgnoreCase)) { contentHighlighter = new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer()); } else if (_ContentAnalyzerName.Equals("EnglishAnalyzer", StringComparison.CurrentCultureIgnoreCase)) { contentHighlighter = new Highlighter(simpleHTMLFormatter, new Hubble.Core.Analysis.EnglishAnalyzer()); } else { contentHighlighter = new Highlighter(simpleHTMLFormatter, new Hubble.Core.Analysis.SimpleAnalyzer()); } titleHighlighter.FragmentSize = 50; contentHighlighter.FragmentSize = 100; V_Sentiment.Title = titleHighlighter.GetBestFragment(temp, V_Sentiment.Title); V_Sentiment.Content1 = contentHighlighter.GetBestFragment(temp, V_Sentiment.Content1); //news.Abstract = contentHighlighter.GetBestFragment(keywords, news.Content); //news.TitleHighLighter = titleHighlighter.GetBestFragment(keywords, news.Title); if (string.IsNullOrEmpty(V_Sentiment.Title)) { V_Sentiment.Title = row["Title"].ToString(); } if (string.IsNullOrEmpty(V_Sentiment.Content1)) { V_Sentiment.Content1 = row["Content1"].ToString(); } result.Add(V_Sentiment); } return result; } #endregion
这里用到了hubble.net分词检索和全文索引,没有细细研究过。
jquery(Ajax)分页控件逻辑:通过取到总页数形成分页比如共有80条数据,每页十条数据,则可以形成0-7页,每次点击分页则会传入当前页,取出相应的数据绑定。今天学习就到这里。