请教一个模糊搜索问题,谢谢了

xiliumy 2008-04-14 10:25:40
刚做了个模精搜索,我想实现逐字搜索功能,比如"2008年中国年度人物评选活动开始"这句话,如果能实现搜索"中国人物"或者"年度活动"等等这样分词的搜索也能成功,请问怎么办,下面哪里错了,以下是我的搜索代码.谢谢了


<%
dim i
Search=trim(request("search"))
search = Split(search,",")

if search <> "" then
for i=1 to ubound(search)
sql="SELECT * FROM query where title like '%"&search(i)&"%' or keywords like '%"&search(i)&"%' order by ID desc"
next
else
sql="SELECT * FROM query order by ID desc"
end if

set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "<p>很抱歉!根据您输入的关键词没有查询到相关结果!"
else
'------------------分页-----------------------------
rs.pagesize=List_pagecount
page=cint(request("page"))
if page<=0 or page>rs.pagecount or page="" then
page=1
end if
rs.absolutepage=page
Tdcount=0
for i=1 to rs.pagesize
if rs.eof then
exit for
else
response.write " ·<a href='"&rs("links")&"' target=_blank title='"&rs("title")&"'>"&rs("title")&"</a><br>"
Tdcount=Tdcount+1
if Tdcount>=5 then
response.write "<br>"
Tdcount=0
end if
rs.movenext
end if
next
response.write "<br>"
call pagelist()
end if
rs.close

%>
...全文
50 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xiliumy 2008-04-14
1楼和3楼的方法好像不太行,搜不出任何结果,二楼(也就是一楼那哥们)方法改为:
Search=trim(request("search"))
search = Split(search,",")
if search <> "" then
str = "%"
for i=1 to len(search)
str = str & search(i) & "%"
next
sql="SELECT * FROM query where title like '" & str & "' or keywords like '" & str & "' order by ID desc"

else
sql="SELECT * FROM query order by ID desc"
end if
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1

才和原来出来的结果一样.
回复
xiliumy 2008-04-14
好像还是不能实现我所说的功能,仅限于搜索紧挨的一个字词组,不能把词组合并搜索,还是谢谢了
回复
xiliumy 2008-04-14
谢谢两位,正在测试看看
回复
银狐被占用 2008-04-14
楼主先确认你要搜的词里是不是有逗号。否则是分不了组的。
如果没有逗号,那你写的是不对的。
先改成1楼那样。
然后把
for i=1 to ubound(search)
sql = sql & " or title like '%"&search(i)&"%' or keywords like '%"&search(i)&"%' "
next
改成下面这样。
for i=1 to len(search)
sql = sql & " or title like '%"&mid(search,i,1)&"%' or keywords like '%"&mid(search,i,1)&"%' "
next
回复
No_Data_Found 2008-04-14
或者


str = "%"
for i=1 to ubound(search)
str = str & search(i) & "%"
next

sql="SELECT * FROM query where title like '" & str & "' or keywords like '" & str & "' order by ID desc"
回复
No_Data_Found 2008-04-14
好的分词查询是很困难的

你的代码问题


for i=1 to ubound(search)
sql="SELECT * FROM query where title like '%"&search(i)&"%' or keywords like '%"&search(i)&"%' order by ID desc"
next


sql="SELECT * FROM query where 1<>1 "

for i=1 to ubound(search)
sql = sql & " or title like '%"&search(i)&"%' or keywords like '%"&search(i)&"%' "
next

sql = sql & "order by ID desc"
回复
xiliumy 2008-04-14
问题终于解决了,下面偶把代码发出来看看,以供参考,这里谢谢楼上的朋友们.

<%
Search=trim(request("search"))
if search <> "" then
str = "%"
for i=1 to len(search)
str = str & mid(search,i,1) & "%"
next
sql="SELECT * FROM query where title like '" & str & "' or keywords like '" & str & "' order by ID desc"
else
sql="SELECT * FROM query order by ID desc"
end if
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "<p>很抱歉!根据您输入的关键词没有查询到相关结果! "
else
'------------------分页-----------------------------
rs.pagesize=List_pagecount
page=cint(request("page"))
if page<=0 or page>rs.pagecount or page="" then
page=1
end if
rs.absolutepage=page
Tdcount=0
for i=1 to rs.pagesize
if rs.eof then
exit for
else
response.write " ·<a href='"&rs("links")&"' target=_blank title='"&rs("title")&"'>"&rs("title")&"</a><br>"
Tdcount=Tdcount+1
if Tdcount>=5 then
response.write "<br>"
Tdcount=0
end if
rs.movenext
end if
next
response.write "<br>"
call pagelist()
end if
rs.close

%>
回复
Atai-Lu 2008-04-14
for i=1 to ubound(search)
sql="SELECT * FROM query where title like '%"&search(i)&"%' or keywords like '%"&search(i)&"%' order by ID desc"
next
这样出来sql语句其实还是只有一句,前面的循环都被覆盖,白做了
回复
Atai-Lu 2008-04-14
http://topic.csdn.net/u/20080409/13/19dec227-9ce4-4779-964b-32ce4dae172f.html
虽然写得很烂,但是你可以参考参考,或者google一下“分词算法”要分词的话,一般都要有个词典的
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-04-14 10:25
社区公告
暂无公告