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
%>