yangyj1204 发表于 2008-10-17 15:10:45

中文分词搜索,asp拆词搜索,asp智能分词搜索

中文分词搜索,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   
%>

尐譫灬ゝ 发表于 2008-10-17 20:31:16

:o

流氓鱼 发表于 2008-10-20 10:26:12

看住
页: [1]
查看完整版本: 中文分词搜索,asp拆词搜索,asp智能分词搜索