创意联盟

 找回密码
 注册

用新浪微博连接

一步搞定

QQ登录

只需一步,快速开始

搜索
热搜: mysql server
查看: 1307|回复: 3

中文分词搜索,asp拆词搜索,asp智能分词搜索 [复制链接]

发表于 2008-10-17 15:10:45 |显示全部楼层
中文分词搜索,asp拆词搜索,asp智能分词搜索


l在做一个网站时,老板让实现像百度那样的搜索功能,以前asp实现的都是模糊搜索,匹配查询。没办法。到网上搜搜看,我发现网上提供的方法有这几种,一是建个词库,二是用分词组件,三就是我说的这种,自动分词技术,不过也不是智能的分词,只是隔两个词匹配。最好的是建个词库,根据用户的输入来扩充词库,但对于中小型网站,这可能不太需要。

这是我说的第三种分词搜索,代码如下:使用方法就不说了。

<%   
Function AutoKey(strKey)   
CONST lngSubKey=2   
Dim lngLenKey, strNew1, strNew2, i, strSubKey   

’检测字符串的合法性,若不合法则转到出错页。出错页你可以根据需要进行设定。   

if InStr(strKey,"=")<>0 or InStr(strKey,"`")<>0 or InStr(strKey,"")<>0 or InStr(strKey," ")<>0 or InStr(strKey," ")<>0 or InStr(strKey,"")<>0 or InStr(strKey,chr(34))<>0 or InStr(strKey,"\")<>0 or InStr(strKey,",")<>0 or InStr(strKey,"<")<>0 or InStr(strKey,">")<>0 then   
Response.Redirect "error.htm"   
End If   
lngLenKey=Len(strKey)   
Select Case lngLenKey   
Case 0 若为空串,转到出错页   
Response.Redirect "error.htm"   
Case 1 若长度为1,则不设任何值   
strNew1=""   
strNew2=""   
’Case Else 若长度大于1,则从字符串首字符开始,循环取长度为2的子字符串作为查询条件   
For i=1 To lngLenKey-(lngSubKey-1)   
strSubKey=Mid(strKey,i,lngSubKey)   
strNew1=strNew1 & " or U_Name like %" & strSubKey & "%"   
strNew2=strNew2 & " or U_Info like %" & strSubKey & "%"   
Next   
End Select   
’得到完整的SQL语句   

AutoKey="Select * from T_Sample where U_Name like %" & strKey & "% or U_Info like %" & strKey & "%" & strNew1 & strNew2   
End Function   
%>

Rank: 4

发表于 2008-10-17 20:31:16 |显示全部楼层

使用道具 举报

Rank: 80Rank: 80Rank: 80Rank: 80Rank: 80

发表于 2008-10-20 10:26:12 |显示全部楼层
看住

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

Archiver|意盟 ( 闽ICP备06022703号 )

GMT+8, 2012-2-8 03:24 , Processed in 0.053732 second(s), 16 queries , Eaccelerator On.

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部