ClassGetHAST2HTM.cs
上传用户:zhangkuixh
上传日期:2013-09-30
资源大小:5473k
文件大小:20k
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Collections;
- /*
- ' 迅龙中文分类搜索引擎 v0.6
- '
- ' LGPL 许可发行
- '
- ' 宁夏大学 张冬 康彩 zd4004@163.com
- '
- ' 官网 http://blog.163.com/zd4004/
- */
- namespace XunLong.SearchClassLibrary
- {
- /// <summary>
- /// 搜索 -- > 返回列表值
- /// </summary>
- public class ClassGetHAST2HTM
- {
- /// <summary>
- /// 搜索类
- /// </summary>
- private ClassSearchIT SearchIT = new ClassSearchIT();
- /// <summary>
- /// 帮定的地址 不含 http://
- /// </summary>
- public string HTTPURL = "";
- /// <summary>
- /// 随即
- /// </summary>
- System.Random myRandom = new Random();
- /// <summary>
- /// 编码
- /// </summary>
- NewNxuEncoding.CNewNxuEncoding mCode = new NewNxuEncoding.CNewNxuEncoding();
- /// <summary>
- ///
- /// </summary>
- /// <param name="path"></param>
- public void init(string path)
- {
- SearchIT.k_c_path = path;
- SearchIT.ClassSearchIT_1();
- }
- /// <summary>
- /// 得到分页显示的数据
- /// </summary>
- /// <param name="urldat"></param>
- /// <returns></returns>
- public string GetData(string urldat, int n, string mainType)
- {
- int StartTime = Environment.TickCount;
- //xl
- urldat = urldat.ToLower();
- // dat =<XL>关键词</XL>;
- string data_source = "";
- int one_a1 = urldat.IndexOf("<xl>");
- int one_a2 = urldat.IndexOf("</xl>");
- if (one_a2 > one_a1 & one_a1 > -1)
- {
- data_source = urldat.Substring(one_a1 + 4, one_a2 - one_a1 - 4);
- }
-
- string DAT_BK = ""; ;
- Hashtable c = SearchIT.search_GetData(urldat, n);
- int ALLNUM= (int)c["SYS_ALLNUM"] ;
- int nn = (int)c["SYS_N"];
- string olddat = (string )c["SYS_DAT"];
- ArrayList resultTmpSet = (ArrayList)c["SYS_LIST"];
- if (resultTmpSet.Count == 0)
- {
- return "Sorry 没有找到符合条件的数据 <p>" + olddat+"</p>";
- }
- string[] newHtmlList = new string[resultTmpSet.Count];
- int cc_i = 0;
- string[] SearchWords = new string[10];
- //合成各个单个数据
- foreach (XunLong.PublicClassLibrary.ShowLISTONE cc in resultTmpSet)
- {
- string cc_tmp = "<table width="820" border="0" cellpadding="0" cellspacing="0">";
- cc_tmp = cc_tmp + "<tr><td colspan="2"><span class="style1">" + "<p><A href="" + cc.url + "" target="_blank" >" + HighLight(cc.title, SearchWords, 50) + "</A></p>" + "</span></td></tr>rn";
- cc_tmp = cc_tmp + "<tr><td colspan="2">" + "<p>" + HighLight(cc.data, SearchWords, 140) + "</p>" + "</td></tr>rn";
- cc_tmp = cc_tmp + "<tr><td width="700"><span class="style2">" + "<p><A href="" + cc.url + "" target="_blank" >" + HighLight(cc.url, SearchWords, 50) + "</A></p>" + "</span></td>rn";
- // cc_tmp = cc_tmp + "<td width="42"><span class="style3"><a href="show?url="+cc.url+"" target="_blank">[SHOW]</a></span></td>rn";
- cc_tmp = cc_tmp + "<td width="42"></td>rn";
- cc_tmp = cc_tmp + "</tr></table>"+"rn";
- newHtmlList[cc_i] = cc_tmp;
- cc_i = cc_i + 1;
- }
- //合成HTML 多个数据
- string MuData = "<table align="center" width="820" border="0">"+"rn";
- foreach (string cc_one in newHtmlList)
- {
- MuData = MuData + "<tr><td>" + cc_one + "</td></tr>rn"+ "<tr><td></td></tr>rn";
- }
- MuData = MuData + "</table>";
- DAT_BK = DAT_BK + "<html>"+"rn";
- DAT_BK = DAT_BK + "<head>"+"rn";
- DAT_BK = DAT_BK + "<meta http-equiv="Content-Type" content="text/html; charset=gb2312">"+"rn";
- int UserTime =(Environment.TickCount - StartTime)/10;
- double UserTime_d = (double)UserTime / 1000+0.013;
- string TongJiNum = "共搜索得到数据 " + ALLNUM.ToString() + " 条 消耗时间 " + UserTime_d.ToString() + " 秒";
- DAT_BK = DAT_BK + "<title>ONE1内容 "+ urldat+"</title>"+"rn";
- DAT_BK = DAT_BK + "<style type="text/css">"+"rn";
- DAT_BK = DAT_BK + "<!--"+"rn";
- DAT_BK = DAT_BK + ".style1 {color: #0000FF}"+"rn";
- DAT_BK = DAT_BK + ".style2 {color: #006600}"+"rn";
- DAT_BK = DAT_BK + ".style3 {color: #999999}"+"rn";
- DAT_BK = DAT_BK + "-->"+"rn";
- DAT_BK = DAT_BK + "</style>"+"rn";
- DAT_BK = DAT_BK + "</head>" + "rn";
- DAT_BK = DAT_BK + "<!--script begin--><SCRIPT language=JavaScript>"+"rn";
- DAT_BK = DAT_BK + "<!--"+"rn";
- DAT_BK = DAT_BK + "function SearchOneData(XL)"+"rn";
- DAT_BK = DAT_BK + "{ "+"rn";
- DAT_BK = DAT_BK + "var A1 = HID.value; "+"rn";
- DAT_BK = DAT_BK + "frames.top.frames["one1"].document.location.href = "http://" + HTTPURL + "/one1?wd="+A1+"&<nn>"+XL+"</nn>"+ mainType+""; " + "rn";
- DAT_BK = DAT_BK + "}"+"rn";
- DAT_BK = DAT_BK + "//-->"+"rn";
- DAT_BK = DAT_BK + "</SCRIPT>"+"rn";
- DAT_BK = DAT_BK + "<body>"+"rn";
- DAT_BK = DAT_BK + TongJiNum + "rn";
- DAT_BK = DAT_BK + ""+"rn";
-
- DAT_BK = DAT_BK + MuData +"rn";
- // DAT_BK = DAT_BK + "<p> </p>"+"rn";
- DAT_BK = DAT_BK + "<input name="hiddenField" ID="hiddenField" type="hidden" value="<xl>" + data_source + "</xl>" id ="HID">" + "rn";
- string linkList = "";
- int CoPage = 0;
- if (ALLNUM % 10 == 0)
- {
- CoPage = ALLNUM / 10;
- }
- else
- {
- CoPage = ALLNUM / 10 + 1;
- }
- //合成链接
- for (int i = 1; i <= CoPage; i++)
- {
- if ((i >= n - 5) & (i <= n + 8))
- {
- if (i == n)
- {
- linkList = linkList + " " + i.ToString();
- }
- else
- {
- linkList = linkList + " " + "<a href="one1?wd=" + urldat + "<nn>" + i.ToString() + "</nn>"+ mainType + "">" + i.ToString() + "</a>";
- }
- }
- }
- DAT_BK = DAT_BK + "<p><div align="center" class="style12">" + linkList + "</div></p>" + "rn";
- DAT_BK = DAT_BK + "<p><div align="center" class="style12">©<a href="http://www.liebiao.net" target="_blank">2006 列表网(www.liebiao.net)</a> </div></p>" + "rn";
- DAT_BK = DAT_BK + "</body>"+"rn";
- DAT_BK = DAT_BK + "</html>";
- return DAT_BK;
- }
- /// <summary>
- /// 得到头 + 可选列表数据
- /// </summary>
- /// <param name="urldat"></param>
- /// <returns></returns>
- public string GetRESLIST(string urldat, string mainType)
- {
- urldat = urldat.ToLower().Trim();
- string data_source = "";
- int one_a1 = urldat.IndexOf("<xl>");
- int one_a2 = urldat.IndexOf("</xl>");
- if (one_a2 > one_a1 & one_a1 > -1)
- {
- data_source = urldat.Substring(one_a1 + 4, one_a2 - one_a1 - 4);
- }
- Hashtable c = SearchIT.search_GetRESLIST(urldat,mainType);
- //合成的列表项
- ArrayList ListHTML = new ArrayList(); ;
- ListHTML.Clear();
- //记录各个属性项
- string[] list_label = new string[4];
- // 显示选择列表的数目
- int SelectNum = 0;
- //整理列表 暂时不进行排序
- foreach (System.Collections.DictionaryEntry de in c)
- {
- list_label[SelectNum] = de.Key.ToString();
- SelectNum = SelectNum + 1;
- string OneListHTML = "";// "<p>" + "rn";
- OneListHTML = OneListHTML + " <label>" + de.Key.ToString() + "</label>" + "rn";
- //OneListHTML = OneListHTML + "<input name="selectLabel" + SelectNum.ToString() + "" type="hidden" value="" + de.Key.ToString() + "" id ="selectLabel" + SelectNum.ToString() + "">" + "rn";
- OneListHTML = OneListHTML + " <select name="select" + SelectNum.ToString() + "" id="select" + SelectNum.ToString() + "">" + "rn";
- OneListHTML = OneListHTML + " <option value="---">" + "---" + "</option>" + "rn";
- XunLong.PublicClassLibrary.XLSX deOne = (XunLong.PublicClassLibrary.XLSX)de.Value;
- Hashtable listOne = (Hashtable)deOne.vs;
- foreach (System.Collections.DictionaryEntry de2 in listOne)
- {
- if (de2.Key.ToString().Length < 30)
- {
- OneListHTML = OneListHTML + " <option value="" + de2.Key.ToString() + "">" + de2.Key.ToString() + "</option>" + "rn";
- }
- }
- OneListHTML = OneListHTML + " </select>" + "rn";
- // OneListHTML = OneListHTML + "</p>" + "rn";
- try
- {
- ListHTML.Add(OneListHTML);
- }
- catch
- { }
- }
- /*
- //只列出4个属性
- string TableList = "";
- TableList = TableList + " <table width="50%" border="0" align="center" cellpadding="1" cellspacing="1">" + "rn";
- TableList = TableList + " <tr>" + "rn";
- TableList = TableList + " <td align="left">A_1</td>" + "rn";
- TableList = TableList + " <td align="left">A_2</td>" + "rn";
- TableList = TableList + " </tr>" + "rn";
- TableList = TableList + " <tr>" + "rn";
- TableList = TableList + " <td align="left">A_3</td>" + "rn";
- string List_Search_HTML = "<a href="javascript:SerachList();">搜索</a>" + "rn"; //搜索按钮
- if (SelectNum > 0)
- {
- TableList = TableList + " <td align="left">A_4 " + List_Search_HTML + "</td>" + "rn";
- }
- else
- {
- TableList = TableList + " <td align="left">A_4</td>" + "rn";
- }
- TableList = TableList + " </tr>" + "rn";
- TableList = TableList + " </table>" + "rn";
- */
- string List_Search_HTML = "<a href="javascript:SerachList();">搜索</a>" + "rn"; //搜索按钮
- string TableList = "";
- TableList = TableList + " <table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">" + "rn";
- TableList = TableList + " <tr>" + "rn";
- if (SelectNum > 0)
- {
- TableList = TableList + " <td align="center">A_1    A_2    A_3    A_4 " + List_Search_HTML + "</td>" + "rn";
- }
- else
- {
- TableList = TableList + " <td align="center">A_1    A_2    A_3    A_4 </td>" + "rn";
- }
- TableList = TableList + " </tr>" + "rn";
- // string List_Search_HTML = "<a href="javascript:SerachList();">搜索</a>" + "rn"; //搜索按钮
- TableList = TableList + " </table>" + "rn";
- for (int i = 1; i <= 4; i++)
- {
- try
- {
- TableList = TableList.Replace("A_" + i.ToString(), ListHTML[i - 1].ToString());
- }
- catch
- {
- TableList = TableList.Replace("A_" + i.ToString(), "");
- }
- }
- //合成属性搜索
- string List_Search_Data = "";
- string mainType_new = "<xl>" + data_source + "</xl>" + mainType;
- switch (SelectNum)
- {
- case 0:
- List_Search_Data = "";
- break;
- case 1:
- List_Search_Data = List_Search_Data + "function SerachList()" + "rn";
- List_Search_Data = List_Search_Data + " {" + "rn";
- List_Search_Data = List_Search_Data + " var x_1 = "<" + list_label[0] + ">" + select1.value + "</" + list_label[0] + ">"" + "rn";
- List_Search_Data = List_Search_Data + " frames.top.frames["one1"].document.location.href ="one1?wd="+x_1 +"" + mainType_new + "";rn";
- List_Search_Data = List_Search_Data + " }" + "rn";
- break;
- case 2:
- List_Search_Data = List_Search_Data + "function SerachList()" + "rn";
- List_Search_Data = List_Search_Data + " {" + "rn";
- List_Search_Data = List_Search_Data + " var x_1 = "<" + list_label[0] + ">" + select1.value + "</" + list_label[0] + ">" + "";rn";
- List_Search_Data = List_Search_Data + " x_1 = x_1 + "<" + list_label[1] + ">" + select2.value + "</" + list_label[1] + ">" + "";rn";
- List_Search_Data = List_Search_Data + " frames.top.frames["one1"].document.location.href ="one1?wd="+x_1 +"" + mainType_new + "";rn";
- List_Search_Data = List_Search_Data + " }" + "rn";
- break;
- case 3:
- List_Search_Data = List_Search_Data + "function SerachList()" + "rn";
- List_Search_Data = List_Search_Data + " {" + "rn";
- List_Search_Data = List_Search_Data + " var x_1 = "<" + list_label[0] + ">" + select1.value + "</" + list_label[0] + ">" + "";rn";
- List_Search_Data = List_Search_Data + " x_1 = x_1 + "<" + list_label[1] + ">" + select2.value + "</" + list_label[1] + ">" + "";rn";
- List_Search_Data = List_Search_Data + " x_1 = x_1 + "<" + list_label[2] + ">" + select3.value + "</" + list_label[2] + ">" + "";rn";
- List_Search_Data = List_Search_Data + " frames.top.frames["one1"].document.location.href ="one1?wd="+x_1 + "" + mainType_new + "";rn";
- List_Search_Data = List_Search_Data + " }" + "rn";
- break;
- case 4:
- List_Search_Data = List_Search_Data + "function SerachList()" + "rn";
- List_Search_Data = List_Search_Data + " {" + "rn";
- List_Search_Data = List_Search_Data + " var x_1 = "<" + list_label[0] + ">" + select1.value + "</" + list_label[0] + ">" + "";rn";
- List_Search_Data = List_Search_Data + " x_1 = x_1 + "<" + list_label[1] + ">" + select2.value + "</" + list_label[1] + ">" + "";rn";
- List_Search_Data = List_Search_Data + " x_1 = x_1 + "<" + list_label[2] + ">" + select3.value + "</" + list_label[2] + ">" + "";rn";
- List_Search_Data = List_Search_Data + " x_1 = x_1 + "<" + list_label[3] + ">" + select4.value + "</" + list_label[3] + ">" + "";rn";
- List_Search_Data = List_Search_Data + " frames.top.frames["one1"].document.location.href ="one1?wd="+x_1 + "" + mainType_new + "";rn";
- List_Search_Data = List_Search_Data + " }" + "rn";
- break;
-
- }
- string SCRIPT_CODE = "";
- SCRIPT_CODE = SCRIPT_CODE +" <script language="javascript">" + "rn";
- //主搜索
- SCRIPT_CODE = SCRIPT_CODE +" function SerachOne()" + "rn";
- SCRIPT_CODE = SCRIPT_CODE +" {" + "rn";
- // SCRIPT_CODE = SCRIPT_CODE +" window.location.href = "s?wd=<XL>"+ wdd.value +"</XL>"+ mainType +""" + ";" + "rn";
- SCRIPT_CODE = SCRIPT_CODE + " frames.top.frames["one1"].document.location.href = "one1?wd=<xl>"+ wdd.value +"</xl>" + mainType + """ + ";" + "rn";
- SCRIPT_CODE = SCRIPT_CODE + " frames.top.frames["one2"].document.location.href = "one2?wd=<xl>"+ wdd.value +"</xl>" + mainType + """ + ";" + "rn";
-
- SCRIPT_CODE = SCRIPT_CODE +" }" + "rn";
- //属性搜索融合
- SCRIPT_CODE = SCRIPT_CODE + List_Search_Data + "rn";
-
- SCRIPT_CODE = SCRIPT_CODE +" </script> " + "rn";
- string One2HTML ="";
- One2HTML=One2HTML+"<html>" + "rn";
- One2HTML=One2HTML+"<head>" + "rn";
- One2HTML=One2HTML+"<meta http-equiv="Content-Type" content="text/html; charset=gb2312">" + "rn";
- One2HTML = One2HTML + "<title>列表网 " + data_source + " </title>" + "rn";
- One2HTML = One2HTML + "<style type="text/css">" + "rn";
- One2HTML = One2HTML + "<!--" + "rn";
- One2HTML = One2HTML + "body {" + "rn";
- // One2HTML = One2HTML + " background-color: #E8F3F9;" + "rn";
- One2HTML = One2HTML + " background-color: #F7F4F7;" + "rn";
- One2HTML = One2HTML + "}" + "rn";
- One2HTML = One2HTML + ".style2 {" + "rn";
- One2HTML = One2HTML + "font-size: 24px;" + "rn";
- One2HTML = One2HTML + "font-weight: bold;" + "rn";
- One2HTML = One2HTML + "color: #000099;" + "rn";
- One2HTML = One2HTML + "}" + "rn";
- One2HTML = One2HTML + "-->" + "rn";
- One2HTML = One2HTML + "</style>" + "rn";
- One2HTML=One2HTML+"</head>" + "rn";
- One2HTML = One2HTML + SCRIPT_CODE + "rn";
- string mainTypeOne = mainType.Replace("&czd=", "");
- One2HTML=One2HTML+"<body>" + "rn";
- One2HTML = One2HTML + "<p><span class="style2"><a href="http://www.liebiao.net" target="_blank">列表网</a>-" + mainTypeOne + " </span>rn";
- One2HTML=One2HTML+"" + "rn";
- One2HTML = One2HTML + " <input type="text" name="wdd" id="wdd" value="" + data_source + "" > " + "rn";
- One2HTML=One2HTML+"<a href="javascript:SerachOne();">列表搜索</a></p>" + "rn";
- One2HTML = One2HTML + " <p align="center">" + TableList + "</p>" + "rn";
- One2HTML=One2HTML+"</body>" + "rn";
- One2HTML=One2HTML + "</html>" + "rn";
- //排序 合成HTML
- return One2HTML;
- }
- /// <summary>
- /// 高亮和截取
- /// </summary>
- /// <param name="data">数据</param>
- /// <param name="word">需要加亮的词</param>
- /// <param name="Len">截取后的长度</param>
- /// <returns>高亮和截取</returns>
- public string HighLight(string data, string[] word, int Len)
- {
- if (data.Length <= Len)
- {
- return data;
- }
- else
- {
- return data.Substring(0, Len);
- }
- }
- }
- }