首先建一個access 數據庫,庫中有一個URLINDEX表,其中URL和Keywords字段分別添加了索引,如下:
’ 搜索Summary字段
sql = sql & " ) OR ( [Summary] LIKE ’%" & QueryWords( 0 ) & "%’"
For i = LBound( QueryWords ) + 1 to UBound( QueryWords )
If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then
If uCase( QueryWords( i-1 ) ) = "OR" Then
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.CreateObject("ADODB.Recordset")
rs.Open sql, conn, 3, 3
Response.Write "<BR><B> 你搜索的是: </B> " & QueryString
Response.Write "<BR><B> 搜索的關鍵字: </B> "
For i = LBound( QueryWords ) to UBound( QueryWords )
Response.Write "<BR>" & strIndent & i & ": " & QueryWords( i )
Next
’ Print the SQL String
Response.Write "<BR><B> sql 語句 : </B> " & sql
’ Print the Results
Response.Write "<BR><B> 結果 : </B> <UL>"
On Error Resume Next
rs.MoveFirst
Do While Not rs.eof
Response.Write "<BR>" & "<A HREF=’OpenPage.asp?IndexURL=" & rs.Fields("URL").Value & "’>" & rs.Fields("Title") & "</A> - "
Response.Write rs.Fields("Description") & "<BR>"
Response.Write " <FONT SIZE=2>URL: " & rs.Fields("URL") & "</FONT>"
Response.Write "<HR SIZE=1 WIDTH=200 ALIGN=LEFT>"
rs.MoveNext
Loop
Response.Write "</UL>"
end if
%>
</BODY>
</HTML>