ASP simple intra-Site Search

Source: Internet
Author: User
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...
Related Article

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.