上午参看了一些资料,希望能把站内搜索做得更高级一些,其实应该去学学关于搜索的一些算法的...不过我一直都没有找到...看来自己还是太菜了

因此我做的这个支持分词搜索,主要通过空格来加以区分而已,然后通过instr来获得空格的位置,然后通过while语句进行控制,把所有关键字串起来以达到分词的效果...不过一般情况下搜索引擎应该都可以自动将关键字进行拆分,比如"百度搜索",系统自动将这个词拆分成"百度"和"搜索"两个单词,但好似这个方法需要建立一个庞大的词库...具体的还再研究中....
因此我只奉上我那个搜索的核心代码,由于代码比较简单,我就不加以注释了,给大家一个参考吧

Dim conn
Set conn=server.createobject("ADODB.connection")
conn.connectionstring="provider=microsoft.jet.oledb.4.0; data source=" & server.mappath("db1.mdb")
conn.open
key = trim(request("txtSreach"))'这里一定要加上trim来去除字符串前后的空格,不然的话当你输入"百度 "的时候,空格也会参加匹配,这样一来搜索的精度就不准确了....
dim strSQL,tmpSQL
strSQL = "select * from info where "
tmpSQL = "note like "
dim Pos
Pos = 1
while Pos > 0
Pos = instr(1,key," ")
if Pos = 0 then
tmpSQL = tmpSQL & "'%"&key&"%' or title like '%"&key&"%'"
else
tmpSQL = tmpSQL & "'%"&mid(key,1,Pos-1) &"%' or title like '%"&mid(key,1,Pos-1)&"%' and note like "
key = mid(key,Pos+1,len(key))
end if
wend
strSQL = strSQL & tmpSQL
strSQL = strSQL & "order by id desc"
set rs = conn.execute(strSQL)
if rs.eof then
response.write "对不起没有找到!"
else
do while not rs.eof
response.write rs("Title")
rs.movenext
loop
end if
set rs=nothing
set conn=nothing