ClassGetHAST2HTM.cs
上传用户:zhangkuixh
上传日期:2013-09-30
资源大小:5473k
文件大小:20k
源码类别:

搜索引擎

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Collections;
  5. /*
  6.       '       迅龙中文分类搜索引擎  v0.6
  7.       '
  8.       '        LGPL  许可发行
  9.       '
  10.       '       宁夏大学  张冬 康彩  zd4004@163.com
  11.       ' 
  12.       '        官网 http://blog.163.com/zd4004/
  13.  */
  14. namespace XunLong.SearchClassLibrary
  15. {
  16.     /// <summary>
  17.     /// 搜索 -- >  返回列表值 
  18.     /// </summary>
  19.    public  class ClassGetHAST2HTM
  20.     {
  21.        /// <summary>
  22.        /// 搜索类
  23.        /// </summary>
  24.         private  ClassSearchIT SearchIT = new  ClassSearchIT();
  25.        /// <summary>
  26.        /// 帮定的地址 不含 http://
  27.        /// </summary>
  28.       public  string HTTPURL = "";
  29.        /// <summary>
  30.        /// 随即
  31.        /// </summary>
  32.        System.Random myRandom = new Random();
  33.        /// <summary>
  34.        /// 编码
  35.        /// </summary>
  36.        NewNxuEncoding.CNewNxuEncoding mCode = new NewNxuEncoding.CNewNxuEncoding();
  37.        /// <summary>
  38.        /// 
  39.        /// </summary>
  40.        /// <param name="path"></param>
  41.        public void init(string path)
  42.        {
  43.            SearchIT.k_c_path = path;
  44.            SearchIT.ClassSearchIT_1();  
  45.        }
  46.         /// <summary>
  47.         /// 得到分页显示的数据
  48.         /// </summary>
  49.         /// <param name="urldat"></param>
  50.         /// <returns></returns>
  51.        public string GetData(string urldat, int n, string mainType)
  52.         {
  53.             int StartTime = Environment.TickCount;
  54.            //xl
  55.             urldat = urldat.ToLower();
  56.             // dat =<XL>关键词</XL>;
  57.             string data_source = "";
  58.             int one_a1 = urldat.IndexOf("<xl>");
  59.             int one_a2 = urldat.IndexOf("</xl>");
  60.             if (one_a2 > one_a1 & one_a1 > -1)
  61.             {
  62.                 data_source = urldat.Substring(one_a1 + 4, one_a2 - one_a1 - 4);             
  63.             }
  64.             
  65.             string DAT_BK = ""; ;
  66.             Hashtable c = SearchIT.search_GetData(urldat, n);
  67.             int ALLNUM= (int)c["SYS_ALLNUM"] ;
  68.             int nn =  (int)c["SYS_N"];
  69.             string  olddat = (string )c["SYS_DAT"];
  70.             ArrayList resultTmpSet = (ArrayList)c["SYS_LIST"];
  71.             if (resultTmpSet.Count == 0)
  72.             {
  73.                 return "Sorry 没有找到符合条件的数据 <p>" + olddat+"</p>";
  74.             }
  75.             string[] newHtmlList = new string[resultTmpSet.Count];
  76.             int cc_i = 0;
  77.             string[] SearchWords = new string[10];
  78.             //合成各个单个数据
  79.             foreach (XunLong.PublicClassLibrary.ShowLISTONE cc in resultTmpSet)
  80.             {
  81.                 string cc_tmp = "<table width="820"  border="0" cellpadding="0" cellspacing="0">";
  82.                 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";
  83.                 cc_tmp = cc_tmp + "<tr><td colspan="2">" + "<p>" + HighLight(cc.data, SearchWords, 140) + "</p>" + "</td></tr>rn";
  84.                 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";
  85.                // cc_tmp = cc_tmp + "<td width="42"><span class="style3"><a href="show?url="+cc.url+"" target="_blank">[SHOW]</a></span></td>rn";
  86.                 cc_tmp = cc_tmp + "<td width="42"></td>rn";
  87.                 cc_tmp = cc_tmp + "</tr></table>"+"rn";
  88.                 newHtmlList[cc_i] = cc_tmp;
  89.                 cc_i = cc_i + 1;
  90.             }
  91.             //合成HTML 多个数据
  92.             string MuData = "<table  align="center" width="820" border="0">"+"rn";
  93.             foreach (string cc_one in newHtmlList)
  94.             {
  95.                 MuData = MuData + "<tr><td>" + cc_one + "</td></tr>rn"+ "<tr><td></td></tr>rn";           
  96.             }
  97.             MuData = MuData + "</table>";
  98.            DAT_BK =   DAT_BK + "<html>"+"rn";
  99.            DAT_BK =   DAT_BK + "<head>"+"rn";
  100.            DAT_BK =   DAT_BK + "<meta http-equiv="Content-Type" content="text/html; charset=gb2312">"+"rn";
  101.            int UserTime =(Environment.TickCount - StartTime)/10;
  102.            double UserTime_d = (double)UserTime / 1000+0.013;
  103.            string TongJiNum = "共搜索得到数据 " + ALLNUM.ToString() + " 条  消耗时间 " + UserTime_d.ToString() + "  秒";
  104.            DAT_BK =   DAT_BK + "<title>ONE1内容 "+ urldat+"</title>"+"rn";
  105.            DAT_BK =   DAT_BK + "<style type="text/css">"+"rn";
  106.            DAT_BK =   DAT_BK + "<!--"+"rn";
  107.            DAT_BK =   DAT_BK + ".style1 {color: #0000FF}"+"rn";
  108.            DAT_BK =   DAT_BK + ".style2 {color: #006600}"+"rn";
  109.            DAT_BK =   DAT_BK + ".style3 {color: #999999}"+"rn";
  110.            DAT_BK =   DAT_BK + "-->"+"rn";
  111.            DAT_BK =   DAT_BK + "</style>"+"rn";
  112.            DAT_BK = DAT_BK + "</head>" + "rn";
  113.            DAT_BK =   DAT_BK + "<!--script begin--><SCRIPT language=JavaScript>"+"rn";
  114.            DAT_BK =   DAT_BK + "<!--"+"rn";
  115.            DAT_BK =   DAT_BK + "function SearchOneData(XL)"+"rn";
  116.            DAT_BK =   DAT_BK + "{ "+"rn";
  117.            DAT_BK =   DAT_BK + "var  A1 = HID.value; "+"rn";
  118.            DAT_BK = DAT_BK + "frames.top.frames["one1"].document.location.href = "http://" + HTTPURL + "/one1?wd="+A1+"&<nn>"+XL+"</nn>"+ mainType+"";  " + "rn";
  119.            DAT_BK =   DAT_BK + "}"+"rn";
  120.            DAT_BK =   DAT_BK + "//-->"+"rn";
  121.            DAT_BK =   DAT_BK + "</SCRIPT>"+"rn";
  122.            DAT_BK =   DAT_BK + "<body>"+"rn";
  123.            DAT_BK = DAT_BK + TongJiNum + "rn";
  124.            DAT_BK =   DAT_BK + ""+"rn";
  125.           
  126.              DAT_BK = DAT_BK +  MuData +"rn";
  127.          //  DAT_BK =   DAT_BK + "<p>&nbsp;</p>"+"rn";
  128.            DAT_BK = DAT_BK + "<input name="hiddenField" ID="hiddenField" type="hidden" value="<xl>" + data_source + "</xl>"  id ="HID">" + "rn";
  129.            string linkList = "";
  130.            int CoPage = 0;
  131.            if (ALLNUM % 10 == 0)
  132.            {
  133.                CoPage = ALLNUM / 10;
  134.            }
  135.            else
  136.            {
  137.                CoPage = ALLNUM / 10 + 1;
  138.            }
  139.             //合成链接
  140.            for (int i = 1; i <= CoPage; i++)
  141.            {
  142.                if ((i >= n - 5) & (i <= n  + 8))
  143.                {
  144.                    if (i == n)
  145.                    {
  146.                        linkList = linkList + "  " + i.ToString();
  147.                    }
  148.                    else
  149.                    {
  150.                        linkList = linkList + "&nbsp;" + "<a href="one1?wd=" + urldat + "<nn>" + i.ToString() + "</nn>"+ mainType + "">" + i.ToString() + "</a>";
  151.                    }
  152.                }
  153.            }
  154.            DAT_BK = DAT_BK + "<p><div align="center" class="style12">" + linkList + "</div></p>" + "rn";
  155.            DAT_BK = DAT_BK + "<p><div align="center" class="style12">&copy;<a href="http://www.liebiao.net" target="_blank">2006 列表网(www.liebiao.net)</a> </div></p>" + "rn";
  156.            DAT_BK =   DAT_BK + "</body>"+"rn";
  157.            DAT_BK =   DAT_BK + "</html>";
  158.             return DAT_BK;
  159.         }
  160.         /// <summary>
  161.         /// 得到头 +   可选列表数据
  162.         /// </summary>
  163.         /// <param name="urldat"></param>
  164.         /// <returns></returns>
  165.        public string GetRESLIST(string urldat, string mainType)
  166.         {
  167.             urldat = urldat.ToLower().Trim();
  168.             string data_source = "";
  169.             int one_a1 = urldat.IndexOf("<xl>");
  170.             int one_a2 = urldat.IndexOf("</xl>");
  171.             if (one_a2 > one_a1 & one_a1 > -1)
  172.             {
  173.                 data_source = urldat.Substring(one_a1 + 4, one_a2 - one_a1 - 4);
  174.             }
  175.             Hashtable c = SearchIT.search_GetRESLIST(urldat,mainType);
  176.            //合成的列表项
  177.             ArrayList ListHTML = new ArrayList(); ;
  178.             ListHTML.Clear();
  179.            //记录各个属性项
  180.             string[] list_label = new string[4];
  181.             // 显示选择列表的数目
  182.             int SelectNum = 0;
  183.             //整理列表  暂时不进行排序
  184.             foreach (System.Collections.DictionaryEntry de in c)
  185.             {
  186.                 list_label[SelectNum] = de.Key.ToString();
  187.                 SelectNum = SelectNum + 1;
  188.                 string OneListHTML = "";// "<p>" + "rn";      
  189.                 OneListHTML = OneListHTML + " <label>" + de.Key.ToString() + "</label>" + "rn";
  190.                 //OneListHTML = OneListHTML + "<input  name="selectLabel" + SelectNum.ToString() + "" type="hidden" value="" + de.Key.ToString() + ""  id ="selectLabel" + SelectNum.ToString() + "">" + "rn";
  191.                 OneListHTML = OneListHTML + " <select name="select" + SelectNum.ToString() + "" id="select" + SelectNum.ToString() + "">" + "rn";
  192.                 OneListHTML = OneListHTML + "    <option value="---">" + "---" + "</option>" + "rn";
  193.                 XunLong.PublicClassLibrary.XLSX  deOne = (XunLong.PublicClassLibrary.XLSX)de.Value;
  194.                 Hashtable listOne = (Hashtable)deOne.vs;
  195.                 foreach (System.Collections.DictionaryEntry de2 in listOne)
  196.                 {
  197.                     if (de2.Key.ToString().Length < 30)
  198.                     {
  199.                         OneListHTML = OneListHTML + "    <option value="" + de2.Key.ToString() + "">" + de2.Key.ToString() + "</option>" + "rn";
  200.                     }
  201.                 }
  202.                 OneListHTML = OneListHTML + " </select>" + "rn";
  203.                // OneListHTML = OneListHTML + "</p>" + "rn";
  204.                 try
  205.                 {
  206.                     ListHTML.Add(OneListHTML);
  207.                 }
  208.                 catch
  209.                 { }
  210.             }
  211.            /*
  212.            //只列出4个属性
  213.             string TableList = "";
  214.             TableList = TableList + " <table width="50%"  border="0" align="center" cellpadding="1" cellspacing="1">" + "rn";
  215.             TableList = TableList + "   <tr>" + "rn";
  216.             TableList = TableList + "     <td align="left">A_1</td>" + "rn";
  217.             TableList = TableList + "     <td align="left">A_2</td>" + "rn";
  218.             TableList = TableList + "   </tr>" + "rn";
  219.             TableList = TableList + "   <tr>" + "rn";
  220.             TableList = TableList + "     <td align="left">A_3</td>" + "rn";
  221.             string List_Search_HTML = "<a href="javascript:SerachList();">搜索</a>" + "rn"; //搜索按钮
  222.             if (SelectNum > 0)
  223.             {            
  224.                 TableList = TableList + "     <td  align="left">A_4 " + List_Search_HTML + "</td>" + "rn";
  225.             }
  226.             else
  227.             { 
  228.                 TableList = TableList + "     <td  align="left">A_4</td>" + "rn";            
  229.             }
  230.             TableList = TableList + "   </tr>" + "rn";
  231.             TableList = TableList + " </table>" + "rn";
  232.            */
  233.             string List_Search_HTML = "<a href="javascript:SerachList();">搜索</a>" + "rn"; //搜索按钮
  234.             string TableList = "";
  235.             TableList = TableList + " <table width="100%"  border="0" align="center" cellpadding="1" cellspacing="1">" + "rn";
  236.             TableList = TableList + "   <tr>" + "rn";
  237.             if (SelectNum > 0)
  238.             {
  239.                 TableList = TableList + "     <td  align="center">A_1 &nbsp&nbsp A_2 &nbsp&nbsp A_3 &nbsp&nbsp A_4 " + List_Search_HTML + "</td>" + "rn";
  240.             }
  241.             else
  242.             {
  243.                 TableList = TableList + "     <td  align="center">A_1 &nbsp&nbsp A_2 &nbsp&nbsp A_3 &nbsp&nbsp A_4 </td>" + "rn";
  244.             }
  245.             TableList = TableList + "   </tr>" + "rn";
  246.          //   string List_Search_HTML = "<a href="javascript:SerachList();">搜索</a>" + "rn"; //搜索按钮
  247.             TableList = TableList + " </table>" + "rn";
  248.             for (int i = 1; i <= 4; i++)
  249.             {
  250.                 try
  251.                 {
  252.                     TableList = TableList.Replace("A_" + i.ToString(), ListHTML[i - 1].ToString());
  253.                 }
  254.                 catch
  255.                 {
  256.                     TableList = TableList.Replace("A_" + i.ToString(), "");
  257.                 }          
  258.             }
  259.             //合成属性搜索
  260.             string List_Search_Data = "";
  261.             string  mainType_new = "<xl>" + data_source + "</xl>" + mainType;
  262.             switch (SelectNum)
  263.             { 
  264.                 case 0:
  265.                     List_Search_Data = "";
  266.                     break;
  267.                 case 1:
  268.                     List_Search_Data = List_Search_Data + "function SerachList()" + "rn";
  269.                     List_Search_Data = List_Search_Data + "    {" + "rn";
  270.                     List_Search_Data = List_Search_Data + "        var x_1 = "<" + list_label[0] + ">" + select1.value + "</" + list_label[0] + ">"" + "rn";
  271.                     List_Search_Data = List_Search_Data + "        frames.top.frames["one1"].document.location.href ="one1?wd="+x_1 +"" + mainType_new + "";rn";
  272.                     List_Search_Data = List_Search_Data + "    }" + "rn";
  273.                     break;
  274.                 case 2:
  275.                     List_Search_Data = List_Search_Data + "function SerachList()" + "rn";
  276.                     List_Search_Data = List_Search_Data + "    {" + "rn";
  277.                     List_Search_Data = List_Search_Data + "        var x_1 = "<" + list_label[0] + ">" + select1.value + "</" + list_label[0] + ">" + "";rn";
  278.                     List_Search_Data = List_Search_Data + "         x_1 = x_1 + "<" + list_label[1] + ">" + select2.value + "</" + list_label[1] + ">" + "";rn";
  279.                     List_Search_Data = List_Search_Data + "        frames.top.frames["one1"].document.location.href ="one1?wd="+x_1 +"" + mainType_new + "";rn";
  280.                     List_Search_Data = List_Search_Data + "    }" + "rn";
  281.                     break;
  282.                 case 3:
  283.                     List_Search_Data = List_Search_Data + "function SerachList()" + "rn";
  284.                     List_Search_Data = List_Search_Data + "    {" + "rn";
  285.                     List_Search_Data = List_Search_Data + "        var x_1 = "<" + list_label[0] + ">" + select1.value + "</" + list_label[0] + ">" + "";rn";
  286.                     List_Search_Data = List_Search_Data + "         x_1 = x_1 + "<" + list_label[1] + ">" + select2.value + "</" + list_label[1] + ">" + "";rn";
  287.                     List_Search_Data = List_Search_Data + "         x_1 = x_1 + "<" + list_label[2] + ">" + select3.value + "</" + list_label[2] + ">" + "";rn";
  288.                     List_Search_Data = List_Search_Data + "        frames.top.frames["one1"].document.location.href ="one1?wd="+x_1 + "" + mainType_new + "";rn";
  289.                     List_Search_Data = List_Search_Data + "    }" + "rn";
  290.                     break;
  291.                 case 4:
  292.                     List_Search_Data = List_Search_Data + "function SerachList()" + "rn";
  293.                     List_Search_Data = List_Search_Data + "    {" + "rn";
  294.                     List_Search_Data = List_Search_Data + "        var x_1 = "<" + list_label[0] + ">" + select1.value + "</" + list_label[0] + ">" + "";rn";
  295.                     List_Search_Data = List_Search_Data + "         x_1 = x_1 + "<" + list_label[1] + ">" + select2.value + "</" + list_label[1] + ">" + "";rn";
  296.                     List_Search_Data = List_Search_Data + "         x_1 = x_1 + "<" + list_label[2] + ">" + select3.value + "</" + list_label[2] + ">" + "";rn";
  297.                     List_Search_Data = List_Search_Data + "         x_1 = x_1 + "<" + list_label[3] + ">" + select4.value + "</" + list_label[3] + ">" + "";rn";
  298.                     List_Search_Data = List_Search_Data + "        frames.top.frames["one1"].document.location.href ="one1?wd="+x_1 + "" + mainType_new + "";rn";
  299.                     List_Search_Data = List_Search_Data + "    }" + "rn";
  300.                     break;                                
  301.             
  302.             }
  303.             string SCRIPT_CODE = "";
  304.        SCRIPT_CODE = SCRIPT_CODE +"    <script language="javascript">" + "rn";
  305.        //主搜索
  306.        SCRIPT_CODE = SCRIPT_CODE +"    function SerachOne()" + "rn";
  307.        SCRIPT_CODE = SCRIPT_CODE +"    {" + "rn";
  308.       // SCRIPT_CODE = SCRIPT_CODE +"          window.location.href  = "s?wd=<XL>"+ wdd.value  +"</XL>"+ mainType  +""" + ";" + "rn";
  309.        SCRIPT_CODE = SCRIPT_CODE + "         frames.top.frames["one1"].document.location.href = "one1?wd=<xl>"+ wdd.value  +"</xl>" + mainType + """ + ";" + "rn";
  310.        SCRIPT_CODE = SCRIPT_CODE + "         frames.top.frames["one2"].document.location.href = "one2?wd=<xl>"+ wdd.value  +"</xl>" + mainType + """ + ";" + "rn";
  311.       
  312.        SCRIPT_CODE = SCRIPT_CODE +"    }" + "rn";
  313.        //属性搜索融合
  314.        SCRIPT_CODE = SCRIPT_CODE + List_Search_Data + "rn";
  315.      
  316.        SCRIPT_CODE = SCRIPT_CODE +"   </script> " + "rn";
  317.            string One2HTML ="";
  318.            One2HTML=One2HTML+"<html>" + "rn";
  319.            One2HTML=One2HTML+"<head>" + "rn";
  320.            One2HTML=One2HTML+"<meta http-equiv="Content-Type" content="text/html; charset=gb2312">" + "rn";
  321.            One2HTML = One2HTML + "<title>列表网 " + data_source + "  </title>" + "rn";
  322.            One2HTML = One2HTML + "<style type="text/css">" + "rn";
  323.            One2HTML = One2HTML + "<!--" + "rn";
  324.            One2HTML = One2HTML + "body {" + "rn";
  325.             // One2HTML = One2HTML + " background-color: #E8F3F9;" + "rn";
  326.          One2HTML = One2HTML + " background-color: #F7F4F7;" + "rn";
  327.            One2HTML = One2HTML + "}" + "rn";
  328.            One2HTML = One2HTML + ".style2 {" + "rn";
  329.            One2HTML = One2HTML + "font-size: 24px;" + "rn";
  330.            One2HTML = One2HTML + "font-weight: bold;" + "rn";
  331.            One2HTML = One2HTML + "color: #000099;" + "rn";
  332.            One2HTML = One2HTML + "}" + "rn";
  333.            One2HTML = One2HTML + "-->" + "rn";
  334.            One2HTML = One2HTML + "</style>" + "rn";
  335.            One2HTML=One2HTML+"</head>" + "rn";
  336.            One2HTML = One2HTML + SCRIPT_CODE + "rn";
  337.            string mainTypeOne = mainType.Replace("&czd=", "");
  338.            One2HTML=One2HTML+"<body>" + "rn";
  339.            One2HTML = One2HTML + "<p><span class="style2"><a href="http://www.liebiao.net" target="_blank">列表网</a>-" + mainTypeOne + "  </span>rn";
  340.            One2HTML=One2HTML+"" + "rn";
  341.            One2HTML = One2HTML + " <input type="text" name="wdd"  id="wdd" value="" + data_source + "" > " + "rn";
  342.            One2HTML=One2HTML+"<a href="javascript:SerachOne();">列表搜索</a></p>" + "rn";
  343.            One2HTML = One2HTML + " <p align="center">" + TableList + "</p>" + "rn";
  344.            One2HTML=One2HTML+"</body>" + "rn";
  345.            One2HTML=One2HTML + "</html>" + "rn";
  346.             //排序  合成HTML
  347.            return One2HTML;
  348.         }
  349.         /// <summary>
  350.         /// 高亮和截取
  351.         /// </summary>
  352.         /// <param name="data">数据</param>
  353.         /// <param name="word">需要加亮的词</param>
  354.         /// <param name="Len">截取后的长度</param>
  355.         /// <returns>高亮和截取</returns>
  356.         public string HighLight(string data, string[] word, int Len)
  357.         {
  358.             if (data.Length <= Len)
  359.             {
  360.                 return data;
  361.             }
  362.             else
  363.             {
  364.                 return data.Substring(0, Len);
  365.             }
  366.         }
  367.     }
  368. }