Dim act,Key,i,sql
act=trim(request.QueryString("action"))
if act="search" then
Key=trim(request.Form("Keyword"))
if requestCstringSafe(Key)="" then Dimerr "搜索字符串中含有非法字符,或者为空","back"
Key=replace(Key," "," ")
Key=split(Key," ")
'查询JL_Subject表,构造SQL语句
sql="select * from JL_Subject where "
sql=sql&"(Keyword Like '%"&Key(0)&"%' " '搜索Keyword字段
for i=Lbound(Key)+1 to Ubound(Key)
if Key(i)<>"" and UCase(Key(i))<>"OR" and UCase(Key(i))<>"AND" then
act=trim(request.QueryString("action"))
if act="search" then
Key=trim(request.Form("Keyword"))
if requestCstringSafe(Key)="" then Dimerr "搜索字符串中含有非法字符,或者为空","back"
Key=replace(Key," "," ")
Key=split(Key," ")
'查询JL_Subject表,构造SQL语句
sql="select * from JL_Subject where "
sql=sql&"(Keyword Like '%"&Key(0)&"%' " '搜索Keyword字段
for i=Lbound(Key)+1 to Ubound(Key)
if Key(i)<>"" and UCase(Key(i))<>"OR" and UCase(Key(i))<>"AND" then
if UCase(Key(i-1))="OR" then
sql=sql&" or Keyword Like '%"&Key(i)&"%'"
else
sql=sql&" and Keyword Like '%"&Key(i)&"%'"
end if
end if
next
sql=sql&") or (Title Like '%"&Key(0)&"%' "
for i=Lbound(Key)+1 to Ubound(Key)
if Key(i)<>"" and UCase(Key(i))<>"OR" and UCase(Key(i))<>"AND" then
if UCase(Key(i-1))="OR" then
sql=sql&" or Title Like '%"&Key(i)&"%'"
else
sql=sql&" and Title Like '%"&Key(i)&"%'"
end if
end if
next
sql=sql&")"
response.Write(sql)
end if
sql=sql&" or Keyword Like '%"&Key(i)&"%'"
else
sql=sql&" and Keyword Like '%"&Key(i)&"%'"
end if
end if
next
sql=sql&") or (Title Like '%"&Key(0)&"%' "
for i=Lbound(Key)+1 to Ubound(Key)
if Key(i)<>"" and UCase(Key(i))<>"OR" and UCase(Key(i))<>"AND" then
if UCase(Key(i-1))="OR" then
sql=sql&" or Title Like '%"&Key(i)&"%'"
else
sql=sql&" and Title Like '%"&Key(i)&"%'"
end if
end if
next
sql=sql&")"
response.Write(sql)
end if
OK,看看这样的SQL语句句应该没问题了吧...呵呵...
其实做站内搜索还有个投机取巧的办法:利用google或者百度的site:domainroot语法进行指定站搜索,将站内的搜索提交到google或者百度的服务器上(这样做的前提是你的页面必须事先被百度跟google收录了,要不然是搜取不到D...嘿嘿...)当然,如果你懂小偷技术原理的话,你还可以将提交返回的页面修改成你的风格,这样不仔细看的话还真不知道你是提交到google或者百度返回的结果.呵呵...