中文分词搜索,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
%>
【服务器+硬件防火墙+商业版服务端+配套专业型网
站系统+登陆器制作+架设+游戏安全策略服务+版
本修改+技术支持+售后.】
╔服╗┊主┊主┊域┊虚┊代┊网┊网┊域┊╔诚╗
┃务┃┊机┊机┊名┊拟┊理┊站┊站┊名┊┃信┃
┃项┃┊租┊托┊服┊主┊专┊建┊推┊注┊┃可┃
╚目╝┊用┊管┊务┊机┊区┊设┊广┊册┊╚靠╝
在线订购: www.bl-kj.com QQ:320092873
百隆竭诚为您服务
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
%>
【服务器+硬件防火墙+商业版服务端+配套专业型网
站系统+登陆器制作+架设+游戏安全策略服务+版
本修改+技术支持+售后.】
╔服╗┊主┊主┊域┊虚┊代┊网┊网┊域┊╔诚╗
┃务┃┊机┊机┊名┊拟┊理┊站┊站┊名┊┃信┃
┃项┃┊租┊托┊服┊主┊专┊建┊推┊注┊┃可┃
╚目╝┊用┊管┊务┊机┊区┊设┊广┊册┊╚靠╝
在线订购: www.bl-kj.com QQ:320092873
百隆竭诚为您服务