It is very convenient to use ASP to implement the functions of search engines, but how to implement intelligent searches similar to 3721
What about searching? For example, when "Chinese People" is entered in the search condition box, "China" will be automatically extracted from it,
Keywords such as "people" and search in the database. After reading this article, you can discover this skill
It is so simple to achieve. OK, FollowMe!
The first step is to create a database called db_sample.mdb (this article uses Access2000 number
The database is used as an example), and create a table T_Sample in it. Table T_Sample includes the following fields:
Automatic ID numbering
U_Name text
U_Info Notes
In the second step, we start designing the search page Search.asp. This page includes a form
(Frm_Search), the form includes a text box and a submit button. And put the method of the form
Set the nature to "get" and the action attribute to "Search.asp", which means submitting it to the web page itself. The code is as follows
:
<!--Search.asp-->
<formname="frm_Search"method="get"action="Search.asp">
Please enter keywords:
<inputtype="text"name="key"size="10">
<inputtype="submit"value="Search">
</form>
Next, we enter the key part of implementing intelligent search.
First, establish a database connection. Add the following code to the beginning of Search.asp:
<%
DimstrProvider,CNN
strProvider="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="
strProvider=strProvider&Server.MapPath("/")&
"/data/db_Sample.mdb"'Suppose the database is stored in the data directory in the root directory of the home page
SetCNN=Server.CreateObject("ADODB.connection")
CNN.OpenstrProvider'Open database connection
%>
Next, the data received by the ASP page is judged and searched in the database.
<%
DimS_Key,RST,StrSQL
S_Key=Trim(Request("key"))' get the value of the search keyword
IfS_Key<>""then
SetRST=Server.CreateObject("ADODB.RecordSet")