怎样用asp实现站内搜索?谢谢!

ZTMSS 2003-12-02 01:28:10
怎样用asp实现站内搜索?
Thank you very much!
...全文
64 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
minghui000 2004-01-14
  • 打赏
  • 举报
回复
SEARCH.ASP

<HTML>
<HEAD>
<TITLE>'<%=Request("SearchText")%>'的搜索结果</TITLE>
</HEAD>
<BODY>
<B>'<%=Request("SearchText")%>'的搜索结果</B><BR>
<%
Const fsoForReading = 1
Dim objFile, objFolder, objSubFolder, objTextStream
Dim bolCase, bolFileFound, bolTagFound
Dim strCount, strDeTag, strExt, strFile, strContent, strRoot, strTag, strText, strTitle, strTitleL
strFile = ".asp .htm .html .js .txt .css"
strRoot = "/"
strText = Request("SearchText")
strTag = Chr(37) & Chr(62)
bolFileFound = False
bolTagFound = False
If Request("Case") = "on" Then bolCase = 0 Else bolCase = 1
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
RealPath=Server.MapPath(strRoot)
VirtualPath="http://" & Request.ServerVariables("SERVER_NAME")
Set objFolder = objFSO.GetFolder(RealPath)
schSubFol(objFolder)
Sub schSubFol(objFolder)
on error resume next
For Each objFile in objFolder.Files
If strText = "" Then Exit Sub
If Response.IsClientConnected Then
Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)
strContent = objTextStream.ReadAll
If InStr(1, strContent, strTag, bolCase) Then
Else
If Mid(objFile.Name, Len(objFile.Name) - 1, 1) = "." Then strExt = Mid(objFile.Name, Len(objFile.Name) - 1, 2)
If Mid(objFile.Name, Len(objFile.Name) - 2, 1) = "." Then strExt = Mid(objFile.Name, Len(objFile.Name) - 2, 3)
If Mid(objFile.Name, Len(objFile.Name) - 3, 1) = "." Then strExt = Mid(objFile.Name, Len(objFile.Name) - 3, 4)
If Mid(objFile.Name, Len(objFile.Name) - 4, 1) = "." Then strExt = Mid(objFile.Name, Len(objFile.Name) - 4, 5)
If InStr(1, strContent, strText, bolCase) And Instr(1, strFile, strExt, 1) Then
If InStr(1, strContent, "<TITLE>", 1) Then
strTitle = Mid(strContent, InStr(1, strContent, "<TITLE>", 1) + 7, InStr(1, strContent, "</TITLE>", 1))
Else
strTitle = "未命名"
end if
myFile=objFile.Path
myFile=replace(myfile,RealPath,VirtualPath,1,-1,1)
myFile=replace(myfile,"\","/")
strCount = strCount + 1
Response.Write "<DL><DT><B><I>"& strCount &"</I></B> - <A HREF=" & myFile & ">" & strTitle & "</A></A></DT><BR><DD>"
strTitleL = InStr(1, strContent, "</TITLE>", 1) - InStr(1, strContent, "<TITLE>", 1) + 7
strDeTag = ""
bolTagFound = False
Do While InStr(strContent, "<")
bolTagFound = True
strDeTag = strDeTag & " " & Left(strContent, InStr(strContent, "<") - 1)
strContent = MID(strContent, InStr(strContent, ">") + 1)
Loop
strDeTag = strDeTag & strContent
If Not bolTagFound Then strDeTag = strContent
Response.Write replace(Mid(strDeTag, strTitleL, 200),strText,"<font color=red>" & strText & "</font>",1,-1,bolcase)
Response.Write "...<BR><b><FONT SIZE='2'>URL: " & myFile
Response.Write " - 上次修改时间: " & objFile.DateLastModified
Response.Write " - " & FormatNumber(objFile.Size / 1024)
Response.Write "Kbytes</FONT></b></DD></DL>"
bolFileFound = True
End If
objTextStream.Close
End If
End If
Next
End Sub
For Each objSubFolder in objFolder.SubFolders
schSubFol(objSubFolder)
Next
If Not bolFileFound then Response.Write "没有匹配结果"
If bolFileFound then Response.Write "<B>搜索结束</B>"
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</BODY></HTML>


SEARCH.HTM

<HTML>
<HEAD>
<TITLE>文件搜索引擎</TITLE>
</HEAD>
<BODY>
<CENTER>
<FORM METHOD=POST ACTION="search.asp">
<TABLE BGCOLOR="#CC6633" BORDER="0">
<TR>
<TD> <FONT COLOR="#FFFFFF">
请输入所要搜索的字符串:
<INPUT TYPE="text" NAME="SearchText" SIZE="22"></FONT> </TD>
<TD><INPUT TYPE="submit" VALUE="确定">
<INPUT TYPE="reset" VALUE="清除"></TD>
</tr>
</TABLE>
</FORM>
</CENTER>
</BODY>
</HTML>

flying310 2003-12-08
  • 打赏
  • 举报
回复
up
jinco 2003-12-08
  • 打赏
  • 举报
回复
我也想知道~~~,那个文件
帮顶一下
htao007 2003-12-08
  • 打赏
  • 举报
回复
说说是哪一个文件阿
bzscs 2003-12-02
  • 打赏
  • 举报
回复
启动IIS的默认站点,它其中有一个不必连数据库的全站搜索的功能,你把对应的asp文件源码看一下就知道了,
-
服务器默认是支持这个功能的,
chang1216 2003-12-02
  • 打赏
  • 举报
回复
楼上的哥们怎么搞得!
eliphe 2003-12-02
  • 打赏
  • 举报
回复
sql="select * from table where " & 选择的值 & " like '%" & 输入文字 & "%' order by id desc"
chang1216 2003-12-02
  • 打赏
  • 举报
回复
sql="select * from table where " & 选择的值 & " like '%" & 输入文字 & "%' order by id desc"
cuipi2003 2003-12-02
  • 打赏
  • 举报
回复
google可以
呵呵
如果你要自己搜索可以参考,sql server的全文检索功能,我最讨厌的就是这个了:)

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧