Summer Fun Huge offer ~------support the logical search/Word search/Phrase search + support Or/and keywords! (2)

Source: Internet
Author: User
Tags exit copy count file copy gettext
Key word//ROOT1. Hey!!! //

The following code is directly in my home page copy down, has been combined with the page, so more ugly understand. Because I wrote this file a long time ago. Now get to oneself also see not understand ~ ~ Hehe!!! Because recently prepared to give up the computer for a while, study hard. So I wrote some of the code I think is passable ... Oh

---------have time later I'll get the ASP file copy of the processing SQL statement--------
---------dynamically generate a VBS file for SQL statements based on the search criteria entered by the user-----

Sub Show (Numbers)
Dim STR
Select Case Numbers
Case 1
Str= "Start the search by author"
Window.document.all ("Show"). Innerhtml=str
Case 2
Str= "Start by word search"
Window.document.all ("Show"). Innerhtml=str
Case 3
Str= "Start by phrase search"
Window.document.all ("Show"). Innerhtml=str
Case 4
Str= "Start the Search by logic"
Window.document.all ("Show"). Innerhtml=str
Case 5
Str= "To search for complex logic"
Window.document.all ("Show"). Innerhtml=str
End Select
End Sub
'----------------------------------------------Global variables
Dim A7
A7= ""

'-------------------------------------------------------
Function Checkhaha (haha)
Text=replace (Trim (haha.search.value), "'", "" ")
If text= "" Then
Alert ("Sorry. Please enter your search keyword")
Haha.search.value= ""
Haha.search.focus ()
Exit Function
End If
Haha.search.value=text
haha. Searchstring.value=gettext (Text,haha)
Haha.submit ()
End Function


Function GetText (Text,haha)
Dim Reg
Dim Res
Dim Sky

If haha.radiobutton.checked Then ' ************************************* if submitted by author
Call Show (1)
gettext= "Name= '" & Text & "'"
Exit Function
End If
'*********************************************************************
Set reg=new RegExp
Reg. IgnoreCase = True
Reg. Global = True
Reg. Pattern= "\s"
Res=reg.test (text)
' ********************************************************* word Search If the keyword does not contain a space
If not res Then
Call Show (2)
Gettext= "(title + article) like '% ' & text & '% '
Exit Function
End If
'********************************************************************************************

Reg. Pattern= "\sand|\sor"
Res=reg.test (text)
If res Then ' ************************************************* check logical expression, correct return SQL statement, otherwise return false, search by phrase
Sky=check (Reg,text)
If Sky=false Then ' ************************************** a phrase search if the logical search is incorrect
Gettext=wahaha (Reg,text)
Else ' ************************************************** submit a logical search
Gettext=sky
End If
Else ' **************************************************** a phrase search without the and or keyword
Gettext=wahaha (Reg,text)
End If
End Function

Function Wahaha (reg,text) ' ***************************************** phrase search
Dim ter
Dim Ter1
Dim likes
Dim Ors
Ter= ""
Ter1= ""
Likes= "or (title + article) like '% '
ors= "%") "
Reg. Pattern= "(\s*\s)"
Set Re=reg. Execute (text)
For each i in re
Ter=ter & likes & I & Ors
Ter1=ter1 & I & A7
Next
Call Show (3)
Wahaha=mid (ter,4)
End Function


Function Check (REG2,TEXT2)
Dim RE
Dim I
Dim BBB
Dim tru
Dim Re1
Dim Re2
Dim Re3
Dim Str
Dim str1
Dim A1
Dim A2
Dim A3
Dim A4
Str= "(title + article) like '% '
str1= "%"
Tru=true
Bbb=true
REG2. Pattern= "^\ (. +\) \s (and|or) \s"
Re=reg2.test (TEXT2)
REG2. Pattern= "\s (and|or) \s\ (. +\) $"
Re3=reg2.test (TEXT2)

If re and Re3 Then ' *********************************** if it is full composite logic, return the SQL statement
REG2. Pattern= "^\ (\s*\s) (\bor\b|\band\b) (\s*\s) \) (And|or) \ (\s*\s) (\bor\b|\band\b) (\s*\s) \) $"
Set RE1=REG2. Execute (TEXT2)
If re1.count<1 Then
Check=false
Exit Function
End If
Set re2=re1 (0)
If re2.submatches.count<6 Then
Check=false
Exit Function
End If
A1=re2.submatches (0)
A2=re2.submatches (2)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.