Recently, I am working on a company website. In order to make it easier for customers to find the company's products, news, and other information, we need to implement simple intra-site searches. if you simply use the SQL like '% keyword %' method, the efficiency is not high. for example, if you enter "ip board", you cannot find the product. I figured out a solution. construct the core of an SQL statement Code As follows:
Dim act, key, I, SQL
Act = trim (request. querystring ("action "))
If act = "Search" then
Key = trim (request. Form ("keyword "))
If requestcstringsafe (key) = "" Then dimerr ", the search string contains invalid characters or is empty.", "back"
Key = Replace (key ,"","")
Key = Split (key ,"")
'Query the jl_subject table and construct an SQL statement
SQL = "select * From jl_subject where"
SQL = SQL & "(keyword like '%" & Key (0) & "%'" 'search for keyword Fields
For I = lbound (key) + 1 to ubound (key)
If key (I) <> "" And ucase (Key (I) <> "or" and ucase (Key (I )) <> "and" then if ucase (Key (I-1) = "or" then
SQL = SQL & "or keyword like '%" & Key (I) & "% '"
Else
SQL = SQL & "and keyword like '%" & Key (I) & "% '"
End if
End if
Next
SQL = SQL & ") or (title like '%" & Key (0) & "% '"
For I = lbound (key) + 1 to ubound (key)
If key (I) <> "" And ucase (Key (I) <> "or" and ucase (Key (I) <> "and" then
If ucase (Key (I-1) = "or" then
SQL = SQL & "or title like '%" & Key (I) & "% '"
Else
SQL = SQL & "and title like '%" & Key (I) & "% '"
End if
End if
Next
SQL = SQL &")"
Response. Write (SQL)
End if OK. Check whether the SQL statement is correct... haha... in fact, there is still a opportunistic way to do intra-Site Search: using Google or Baidu's site: domainroot syntax for specific site search, submit the intra-site search to Google or Baidu's server (the premise is that your page must be indexed by Baidu and Google beforehand, or you cannot find d... hey hey ...) of course, if you understand the technical principles of thieves, you can also change the pages submitted for return to your style. If you do not read them carefully, you do not know whether you submitted the results to Google or Baidu. haha...