Implementation of ASP smart search

Source: Internet
Author: User

It is very convenient to use ASP to implement the search engine function. However, how can we achieve smart search similar to 3721? For example, when "Chinese people" is entered in the search condition box, keywords such as "China" and "people" are automatically extracted and searched in the database. After reading this article, you can find that the implementation of this function is so simple. OK, Follow Me!
Step 1: create a database named db_sample.mdb (this document uses the Access2000 database as an example) and create the T_Sample table in it. Table T_Sample includes the following fields:
ID automatic number
U_Name text
U_Info remarks
Step 2: Design the Search page Search. asp. This page contains a form (Frm_Search), which contains a text box and a submit button. Set the method attribute of the form to "get", and the action attribute to "Search. asp", that is, submit the form to the webpage itself. The code is as follows:
<! -- Search. asp -->
<Form name = "frm_Search" method = "get" action = "Search. asp">
Enter keywords:
<Input type = "text" name = "key" size = "10">
<Input type = "submit" value = "search">
</Form>
Next, we enter the key part for implementing intelligent search.
First, establish a database connection. Add the following code at the beginning of Search. asp:
<%
Dim strProvider, CNN
StrProvider = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source ="
StrProvider = strProvider & Server. MapPath ("") & "datadb_Sample.mdb" 'assume that the data inventory is stored in the data directory under the root directory of the home page.
Set CNN = Server. CreateObject ("ADODB. connection ")
CNN. Open strProvider Open the database connection
%>
Next, judge the data received by the ASP page and search in the database.
<%
Dim S_Key, RST, StrSQL
S_Key = Trim (Request ("key") 'to get the search keyword value
If S_Key <> "" then
Set RST = Server. CreateObject ("ADODB. RecordSet ")
StrSQL = AutoKey (S_Key) 'use the custom function AutoKey (), which is the core of smart search.
RST. Open StrSQL, CNN, 3, 2 'get the record after search
%>

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.