国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

實(shí)現(xiàn)支持邏輯搜索/單詞搜索/詞組搜索+支持OR/AND關(guān)鍵字的VBS CLASS

2024-07-21 02:15:37
字體:
供稿:網(wǎng)友
class功能.替換傳入的字符串成為sql語句where關(guān)鍵字后面的表達(dá)式:

詞語搜索 [例如: 小明]

詞組搜索
詞組里面每一個詞都將被檢索
例如: 小強(qiáng)1 小名1 小強(qiáng)強(qiáng) 小小強(qiáng)

邏輯搜索
支持 and 和 or 運(yùn)算符.
例如: 小明 and 小強(qiáng) and 小小強(qiáng)

復(fù)合條件:
例如:(小小明 or 小明) and (小強(qiáng) or 小小強(qiáng))
例如:(小小明 or 小名) and 小小強(qiáng)
例如: root1 and (廣東人 or 北京人)


-----------------------------------------------------------
class createquerystring

public objreg
public intstart
public strfield
private objnode2
private strtext

public property let querystring( strvalue )
strtext = lcase( strvalue )
end property

private sub class_initialize()
set objreg = new regexp
strfield = "(標(biāo)題+文章)"
end sub

private sub class_terminate()
set objreg = nothing
end sub

public default function gettext()
dim blnres
dim strsky
with objreg
.ignorecase = true
.global = true
.pattern = "/s"
blnres = .test( strtext )
end with
if (not blnres) then
intstart = 2
gettext = strfield & " like '%" & strtext & "%'"
else
objreg.pattern = "/sand|/sor"
blnres = objreg.test( strtext )
if blnres then
strsky = check()
if strsky = false then
gettext = wahaha()
else
gettext = strsky
end if
else
gettext = wahaha()
end if
end if
end function

private function wahaha()
dim strter
dim strlikes
dim strors
dim stri
dim objre
strter = ""
strlikes = " or (" & strfield & " like '%"
strors = "%')"
objreg.pattern = "(/s*/s)"
set objre = objreg.execute(strtext)
for each stri in objre
strter = strter & strlikes & stri & strors
next
wahaha = mid( strter , 4 )
intstart = 3
end function

private function checkyes( strmode , intcount)
dim objnode1
objreg.pattern = strmode
set objnode1 = objreg.execute( strtext )
if objnode1.count < 1 then
checkyes = true
else
set objnode2 = objnode1( 0 )
if objnode2.submatches.count < intcount then
checkyes = true
end if
end if
end function

private function orand()
dim strsss
dim strccc
dim straaa
dim a143
dim i
dim objn
dim blntru
dim blnbbb
strsss = "(" & strfield & " like '%"
strccc = "%')"
straaa = ""
n1 = 0
blntru = true
blnbbb = true

objreg.pattern = "(/s*/s)"
set objn = objreg.execute( strtext )
a143 = objn.count - 1
if (objn.item( a143 ) = "and") or (objn.item( a143 ) = "or") then
orand = false
exit function
end if
for each i in objn
if blntru then
if (i <> "and") and (i <> "or") then
blntru = false
straaa = straaa & strsss & i & strccc
else
blnbbb = false
exit for
end if
else
if (i = "and") or (i = "or") then
blntru = true
straaa = straaa & i
else
blnbbb = false
exit for
end if
end if
next
if (not blnbbb) then
orand = false
else
orand = straaa
intstart = 4
end if
end function



private function check()
dim re
dim re1
dim re2
dim re3
dim str
dim str1
dim a1
dim a2
dim a3
dim a4
str = strfield & " like '%"
str1 = "%'"
with objreg
.pattern = "^/(.+/)/s(and|or)/s"
re = .test( strtext )
.pattern = "/s(and|or)/s/(.+/)$"
re3 = .test( strtext )
end with
if re and re3 then
if checkyes( "^/((/s*/s) (/bor/b|/band/b) (/s*/s)/) (and|or) /((/s*/s) (/bor/b|/band/b) (/s*/s)/)$" , 6 ) then
check = false
else
with objnode2
a1 = .submatches(0)
a2 = .submatches(2)
a3 = .submatches(4)
a4 = .submatches(6)
check = "(" & str & a1 & str1 & " " & .submatches(1) & " " & str & a2 & str1 & ") " &_
.submatches(3) & " (" & str & a3 & str1 & " " & .submatches(5) & " " & str & a4 & str1 & ")"
intstart = 5

|||end with
end if
elseif re then
if checkyes( "^/((/s*/s) (/bor/b|/band/b) (/s*/s)/) (and|or) (.+)" , 4 ) then
check = false
else
with objnode2
a1 = .submatches(0)
a2 = .submatches(2)
a3 = .submatches(4)
check = "(" & str & a1 & str1 & " " & .submatches(1) & " " & str & a2 & str1 & ") " &_
.submatches(3) & " (" & str & a3 & str1 & ")"
intstart = 5
end with
end if
elseif re3 then
if checkyes( "(.+) (and|or) /((/s*/s) (/bor/b|/band/b) (/s*/s)/)$" , 4 ) then
check = false
else
with objnode2
a1 = .submatches(0)
a2 = .submatches(2)
a3 = .submatches(4)
check = "(" & str & a1 & str1 & ") " & .submatches(1) & " (" & str & a2 & str1 & " " &_
.submatches(3) & " " & str & a3 & str1 & ")"
intstart = 5
end with
end if
else
check = orand()
end if
end function

end class
-------------------------注意-----------------------------
替換好的字符串并不是完整的sql語句.只是生成sql語句的where關(guān)鍵字后面的表達(dá)式.發(fā)送到asp程序的時候.你可以在前面加上
"select id,標(biāo)題,name,tablename from searchall where "
這樣類似的sql語句
-------------------------vbscript例子-----------------------------
dim objroot1
set objroot1 = new createquerystring
objroot1.querystring = strtext '====傳入要替換的字符串
objroot1.strfield = "要查詢的字段名字" '===如果不設(shè)置.默認(rèn)值是"(標(biāo)題+文章)"
strtext = objroot1() '=========得到替換好的sql語句
if (objquerystring.intstart = 4) then
call msgbox("啟動按邏輯搜索")
end if
set objroot1 = nothing

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 若尔盖县| 信宜市| 大港区| 侯马市| 五常市| 民乐县| 万载县| 南郑县| 大洼县| 新泰市| 涿州市| 商水县| 越西县| 水富县| 伊通| 宜昌市| 鹿邑县| 塘沽区| 临汾市| 湘潭市| 光泽县| 平乐县| 得荣县| 上犹县| 海南省| 庆元县| 利辛县| 上饶县| 乌海市| 古浪县| 重庆市| 开封市| 本溪| 德惠市| 金阳县| 阿尔山市| 云林县| 建德市| 玛曲县| 锡林郭勒盟| 乌拉特前旗|