首先建一個access 數據庫
Title 文本
Description 文本
Summary 文本
Keywords 文本(索引:有(無重復)) 程序文件doquery
<HTML><HEAD><TITLE>簡單搜索引擎</TITLE></HEAD>
<BODY BGCOLOR=#ffffff MARGINWIDTH="
LEFTMARGIN=
<FORM METHOD="post" ACTION="doquery
Query: <INPUT TYPE="Text" NAME="QueryString"><BR>
<INPUT TYPE="Submit" VALUE="Submit">
</FORM>
</CENTER>
<%
dim act
act=request("act")
if(act="search") then
QueryString = Request
QueryWords = Split( QueryString )
strIndent = " "
’ 如果搜索為空則返回
If QueryString = "" Then
Response
End If
Session
If IsObject(Session("sitesearch_conn")) Then
Set conn = Session("sitesearch_conn")
Else
Set conn = Server
conn
Set Session("sitesearch_conn") = conn
End If
’ 查詢語句
sql = "SELECT * FROM [URLIndex] WHERE"
’搜索Description字段
sql = sql & " ( [Description] LIKE ’%" & QueryWords(
For i = LBound( QueryWords ) +
If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then
If uCase( QueryWords( i
sql = sql & " OR [Description] LIKE ’%" & QueryWords( i ) & "%’"
Else
sql = sql & " AND [Description] LIKE ’%" & QueryWords( i ) & "%’"
End If
End If
Next
’ 搜索Keywords字段
sql = sql & " ) OR ( [Keywords] LIKE ’%" & QueryWords(
For i = LBound( QueryWords ) +
If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then
If uCase( QueryWords( i
sql = sql & " OR [Keywords] LIKE ’%" & QueryWords( i ) & "%’"
Else
sql = sql & " AND [Keywords] LIKE ’%" & QueryWords( i ) & "%’"
End If
End If
Next
’ 搜索Title字段
sql = sql & " ) OR ( [Title] LIKE ’%" & QueryWords(
For i = LBound( QueryWords ) +
If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then
If uCase( QueryWords( i
sql = sql & " OR [Title] LIKE ’%" & QueryWords( i ) & "%’"
Else
sql = sql & " AND [Title] LIKE ’%" & QueryWords( i ) & "%’"
End If
End If
Next
’ 搜索Summary字段
sql = sql & " ) OR ( [Summary] LIKE ’%" & QueryWords(
For i = LBound( QueryWords ) +
If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then
If uCase( QueryWords( i
sql = sql & " OR [Summary] LIKE ’%" & QueryWords( i ) & "%’"
Else
sql = sql & " AND [Summary] LIKE ’%" & QueryWords( i ) & "%’"
End If
End If
Next
sql = sql & " )"
’
Set rs = Server
rs
Response
Response
For i = LBound( QueryWords ) to UBound( QueryWords )
Response
Next
’ Print the SQL String
Response
’ Print the Results
Response
On Error Resume Next
rs
Do While Not rs
Response
Response
Response
Response
rs
Loop
Response
end if
%>
</BODY>
</HTML>
From:http://tw.wingwit.com/Article/program/net/201311/14292.html