因为本人积累了很多代码,平时靠文件系统查询比较麻烦和费事,写了一个检索系统,在dis.aspx这个最终内容显示页面上我会把查询关键字加粗并用红色标识出来,但是有时候能标识出来,有时不行,如"开发"这个关键字用全文搜索,然后点开内容页面就不能标识出来,而且单个汉字也无法标识,英文就没有问题,我用的是正则表达式地址是:http://222.67.177.236/infosch.aspx以下是以前的帖子,解决了一起结帖http://community.csdn.net/Expert/topic/5763/5763186.xml?temp=.6211206http://community.csdn.net/Expert/topic/5762/5762995.xml?temp=.2336084

解决方案 »

  1.   

    哦,对了,因为数据库里面文章比较少,只有80来篇,关键词大家可以用datagrid或checkboxlist或button,然后选择全文搜索
      

  2.   

    代码如下:
    <%@ Page Language="VB" Debug="true" validateRequest="false" %>
    <%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2"%>
    <%@Import Namespace="System.Data"%>
    <%@Import Namespace="System.Data.Sqlclient"%>
    <%@ Register
        Assembly="AjaxControlToolkit"
        Namespace="AjaxControlToolkit"
        TagPrefix="ajaxToolkit" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server" language="VB">
        
        Sub Page_load()
            If Not IsPostBack Then
                Dim strcontent As String
                Dim strarray() As String
                Dim strtitle As String
                Dim str As String
                Dim con As SqlConnection
                Dim cmd As SqlCommand
                Dim strcmd As String
                Dim da As SqlDataReader
                con = New SqlConnection(ConfigurationSettings.AppSettings("innsa"))
                strcmd = "select title,content from infomation where id=" & CInt(Request("id"))
                cmd = New SqlCommand(strcmd, con)
                con.Open()
                da = cmd.ExecuteReader
                If da.Read() Then
                    ttl.Text = da(0)
                    strcontent = da(1)
                End If
                con.Close()
                
                
                If Request("keyi") <> "" And Request("keyi") <> "请输入查询关键词,如有多个关键词请用-隔开" Then
                    
                    Dim keyi As String = Request("keyi")
                    strarray = keyi.Split("-")
                    For Each str In strarray
                        'Dim r As Regex
                        'r = New Regex("^[\u4E00-\u9FFF]+$")
                        Dim matches As MatchCollection = Regex.Matches(strcontent, str, RegexOptions.IgnoreCase)
                    
                        Dim i As Int32 = 0
                        Dim m As Match
                        For Each m In matches                        strcontent = strcontent.Insert(m.Index + str.Length + i, "</b></font>")
                            strcontent = strcontent.Insert(m.Index + i, "<font color='red'><b>")
                            i = i + 32
                        Next
                
                    Next
                
                End If
                
                content.Value = strcontent            
                
                
                
                
                
                
                
                
                
                
            End If
        End Sub
        
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
    <style type="text/css">
    body {
    font-size:12px;
    scrollbar-face-color:#ECECEC;
    }
    </style>
        <title id="ttl" runat="server"></title>
    </head>
    <body>
        <form id="form1" runat="server">
        
        <div>
            <FCKeditorV2:FCKeditor ID="content" runat="server" BasePath="Files/" width="980px" height="750px">
            </FCKeditorV2:FCKeditor>
        </div>
        </form>
    </body>
    </html>
      

  3.   

    Dim matches As MatchCollection = Regex.Matches(strcontent, str, RegexOptions.IgnoreCase)
                    
                        Dim i As Int32 = 0
                        Dim m As Match
                        For Each m In matches                        strcontent = strcontent.Insert(m.Index + str.Length + i, "</b></font>")
                            strcontent = strcontent.Insert(m.Index + i, "<font color='red'><b>")
                            i = i + 32
                        Next
    ------------------------------
    楼主这段改成这样以为如何:
    strcontent = strcontent.Replace(str,"<font color='red'><b>"+str+"</b></font>");
      

  4.   

    另外 搜索的关键是要搜出用户想要搜的东西
    简单的%keyword%是不行的
    不过楼主的东西自己用还是可以的:-)
      

  5.   

    Request("keyi") 这里面有中文是肯定不行的 一定要编码的
      

  6.   

    不大算做像google、baidu那样的东西,有自知之明,谁都没有自信说我作出来的东西能搜到客户想要的东西,keyowrd比较通用
      

  7.   

    System.Web.HttpUtility.UrlEncode(keyword);编码
    System.Web.HttpUtility.UrlDecode(keyword);解码
      

  8.   

    试过了上面的方法,decode出来的是乱码。
      

  9.   

    ok了,谢谢  keystudio(臣本布衣 躬耕于南阳 苟全性命于乱世 不求闻达于诸侯)