网络编程
位置:首页>> 网络编程>> Asp编程>> 如何做一个只搜索本网站的引擎?

如何做一个只搜索本网站的引擎?

  发布时间:2010-07-12 19:02:00 

标签:搜索,asp

如何做一个只搜索本网站的引擎?
    用下面两个文件即可实现:
searchfiles.html 

<html>
<head>
<title>本网搜索引擎 - asp之家</title>
</head>
<body>
<form method="POST" action="cgi-bin/searchfiles.asp">
  <table border="0" cellpadding="5" bgcolor="#C2E7E3">
    <tr>
      <td align="center">请输入条目或关键词<input type="text" name="term" size="15"> <input  type="submit" value="搜索"></td>
    </tr>
  </table>
</form>
</body>
</html>

searchfiles.asp

<% 
SearchTerm = request.form("term") 
Novalid=" a b c d e f g h i j k l m n o p q r s t u v w x y z yes no and more" 
NovalidResponse ="你输入的内容过于简单,请返回重试!" 
  
if instr(SearchTerm,Novalid)=0 then 
Response. Write ("<CENTER><H2>搜索结果</H2></CENTER>") 
  
  FolderName= "FolderName" 
  ShowList() 
else 
Response.Write NovalidResponse 
End if 
SearchResponse="" 
%> 
<% 
Sub ShowList() 
FolderToCheck = server.mappath("\") &"/" & FolderName & "/" 
Dim fs, f, f1, fc, s 
    Set fs = CreateObject("Scripting.FileSystemObject") 
    Set f = fs.GetFolder(FolderToCheck) 
Set fc = f.Files 
For Each f1 in fc 
        Wfile = f1.name 
          if right(Wfile, 5)=".html" OR right(Wfile, 4)=".htm" then 
            Wfile2 = FolderToCheck & Wfile 
            Set fs = CreateObject("Scripting.FileSystemObject") 
            Set a = fs.OpenTextFile(Wfile2) 
            ct = a.ReadAll 
            a.close 
            ct2=lcase(ct) 
            SearchTerm2 = lcase(SearchTerm) 
                  if instr(ct2,SearchTerm2)>0 then 
                      if instr(ct,"</title>")>0 then 
                  longitud=instr(ct,"</title>") 
                  longitud=longitud -1 
                          ct=left(ct,longitud) 
                          longitud2=len(ct) 
                  longitud=instr(ct,"<title>") 
                  longitud=longitud2 -longitud -6 
                          ct=right(ct,longitud) 
                    else 
                        if instr(ct,"</TITLE>")>0 then 
                    longitud=instr(ct,"</TITLE>") 
                    longitud=longitud -1 
                            ct=left(ct,longitud) 
                            longitud2=len(ct) 
                    longitud=instr(ct,"<TITLE>") 
                    longitud=longitud2 -longitud -6 
                            ct=right(ct,longitud) 
            end if 
                    end if 
                    SearchResponse= SearchResponse +"<TR><TD>"+ ct + "</TD><TD ALIGN=CENTER 
VALIGN=MIDDLE>" + " <A HREF=" + "/" + FolderName + "/" + Wfile +"> More </A></TD></TR>" 
          longitud=0 
                  ct="" 
                  end if 
          end if 
Next 
Response.Write ("<HTML><HEAD><TITLE>搜索结果</TITLE></HEAD><BODY BGCOLOR=FFFFFF><CENTER>")  
Response.Write ("<TABLE BORDER=0 WIDTH=550><TR><TD BGCOLOR=C0C0C0><FONT SIZE=5><B>搜索结果</B></FONT></TD></TR></TABLE>")  
Response.Write ("<TABLE BORDER=0 WIDTH=550>")  
if SearchResponse<>"" then  
Response.Write SearchResponse 
else 
Response.Write ("<TR><TD>对不起,没有找到你输入的条目或关键词!</TD></TR>") 
end if 
Response.Write ("</TABLE>") 
Response.Write ("<TABLE BORDER=0 WIDTH=550><TR><TD BGCOLOR=C0C0C0 ALIGN=RIGHT><FONT SIZE=1>现在调用专业搜索引擎<A HREF= http://www.yahoo.com.cn/ </A></FONT></TD></TR></TABLE>") 
' 任选一个你喜欢的引擎
Response.Write ("</CENTER></BODY></HTML>") 
End Sub 
%>

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com