Function _asp Foundation of multi-field fuzzy search
Source: Internet
Author: User
Some time ago wrote a multiple-field fuzzy search function (similar to Baidui). The function code is as follows
'==================================================
' Function name: Keyword_sousuo
' function: Generate SQL query criteria
' Parameters: table_field------Table's field names (separated by commas)
' Keyword------search keywords (separated by spaces)
' Return: SQL query condition
'==================================================
Function Keyword_sousuo (ByVal table_field,byval Keyword)
Dim str01,str02,keywords,table_fields,i,j
If table_field<> "" Then
Str01= "(" &table_fields (0) & "like '%" &keyword& "%"
For j=0 to UBound (table_fields)
str01=str01& "or" &table_fields (j) & "like"% "&keyword&"% "
Next
str01=str01& ")"
Else
Response. Write ("<script>alert (" parameter error (cannot be empty)! ') </script> ")
Response. End ()
End If
' Full angle--' half corner space
' Keyword=replace (keyword, "", "")
' While INSTR (keyword, "") >0
' Keyword=replace (keyword, "", "")
' Wend
Keywords=split (keyword, "")
If UBound (keywords) >0 then
For i=0 to UBound (keywords)
str02=str02& "(" &table_fields (0) & "like"% "&keywords (i) &"% "
For J=1 to UBound (table_fields)
str02=str02& "or" &table_fields (j) & "like"% "&keywords (i) &"% "
Next
str02=str02& ")"
Next
Str02= "(" &replace (Str02, ") (", ") and (") & ")"
Keyword_sousuo= "(" & Str01 & "or" & Str02 & ")"
Else
Keyword_sousuo=str01
End If
End Function
'==================================================
' Function name: Keyword_tag
' Function: Mark the keyword in the string as red
' Argument: str------string
' keyword------tagged keywords (separated by spaces)
' Return: string (HTML format)
'==================================================
Function Keyword_tag (ByVal str,byval Keyword)
Dim keywords,str01,str02,i
' Full angle--' half corner space
' Keyword=replace (keyword, "", "")
' While INSTR (keyword, "") >0
' Keyword=replace (keyword, "", "")
' Wend
Str01=replace (Str,keyword, "<font color=" "#ff0000" ">" &keyword& "</font>")
Keywords=split (keyword, "")
If UBound (keywords) >0 then
Str02=str
For i=0 to UBound (keywords)
Str02=replace (Str02,keywords (i), "<font color=" "#ff0000" ">" &keywords (i) & "</font>")
Next
Keyword_tag=str02
Else
Keyword_tag=str01
End If
End Function
Here is an example http://www.zhouhaihe.com/blog/uploads/200604/recordread.asp
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.