Class function. Replace the input string with the expression following the where keyword of the SQL statement:
Word search [for example: James]
Phrase search
Each word in a phrase will be retrieved.
For example: Xiaoqiang 1 Xiaoqiang 1 xiaoqiqiangqiang
Logical search
The and or operators are supported.
For example, Xiao Ming and Xiao Qiang
Composite condition:
Example: (Xiao Ming or Xiao Ming) and (Xiao Qiang or Xiao Qiang)
Example: (Xiao Ming or Xiao Ming) and Xiao Qiang
Example: root1 and (Cantonese or Beijingers)
-----------------------------------------------------------
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 = "(Title + Article )"
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
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
End if
Else
If (I = "and") or (I = "or") then
Blntru = true
Straaa = straaa & I
Else
Blnbbb = false
Exit
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
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
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
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
End if
Else
Check = orand ()
End if
End Function
End Class
------------------------- Note -----------------------------
The replaced string is not a complete SQL statement. It only generates the expression following the where keyword of the SQL statement. When it is sent to the ASP program, you can add
"Select ID, title, name, tablename from searchall where"
Similar SQL statements
------------------------- VBScript example -----------------------------
Dim objroot1
Set objroot1 = new createquerystring
Objroot1.querystring = strtext #=== input the string to be replaced
Objroot1.strfield = "field name to be queried" #== if not set, the default value is "(Title + Article )"
Strtext = objroot1 () #========= get the replaced SQL statement
If (objquerystring. intstart = 4) then
Call msgbox ("Start search by logic ")
End if
Set objroot1 = nothing